Sophie

Sophie

distrib > Mandriva > 9.0 > i586 > by-pkgid > 8d125f3514d54b70bf040165a2f5d2e4 > files > 349

maxima-5.6-1mdk.i586.rpm

<HTML>
<HEAD>
<!-- This HTML file has been created by texi2html 1.52
     from maxima.texi on 25 April 2001 -->

<TITLE>Maxima Manual - Plotting</TITLE>
<link href="maxima_8.html" rel=Next>
<link href="maxima_6.html" rel=Previous>
<link href="maxima_toc.html" rel=ToC>

</HEAD>
<BODY>
<p>Go to the <A HREF="maxima_1.html">first</A>, <A HREF="maxima_6.html">previous</A>, <A HREF="maxima_8.html">next</A>, <A HREF="maxima_41.html">last</A> section, <A HREF="maxima_toc.html">table of contents</A>.
<P><HR><P>


<H1><A NAME="SEC27" HREF="maxima_toc.html#TOC27">Plotting</A></H1>



<H2><A NAME="SEC28" HREF="maxima_toc.html#TOC28">Definitions for Plotting</A></H2>

<P>
<DL>
<DT><U>Variable:</U> <B>IN_NETMATH</B> <I>[FALSE]</I>
<DD><A NAME="IDX184"></A>
If not nil, then plot2d will output a representation of the plot
which is suitable for openplot functions.  
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> <B>OPENPLOT_CURVES</B> <I>list rest-options</I>
<DD><A NAME="IDX185"></A>
Takes a list of curves such as

<PRE>
[[x1,y1,x2,y2,...],[u1,v1,u2,v2,...],..]
or 
 [[[x1,y1],[x2,y2],...],.. ]
</PRE>

<P>
and plots them.  This is similar to xgraph_curves, but uses the
open plot routines.
Addtional symbol arguments may be given such as
<CODE> "{xrange -3 4}" </CODE>
The following plots two curves, using big points, labeling the first one
<CODE>jim</CODE> and the second one <CODE>jane</CODE>.   

