Asymptote: Graphing

Revision as of 16:09, 15 March 2016 by Greenpepper9999 (talk | contribs) (Grammar/spelling)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Asymptote (Vector Graphics Language)
Getting Started - Basics - Drawing - Labeling - Filling - Useful functions - Examples - Macros and Packages

Help - Reference - Advanced Asymptote - 3D Graphics - CSE5 Package - How to

Note These example are for the AoPS forums, If you want to use them on your computer, you must "import graph;".

There are two parts to a graph.

The axes' codes:

Label f; 
f.p=fontsize(6); 
xaxis(-8,8,Ticks(f, 2.0)); 
yaxis(-8,8,Ticks(f, 2.0)); 

This means ticks at an interval of 2.0, between -8 and 8 for both the x and y axes.

And the graph code:

real f(real x) 
{ 
return x^3; 
} 
draw(graph(f,-2,2));

The return $x^3$ is the function of the graph, and the draw command draws the graph from the $x$ coordinate of $x = - 2$ to $x = 2$.

[asy] import graph;  size(300);  Label f;  f.p=fontsize(6);  xaxis(-8,8,Ticks(f, 2.0));  yaxis(-8,8,Ticks(f, 2.0));  real f(real x)  {  return x^3;  }  draw(graph(f,-2,2)); [/asy]

We can also alter the ticks code. For example, if we want intervals of 2 labeled, then 0.5 in between each one, we can use the following code:

Label f; 
f.p=fontsize(6); 
xaxis(-8,8,Ticks(f, 2.0,0.5)); 
yaxis(-8,8,Ticks(f, 2.0,0.5)); 

[asy] Label f;  f.p=fontsize(6);  xaxis(-8,8,Ticks(f, 2.0,0.5));  yaxis(-8,8,Ticks(f, 2.0,0.5)); [/asy] This graph, like with any draw command, can have several attributes fixed to it, such as color:

[asy] import graph;  size(300);  Label f;  f.p=fontsize(6);  xaxis(-8,8,Ticks(f, 2.0));  yaxis(-8,8,Ticks(f, 2.0));  real f(real x)  {  return x^3;  }  draw(graph(f,-2,2),green+linewidth(1)); [/asy]

import graph; 
size(300); 
Label f; 
f.p=fontsize(6); 
xaxis(-8,8,Ticks(f, 2.0)); 
yaxis(-8,8,Ticks(f, 2.0)); 
real f(real x) 
{ 
return x^3; 
} 
draw(graph(f,-2,2),green+linewidth(1));

Remember, you can still draw normal functions, so you can create lines, circles and ellipses.