Difference between revisions of "Asymptote: Graphing"

m (Grammar/spelling)
 
(One intermediate revision by one other user not shown)
Line 2: Line 2:
  
 
<b>Note</b> These example are for the AoPS forums, If you want to use them on your computer, you must "import graph;".
 
<b>Note</b> 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.  
 
There are two parts to a graph.  
  
The axises codes:
+
The axes' codes:
  
 
<pre><nowiki>Label f;  
 
<pre><nowiki>Label f;  
Line 12: Line 13:
 
</nowiki></pre>
 
</nowiki></pre>
  
This means ticks at an interveral of 2.0 between -8 and 8 for both the x and y axises.
+
This means ticks at an interval of 2.0, between -8 and 8 for both the x and y axes.
  
 
And the graph code:
 
And the graph code:

Latest revision as of 17:09, 15 March 2016

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.