Asymptote: Graphing: Difference between revisions
No edit summary |
m Grammar/spelling |
||
| Line 5: | Line 5: | ||
There are two parts to a graph. | There are two parts to a graph. | ||
The | The axes' codes: | ||
<pre><nowiki>Label f; | <pre><nowiki>Label f; | ||
| Line 13: | Line 13: | ||
</nowiki></pre> | </nowiki></pre> | ||
This means ticks at an | 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 16:09, 15 March 2016
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
is the function of the graph, and the draw command draws the graph from the
coordinate of
to
.
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));
This graph, like with any draw command, can have several attributes fixed to it, such as color:
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.