<PRE>
openplot_curves([["{plotpoints 1} {pointsize 6} {label jim}
      {text {xaxislabel {joe is nice}}}"] ,
      [1,2,3,4,5,6,7,8],
      ["{label jane} {color pink } "], [3,1,4,2,5,7]]);
</PRE>

<P>
Some other special keywords are xfun, color, plotpoints, linecolors,
pointsize, nolines, bargraph, labelposition, xaxislabel, and
yaxislabel.

</P>
</DL>

<P>
<DL>
<DT><U>Function:</U> <B>PLOT2D</B> <I>(expr,range,...,options,..)</I>
<DD><A NAME="IDX186"></A>
<DT><U>Function:</U> <B>PLOT2D</B> <I>([expr1,expr2,..,exprn],xrange,...,options,..)</I>
<DD><A NAME="IDX187"></A>
EXPR is an expression to be plotted on y axis as
a function of 1 variable.
RANGE is of the form [var,min,max] and expr is assumed to
be an expression to be plotted against VAR.
In the second form of the function a list of expressions may
be given to plot against VAR.   Truncation in the y direction will
be performed, for the default y range.   It may be specified
as an option or using SET_PLOT_OPTION.

</P>

<PRE>
plot2d(sin(x),[x,-5,5]);
plot2d(sec(x),[x,-2,2],[y,-20,20],[nticks,200]);
</PRE>

</DL>

<P>
<DL>
<DT><U>Function:</U> <B>xgraph_curves(list)</B>
<DD><A NAME="IDX188"></A>
graphs the list of `point sets' given in list by using xgraph.

</P>
<P>
A point set may be of the form

</P>

<PRE>
[x0,y0,x1,y1,x2,y2,...] or
[[x0,y0],[x1,y1],....]
</PRE>

<P>
A point set may also contain symbols which give labels or other
information.

</P>

<PRE>
 xgraph_curves([pt_set1,pt_set2,pt_set3]);
</PRE>

<P>
would graph the three point sets as three curves.

</P>

<PRE>
pt_set:append(["NoLines: True","LargePixels: true"],
        [x0,y0,x1,y1,...])
</PRE>

<P>
would make the point set [and subsequent ones], have  
no lines between points, and to use large pixels.
See the man page on xgraph for more options to specify.

</P>

<PRE>
pt_set:append([concat("\"","x^2+y")],[x0,y0,x1,y1,...])
</PRE>

<P>
would make there be a "label" of "x^2+y" for this particular
point set.    The <CODE>"</CODE> at the beginning is what tells
xgraph this is a label.

</P>

<PRE>
pt_set:append([concat("TitleText: Sample Data")],[x0,...])
</PRE>

<P>
would make the main title of the plot be "Sample Data" instead
of "Maxima PLot".

</P>
<P>
To make a bar graph with bars which are .2 units wide, and
to plot two possibly different such bar graphs:

<PRE>
xgraph_curves(
       [append(["BarGraph: true","NoLines: true","BarWidth: .2"],
               create_list([i-.2,i^2],i,1,3)),
        append(["BarGraph: true","NoLines: true","BarWidth: .2"],
           create_list([i+.2,.7*i^2],i,1,3))
]);
</PRE>

<P>

</P>

<P>
A temporary file <TT>`xgraph-out'</TT> is used.

</P>

</DL>

<P>
<DL>
<DT><U>Variable:</U> <B>PLOT_OPTIONS</B>
<DD><A NAME="IDX189"></A>
Members of this list indicate defaults for plotting.  They may
be altered using SET_PLOT_OPTION

</P>

<PRE>
[X, - 3, 3]
[Y, - 3, 3]
</PRE>

<P>
are the x range and y range respectively.

</P>
<P>
[TRANSFORM_XY, FALSE]
if not false, should be the output of

</P>

<PRE>
make_transform([x,y,z], [f1(x,y,z),f2(x,y,z),f3(x,y,z)])
</PRE>

<P>
which produces a transformation from 3 space to 3 space, which
will be applied to the graph.   A built in one is polar_xy which
gives the same as

</P>

<PRE>
make_transform([r,th,z],[r*cos(th),r*sin(th),z])

</PRE>

<P>
[RUN_VIEWER,TRUE] if not false, means run the viewer software - don't just
output a data file.

</P>
<P>
[GRID,30,30] means plot3d should divide the x range into 30 intervals
and similarly the y range.

</P>
<P>
[COLOUR_Z,false] applies to colouring done with plot_format ps.

</P>
<P>
[PLOT_FORMAT,OPENMATH] is for plot3d and currently  OPENMATH,
GNUPLOT, PS, and GEOMVIEW are supported.

</P>
<P>
There are good quality public domain viewers for these formats.
They are openmath, izic, gnuplot, ghostview, and geomview.

</P>
<P>
The Openmath viewer is in the distribution, and is based on tcl/tk.
The executable is <TT>`maxima/bin/omplotdata'</TT>.  The viewer lets you
zoom in, slide around, and rotate (if 3 dimensional).  This format is
also the one used by netmath, for making plots with Netmath. (see
<TT>`http://www.ma.utexas.edu/users/wfs/netmath.html'</TT>)

</P>
<P>
geomview is from the Geometry Center at the University of Minnesota, and
is available from
<TT>`http://www.geom.umn.edu/software/download/geomview.html'</TT> or by
anonymous ftp from <TT>`ftp://ftp.geom.umn.edu/pub/software/geomview/'</TT>.  It
is currently not quite as pretty as izic, but provides excellent support
for multiple objects and multiple lights.

</P>
<P>
gnuplot is everywhere as is ghostview.   We also provide mgnuplot,
a tcl interface for gnuplot, which lets you rotate the plots using
the mouse and a scale.

</P>
<P>
izic is available by ftp from zenon.inria.fr.  Contact one of

</P>
<P>
{fournier,kajler,mourrain}@sophia.inria.fr.

</P>
<P>
It has beautiful colour gouraud shading, and very fast wireframe.  It
runs on X windows.

</P>

</DL>
<P>
<DL>
<DT><U>Function:</U> <B>PLOT3D</B> <I>(expr,xrange,yrange,...,options,..)</I>
<DD><A NAME="IDX190"></A>
<DT><U>Function:</U> <B>PLOT3D</B> <I>([expr1,expr2,expr3],xrange,yrange,...,options,..)</I>
<DD><A NAME="IDX191"></A>

</P>

<PRE>
plot3d(2^(-u^2+v^2),[u,-5,5],[v,-7,7]);
</PRE>

<P>
would plot z = 2^(-u^2+v^2) with u and v varying in [-5,5] and
[-7,7] respectively, and with u on the x axis, and v on the y axis.

</P>
<P>
An example of the second pattern of arguments is

<PRE>
plot3d([cos(x)*(3+y*cos(x/2)),sin(x)*(3+y*cos(x/2)),y*sin(x/2)],
   [x,-%pi,%pi],[y,-1,1],['grid,50,15])
</PRE>

<P>
which will plot a moebius band, parametrized by the 3 expressions given
as the first argument to plot3d.  An additional optional argument
[grid,50,15] gives the grid number of rectangles in the x direction and
y direction.

</P>

<PRE>
/* REal part of z ^ 1/3 */
 plot3d(r^.33*cos(th/3),[r,0,1],[th,0,6*%pi],
     ['grid,12,80],['PLOT_FORMAT,ps],
     ['TRANSFORM_XY,POLAR_TO_XY],['VIEW_DIRECTION,1,1,1.4],
     ['COLOUR_Z,true])
</PRE>

<P>
Here the View_direction indicates the direction from which we
take a projection.  We actually do this from infinitely far away,
but parallel to the line from view_direction to the origin.  This
is currently only used in 'ps' plot_format, since the other viewers
allow interactive rotating of the object.

</P>
<P>
Another example is a moebius band:

<PRE>
plot3d([cos(x)*(3+y*cos(x/2)),
          sin(x)*(3+y*cos(x/2)),y*sin(x/2)],
           [x,-%pi,%pi],[y,-1,1],['grid,50,15]);
</PRE>

<P>
or a klein bottle:

</P>

<PRE>
plot3d([5*cos(x)*(cos(x/2)*cos(y)+sin(x/2)*sin(2*y)+3.0) - 10.0,
          -5*sin(x)*(cos(x/2)*cos(y)+sin(x/2)*sin(2*y)+3.0),
           5*(-sin(x/2)*cos(y)+cos(x/2)*sin(2*y))],
           [x,-%pi,%pi],[y,-%pi,%pi],['grid,40,40])
</PRE>

<P>
or a torus

<PRE>
plot3d([cos(y)*(10.0+6*cos(x)),
           sin(y)*(10.0+6*cos(x)),
           -6*sin(x)], [x,0,2*%pi],[y,0,2*%pi],
            ['grid,40,40])
</PRE>

<P>
We can output to gnplot too:

</P>

<PRE>
 plot3d(2^(x^2-y^2),[x,-1,1],[y,-2,2],[plot_format,gnuplot])
</PRE>

<P>
Sometimes you may need to define a function to plot the expression.  All
the arguments to plot3d are evaluated before being passed to plot3d, and
so trying to make an expression which does just what you want may be
difficult, and it is just easier to make a function.   

<PRE>
M:MATRIX([1,2,3,4],[1,2,3,2],[1,2,3,4],[1,2,3,3])$
f(x,y):=float(M[?round(x),?round(y)]);
plot3d(f,[x,1,4],[y,1,4],['grid,4,4]);
</PRE>

</DL>
<P>
<DL>
<DT><U>Function:</U> <B>PLOT2D_PS</B> <I>(expr,range)</I>
<DD><A NAME="IDX192"></A>
 writes to pstream a sequence of postscript commands which
plot EXPR for RANGE.
EXPR should be an expression of 1 variable.
RANGE should be of the form [variable,min,max]
over which to plot expr.
see CLOSEPS.

</P>
</DL>

<P>
<DL>
<DT><U>Function:</U> <B>CLOSEPS</B> <I>()</I>
<DD><A NAME="IDX193"></A>
This should usually becalled at the end of a sequence of plotting
commands.   It closes the current output stream PSTREAM, and sets
it to nil.   It also may be called at the start of a plot, to ensure
pstream is closed if it was open.    All commands which write to
pstream, open it if necessary.   CLOSEPS is separate from the other
plotting commands, since we may want to plot 2 ranges or superimpose
several plots, and so must keep the stream open.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> <B>SET_PLOT_OPTION</B> <I>(option)</I>
<DD><A NAME="IDX194"></A>
option is of the format of one of the elements of the PLOT_OPTIONS
list.
Thus

<PRE>
SET_PLOT_OPTION([grid,30,40])
</PRE>

<P>
would change the default grid used by plot3d.   Note that if the symbol
grid has a value, then you should quote it here:

<PRE>
SET_PLOT_OPTION(['grid,30,40])
</PRE>

<P>
so that the value will not be substituted.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> <B>PSDRAW_CURVE</B> <I>(ptlist)</I>
<DD><A NAME="IDX195"></A>

</P>
<P>
Draws a curve connecting the points in PTLIST.   The latter
may be of the form [x0,y0,x1,y1,...] or [[x0,y0],[x1,y1],...]
The function JOIN is handy for taking a list of x's and a
list of y's and splicing them together.
PSDRAW_CURVE simply invokes the more primitive function
PSCURVE.   Here is the definition:

</P>

<PRE>
(defun $psdraw_curve (lis)
  (p "newpath")
  ($pscurve lis)
  (p "stroke"))

</PRE>

<P>
 ?DRAW2D  may also be used to produce a list

<PRE>
 points1:?draw2d(1/x,[.05,10],.03) 
</PRE>

</DL>
<P>
<DL>
<DT><U>Function:</U> <B>PSCOM</B> <I>(com)</I>
<DD><A NAME="IDX196"></A>

</P>
<P>
COM will be inserted in the poscript file
eg

<PRE>
  pscom("4.5 72 mul 5.5 72 mul translate  14 14 scale");
</PRE>

</DL>

<P><HR><P>
<p>Go to the <A HREF="maxima_1.html">first</A>, <A HREF="maxima_6.html">previous</A>, <A HREF="maxima_8.html">next</A>, <A HREF="maxima_41.html">last</A> section, <A HREF="maxima_toc.html">table of contents</A>.
</BODY>
</HTML>