[NTG-context] OT: drawing graphs: Asymptote, Gnuplot, MetaFun, …
mojca.miklavec.lists at gmail.com
Mon Apr 18 23:42:16 CEST 2011
On Mon, Apr 18, 2011 at 22:20, Paul Menzel wrote:
> Dear ConTeXt folks,
> I need to plot some random walks similar to , but for example I need
> to emphasize certain sections of the plot and put labels and notes in
> Could you recommend a tool to easily accomplish that goal with easily. I
> guess it can be done with any of those as seen by the demos .
> I only have little experience using Gnuplot and I have never used
> Asymptote or MetaFun. These three seem to be well integrated with
> ConTeXt and I guess in the end I could just create the image files and
> include these in to my ConTeXt source.
> The only downside of Asymptote I found so far is, that there is no
> mailing list.
Below you have an example done in metapost/metafun (which integrates
well with ConTeXt). The downside of metapost is that you have to do
all the labels and axis drawing more or less manually, while gnuplot
will take care of drawing axes and properly adjusting the range etc.
On the other hand metapost might be quite powerful for geometrically
If you use gnuplot, you might need to precompute the points for the
random walk (it supports random numbers, but I'm not sure if you can
calculate sums), while metapost can do some reasonable calculations on
For 2D graphics asymptote doesn't bring you much.
Yet another alternative is TikZ and pgfplots (similar to metapost,
more library functions ready to draw all kinds of graphics, but less
powerful math engine that in metapost).
save wx, wy;
wx = 15cm;
wy = 10cm;
draw unitsquare shifted (0,-0.5) xyscaled (wx,wy);
save val; numeric val;
save tmp; numeric tmp;
save p; path p;
save c; color c;
c = red;
c = .5[red,yellow];
c = .6green;
c = blue;
c = .4white;
vardef newval =
val := val + floor(uniformdeviate(2))*2-1;
for n=1 upto 5:
val := 0; draw (0,0)
for i=0 upto 100:
for i=0 step 20 until 100:
for i=-20 step 5 until 20:
More information about the ntg-context