ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Mojca Miklavec <mojca.miklavec.lists@gmail.com>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re:  OT: drawing graphs: Asymptote, Gnuplot, MetaFun, …
Date: Mon, 18 Apr 2011 23:42:16 +0200	[thread overview]
Message-ID: <BANLkTikH3sZ2r-f0TTsXX8YZnuQtPxng1Q@mail.gmail.com> (raw)
In-Reply-To: <1303158001.3910.257.camel@mattotaupa>

On Mon, Apr 18, 2011 at 22:20, Paul Menzel wrote:
> Dear ConTeXt folks,
>
> I need to plot some random walks similar to [1], but for example I need
> to emphasize certain sections of the plot and put labels and notes in
> there.
>
> 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 [2][3].
>
> 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
complex graphics.

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
the fly.

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).

\setupcolors
	[state=start]
\starttext
\startMPpage

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[1] = red;
c[2] = .5[red,yellow];
c[3] = .6green;
c[4] = blue;
c[5] = .4white;


vardef newval =
	val := val + floor(uniformdeviate(2))*2-1;
	(val)
enddef;

for n=1 upto 5:
	val := 0; draw (0,0)
	for i=0 upto 100:
		-- (0.01*i*wx,0.025*newval*wy)
	endfor
	withcolor c[n];
endfor


for i=0 step 20 until 100:
	label.bot(decimal(i), (0.01*i*wx,-.5*wy));
endfor;
for i=-20 step 5 until 20:
	label.lft(decimal(i), (0,0.025*i*wy));
endfor;

\stopMPpage
\stoptext
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


  parent reply	other threads:[~2011-04-18 21:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-18 20:20 Paul Menzel
2011-04-18 21:04 ` Pontus Lurcock
2011-04-18 21:42 ` Mojca Miklavec [this message]
2011-04-20 15:41 ` Aditya Mahajan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BANLkTikH3sZ2r-f0TTsXX8YZnuQtPxng1Q@mail.gmail.com \
    --to=mojca.miklavec.lists@gmail.com \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).