ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: David Arnold <darnold@northcoast.com>
Subject: Re: function plotting
Date: Tue, 4 Oct 2005 23:17:27 -0700	[thread overview]
Message-ID: <8CF727E2-EDD0-49F4-AB8A-49DF6A9E1AC4@northcoast.com> (raw)
In-Reply-To: <20051004192047.GB30718@none.at>

Alexander,

There is a lot of plots you can do with Metapost. Ordinary, every day  
stuff. For example:

beginfig(1);

% initialize a and c for f(x)=|x-a| and g(x)=c
numeric a, c;
a=-2;
c=2;

% initialize function label abcissas and postions
numeric flabel, glabel;
flabel:=-5;
glabel:=-5;

% define function f(x)=|x-a|
vardef f(expr x)=
     abs(x-a)
enddef;

% draw line with given point and slope
path F;
F:=(-5,f(-5));
for x=-5 step 1 until 5:
     F:=F--(x,f(x));
endfor;

% initialize scale
numeric u; 10u=4cm;

% the line
F:=F scaled 1u;
draw F withcolor blue;

% clipping path
path cpath;
cpath:=(-5,-5)--(5,-5)--(5,5)--(-5,5)--cycle;
cpath:=cpath scaled 1u;

% clip and save current picture
picture pic;
clip currentpicture to cpath;
pic:=currentpicture;

% erase currentpicture
currentpicture:=nullpicture;

% draw grid
for k=-5u step 1u until 5u:
     draw (-5u,k)--(5u,k) withcolor 0.85white;
     draw (k,-5u)--(k,5u) withcolor 0.85white;
endfor;

% draw axes
drawarrow (-5u,0)--(5u,0);
drawarrow (0,-5u)--(0,5u);

% label axes
label.rt(btex $x$ etex, (5.2u,0));
label.top(btex $y$ etex, (0,5.2.u));
label.bot(btex $5$ etex, (5u,0));
label.lft(btex $5$ etex, (0,5u));

% redraw line
draw pic;

% label the functions f(x)=|x-a| and g(x)=c
pair D, E;
D:=(-5,f(-5)) scaled u;
label.lft(btex $f$ etex,D);
E:=(-5,2) scaled u;
label.lft(btex $g$ etex, E);

% draw the graph of g(x)=c
path G;
G:=(-5,2)--(5,2);
G:=G scaled u;
draw G withcolor blue;

endfig;

end.

And for a good stats package, see:

http://www-math.univ-poitiers.fr/~phan/statsmac.html

And for good circuits diagrams, see:

http://www.cnm.es/~pserra/schema/whatis.html

Don't give up on Metapost too soon. It's an awesome language and the  
file size created are small, a plus when you're document includes  
lots of figures and you want it to download in reasonable time on the  
internet.

  reply	other threads:[~2005-10-05  6:17 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-10-02 17:27 Q: about \externalfile from metafun-p.pdf Alexander Lazic
2005-10-02 17:54 ` Christopher Creutzig
2005-10-02 18:58   ` Alexander Lazic
2005-10-02 20:36     ` Christopher Creutzig
2005-10-03  8:03       ` Alexander Lazic
2005-10-03 17:26         ` Christopher Creutzig
2005-10-04  8:29           ` function plotting (was: Re: Q: about \externalfile from metafun-p.pdf) Alexander Lazic
2005-10-04 16:07             ` function plotting Christopher Creutzig
2005-10-04 19:17               ` Alexander Lazic
2005-10-04 17:48             ` function plotting (was: Re: Q: about \externalfile from metafun-p.pdf) Mojca Miklavec
2005-10-04 19:20               ` Alexander Lazic
2005-10-05  6:17                 ` David Arnold [this message]
2005-10-05  9:02                   ` Re: function plotting Alexander Lazic
2005-10-04 22:33               ` Christopher Creutzig
2005-10-05  7:18                 ` Hans Hagen
2005-10-05 13:22                   ` David Arnold
2005-10-05  7:05               ` Hans Hagen
2005-10-05  9:06                 ` Alexander Lazic
2005-10-05 12:08                 ` David Munger
2005-10-05 15:02                 ` Mojca Miklavec
2005-10-06 11:51                   ` Christopher Creutzig
2005-10-04 19:14             ` Peter Münster
2005-10-04 20:25               ` Alexander Lazic
2005-10-05  6:16                 ` Peter Münster
2005-10-05  6:43                   ` luigi.scarso
2005-10-05 21:08                     ` Alexander Lazic

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=8CF727E2-EDD0-49F4-AB8A-49DF6A9E1AC4@northcoast.com \
    --to=darnold@northcoast.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).