iconEuler Reference

Plot Functions plot2d and plot3d

The main plot functions plot2d and plot3d.

plot2d handles all plotting in the plane. This includes plots of funtions of one variable, implicit plots of functions of two variables, plots of curves and polygons in the plane, data and bar plots of two vectors, or clouds of points in the plane.

plot3d handles all plotting in 3D stereographic view. This includes plots of functions of two variables, implicit plots of functions of three variables, plots of surfaces, bar plots of matrices, or clouds of points in the space. There is an option to view the plot in anaglyph mode with red/cyan glasses.

For a demonstration of 2D plots in Euler, see the following introduction notebook.

function plot2d (xv,yv=none,btest=none, ..
    a=none,b=2,c=none,d=2, ..
    xmin=none,xmax=1, r=0, n=100, logplot=0, ..
    grid=2, frame=3, framecolor=none, ..
    square=0, color=none, thickness=1, style=none, auto=1, add=0, ..
    user=0, delta=0.1, points=0, ..
    bar=0, histogram=0, distribution=0, even=0, steps=0,..
    own=0, adaptive=1, ..
    hue=0, level=none, contour=0, nc=40, ..
    filled=0, fillcolor=none, outline=1, ..
    title="",xl=none,yl=none, ..
    maps=0, ..
    contourcolor=none, contourwidth=1, ..
    ticks=1, margin=none, clipping=true, ..
    cx=0, cy=0, ..
    insimg=0, spectral=0)

  Multipurpose plot function for plots in the plane.
  
  Overview: The function can plot
  
  - expressions or functions of one variable,
  - parametric curves,
  - x data against y data,
  - implicit functions,
  - bar plots,
  - polygons.
  
  If a function or expression for xv is given, plot2d will compute
  values in the given range using this function or expression. The
  expression must be a string expression in the variable x. The range
  must be defined in the parameters a and b unless the default range
  [-2,2] should be used. The y-range will be computed automatically,
  unless c and d are specified, or a radius r, which yields the range
  [-r,r] for x and y. For plots of functions, plot2d will use an
  adaptive evaluation of the function by default. To speed up the
  plot for complicated functions, switch this off with adpative=0,
  and otionally decrease the number of intervals n. Moreover, plot2d
  will by default use mapping. I.e., it will compute the plot element
  for element. If your expression or your functions can handle a
  vector x, you can switch that off with maps=0. Note that adaptive
  plots are always computed element for element.
  
  If functions or expressions for both xv and for yv are specified,
  plot2d will compute a curve with the xv values as x-coordinates and
  the yv values as y-coordinates. In this case, a range should be
  defined for the parameter using xmin, xmax. Expressions contained
  in strings must always be expressions in the parameter variable x.
  
  If xv and yv are data vectors, these data will be used as x- and
  y-coordinates of a curve. In this case, a, b, c, and d, or a radius
  r can be specified, or the plot window will adjust automatically to
  the data. Alternatively, square=1 can be set to keep a square
  aspect ratio.
  
  The function plot2d can also plot curves or data as filled
  polygons with filled=1. The fill color is determined by
  fillcolor=1, and on optional outline=0 prevents drawing the
  boundary for all styles but the default one.
  
  If xv is a sorted vector, and yv is a vector of intervals, then
  plot2d will plot the filled ranges in the plane. The fill styles
  are the same as the styles of polygons.
  
  Implicit plots show level lines solving f(x,y)=level, where
  "level" can be a single value or a vector of values. If
  level="auto", there will be nc level lines, which will spread
  between the minimum and the maximum of the function evenly. Darker
  or lighter color can be added with hue=1 to indicate value of the
  function. For implicit functions, xv must be a function or an
  experssion of the parameters x and y, or, alternatively, xv can be
  a matrix of values.
  
  The data for bar plots (bar=1) and histograms (histogram=1) can
  either be explicitely given in xv and yv, or can be computed from
  an empirical distribution in xv (with distribution=1). Histograms
  of xv values will be computed automatically with histogram=1. If
  even=1 is specified, the xv values will be counted in integer
  intervals.
  
  Logarithmic plots can be plotted either using a logarithmic scale
  in y with logarithmic=1, or using logarithmic scales in x and y
  with logarithmic=2.
  
  If you wish to show more than one function in a single plot use
  several calls to plot2d, and add=1 in all, but the first call, or
  provide a vector of expressions and functions, or use a matrix of
  yv values, with one function in each row.
  
  If xv is a function or an expression, user=1 allows the user to
  zoom (+/-), set the plot window with the mouse, or move the
  plot (cursor keys). The space key will reset the plot to the
  original plot window. If xv is a data, then user=1 will simply wait
  for key stroke.
  
  title="string" can be used to describe the plot. The title will
  appear above the plot. Moreover, a label for the x and y axis can
  be added with xl="string" or yl="string". Other labels can be added
  in a separate call to the function "label".
  
  Note: expressions and functions are mapped automatically in plot2d.
  
  Parameters
  
  x,y : equations, functions or data vectors
  
  a,b,c,d : Plot area (default a=-2,b=2)
  r : if r>0 then a=cx-r, b=cx+r, c=cy-r, d=cy+r
  xmin,xmax : range of the parameter for curves
  auto : Determine y-range automatically
  square : if 1, try to keep square x-y-ranges
  n : number of intervals
  grid : 0 = no grid and labels,
  1 = axis only,
  2 = normal grid,
  3 = inside axis
  4 = no grid
  5 = full grid including margin
  frame: 0 = no frame
  framecolor: color of the frame and the grid (default 3)
  margin : number between 0 and 1 for the margin around the plot
  
  color : plot color for curves (default 1)
  thickness : line thickness for curves (default 1)
  style : plot style for lines, markers, and fills
  for points use
  "[]", "<>", ".", "..", "...",
  "*", "+", "|", "-", "o"
  "[]#", "<>#", "o#" (filled shapes)
  "[]w", "<>w", "ow" (non-transparent)
  for lines use
  "-", "--", "-.", ".", ".-.", "-.-", "->"
  for filled polygons or bar plots use
  "#", "#O", "O", "/", "\", "\/",
  "+", "|", "-", "t"
  points : plot single points instead of line segments
  
  add : add the plot to the existing plot
  user : enable user interaction for functions
  delta : step size for user interaction
  
  bar : bar plot (x are the interval bounds, y the interval values)
  histogram : plots the frequencies of x in n subintervals
  distribution=n : plots the distribution of x with n subintervals
  even : use inter values for automatic histograms.
  
  steps : plots the function as a step function (steps=1,2)
  adaptive : use adaptive plots (n is the minimal number of steps)
  
  level : plot level lines of an implicit function of two variables
  hue : add hue color to the level plot to indicate the function
  value
  contour : Use level plot with automatic levels
  nc : number of automatic level lines
  
  title : plot title (default "")
  xl, yl : labels for the x- and y-axis
  
  filled : fill the plot of a curve
  fillcolor : fill color for bar and filled curves
  outline : boundary for filled polygons
  
  logplot : if 1, logplot in y, if 2 logplot in xy
  
  own : a string, which points to an own plot routine. With user=1,
  you get the same user interaction as in plot2d. The range
  will be set before each call to your function.
  
  maps : map expressions (0 is faster), functions are always mapped.
  
  contourcolor : color of contour lines
  contourwidth : width of contour lines
  
  clipping : toggles the clipping (default is true)
  
  Available index colors are
  
  white=0,black=1,red=2,green=3,blue=4,
  cyan=5, olive=6, lightgray=7, gray=8,
  darkgray=9, orange=10, lightgreen=11, turquoise=12,
  lightblue=13, lightorange=14, yellow=15.
  
  or use rgb(red,green,blue).
  
  Some settings can be changed globally only.
  
  setgrid("--",".",3) : Grid style and color
  
  Examples:
  
  >plot2d("x^3-x",-1,2,title="y=x^3-x",yl="y",xl="x");
  >plot2d("x^3-x",a=0,b=2,c=-1,d=2,grid=3,<frame);
  >plot2d("x^3-x",>user,title="Press any key!");
  
  >function f(x) &= x^x;
  >plot2d(f,r=1,cx=1,cy=1,color=blue,thickness=2);
  >plot2d(&diff(f(x),x),>add,color=red,style="-.-");
  
  >x=linspace(0,2pi,1000);
  >plot2d(sin(5x),cos(7x));
  >plot2d(sin(x),cos(x)*0.5,r=1,>filled,style="/");
  
  >k=0:10;
  >plot2d(k,bin(10,k),>bar);
  >plot2d(k,bin(10,k)); plot2d(k,bin(10,k),>points,>add);
  
  >plot2d(normal(1,1000),>distribution,style="O");
  >plot2d("qnormal",0,5;2.5,0.5,>filled);
  
  >plot2d("x^2",0,1,steps=1,color=red,n=10);
  >plot2d("x^2",>add,steps=2,color=blue,n=10);
  
  >plot2d("x^3-y^2",>contour,>hue,>spectral);
  >plot2d("x^3-y^2",level=0,contourwidth=3,>add,contourcolor=red);
  
  See: 
plot3d (Plot Functions plot2d and plot3d),
plot3d (Maxima Documentation),
label (Basic Plot Functions),
label (Maxima Documentation),
rgb (Basic Plot Functions)
function plot3d (x, y=none, z=none, disconnect=none, ..
    xmin=-1,xmax=1,ymin=-1,ymax=1, ..
    a=none,b=none,c=none,d=none, ..
    n=40,scale=1,fscale=-1,frame=1,r=0, ..
    xlabel="x",ylabel="y",zlabel="z",polar=0, ..
    sliced=0, ..
    hue=0,light=[2,3,4],amb=0.1,max=0.9, ..
    anaglyph=0, ..
    user=0,duser=0.1, ..
    wire=0, wirecolor=none, points=0, lines=0, contour=0, ..
    rotate=0,title="",style=".", ..
    level=none,add=0, ..
    implicit=0,zmin=-1,zmax=1, ..
    angle=none,height=none,zoom=none,distance=none,view=none, ..
    center=none, ..
    bar=0, values=none,own=0, ..
    maps=0, ..
    contourcolor=none, contourwidth=1, ..
    color=1, framecolor=none, ..
    cx=0, cy=0, cz=0, ..
    insimg=0, spectral=0, xhue=0, yhue=0, zhue=0, hues=none, ..
    sframe:real vector=none)

  General function for 3D plots.
  
  Overview: This function can plot
  
  - the graph of a function in two variables,
  - as a wire plot,
  - a solid plot,
  - optionally with shading,
  - or with level lines.
  - surfaces, described by three matrices of x-, y-, and
  z-coordinates, or by three functions of two parameters.
  - curves in space,
  - a cloud of points,
  - implicit functions,
  - analgyphs.
  
  The plot3d function uses the convention, that the x axis goes to
  the right, the y axis points into the screen, and the z axis goes
  vertically upwards. The plot can be turned, however, to the left
  and right around the z axis, and up and down. The point the plot
  looks at is the origin by default.
  
  To plot a function of x and y, use an expression string or a
  function name for the first parameter x. "plot3d" will evaluate
  the function on a grid of x and y values, and plot the graph of the
  function. The parameter n determines the number of grid lines in
  both directions. The function values will be scaled in z direction,
  but not in x or y direction. By default (fscale=-1), the scaling
  will depend on the x and y range to make the graph look good. But
  an own scaling factor can be used by setting fscale to some
  positive value. fscale=0 will use no scaling. All 3D plots can be
  scaled in all directions with the parameter scale. Instead of
  rectangle coordinates, polar coordinates can be used with polar=1.
  
  To plot a surface from data, plot3d needs the x, y and z
  coordinates of the surface. These coordinates must be stored in
  three matrices. So the parameterization of the surface is always
  rectangular. Note, that three matrices with compatible size must be
  provided, one for each coordinate of the surface. Row and column
  vectors will be expanded using the rules of the Euler matrix
  language.
  
  If three function names, or three expressions of the variables x
  and y are provided then plot3d will compute the coordinates of
  the surface using the ranges [xmin,xmax] for x or [ymin,ymax] for y.
  Again, n will be the number of partitions.
  
  To add shading to a solid plot, use hue=1. The shading will be
  computed assuming a light from a given direction, and ambient light
  of a given brightness. Contour lines can be added to a shaded plot
  with contour=1. Contour lines at specific levels can be added with
  level=v, where v is a vector of level values. These values for
  contour and level refer to the z value of the surface. However, if
  a matrix of values is provided with values=w, then these values
  will be used to plot the contour lines at the specific levels.
  This form of level lines will work only for surfaces given by data,
  and if level=v is provided additionally.
  
  To plot a cloud of points, use three vectors of x, y and z
  coordinates, and set points=1. You can set the point style with
  style, which must be one of "[]", "<>", ".", "..", "*", "+", or
  "o". For a big lot of points, it looks good to use ".", and
  optionally view the cloud in anaglyph mode (anaglyph=1). For a
  point cloud with points in different colors, the color parameter
  can be a row vector of colors. In this case, the points in the back
  are drawn before the points in the front.
  
  A surface can also be drawn as a wire frame plot with wire=1. To
  plot one curve or several curves in 3D, either provide three
  vectors of data containing the x, y and z parameters of the curve,
  or three functions or expressions in the variable x, and set
  lines=1. In the case of three functions, the range [xmin,xmax] is
  used. To plot several curves at once, use three matrices, with one
  row for each curve, and specify lines=1.
  
  Functions of one variable rotated around the x axis can be plotted
  with rotate=1. In this case, plot3d needs an expression in x, or a
  function f(x), and the range is [xmin,xmax]. The function can also
  be rotated around the z axis (rotate=2). In this case use a
  non-negative xmin.
  
  Implicit plots show the solutions of f(x,y,z)=0 with implicit=1.
  The function needs an expression in x, y, and z, or the name of a
  function f. Cuts trough this set orthogonal to an axis will be
  drawn. Use 1 for the x-axis, 2 for the y-axis and 4 for the z-axis.
  You can add these values to show cuts in several directions.
  Implicit plots are the slowest of the 3D plots. You can speed up
  the plot using expressions, which can handle matrices, with
  maps=0.
  
  Plots can be interactive with user=1. In this case the user can
  turn the plot with the cursor keys, and zoom the plot with +/-. The
  space key will reset the default view. For solid plots with light,
  the key l will toggle to the movement of the light. The center of
  the plot can also be moved in four directions. You can toggle the
  movement of the plot center with the key c.
  
  All plots can be anaglyphs. Use red/cyan glasses to see the rather
  nice 3D effect. Either enter the paparemter analgyph=1, or press a
  in interactive plots.
  
  Note: Functions are mapped automatically in plot2d. Expressions
  must be able to map to their arguments. So use plot("f",...) not
  plot("f(x,y)",...), if "f" does not map.
  
  Parameters
  
  x : expression in x and y
  x,y,z : matrices of the coordinates of a surface
  x,y,z : expressions in x and y for a parametric surface
  x,y,z : expressions in x to plot a line
  xmin,xmax,ymin,ymax : for plots over rectangles
  a,b,c,d : alternative for xmin,xmax,ymin,ymax
  r : a radius can be used instead of xmin,xmax,ymin,ymax
  cx, cy, cr : center of plot, if r is used
  r : also used for polar plots
  n : accuracy
  scale : scale plot to this size (0 = no scaling, 1 = default)
  if scale is a 1x3 vector, it will scale in each direction
  fscale : scales the values for function to this range (0=no, -1=auto)
  
  wire : wire plot
  polar : polar plot
  points : cloud of points
  
  sliced : plot a scliced version (0=no, 1=x-direction, 2=y-direction)
  hue : compute shading
  light, amb, max : controls the shading
  contour : set automatic level (1=solid hue, 2=only contour lines)
  spectral : use spectral colors instead of monochrome hue
  xhue,yhue,zhue : use these coordinates instead of default lighting
  hues : a matrix of hue values from 0 to 1
  level : 2D level plot of these levels
  add : adds a level plot to another
  
  user : user can turn the plot around with the keyboard
  duser : controls the user action
  
  lines : a line given by three expressions
  rotate : rotation plot, the function must be of one variable
  
  anaglyph : 3d plot
  
  viewangle : changes the default angle of view
  viewheight : changes the height of view
  zoom : changes the zoom of view
  distance : changes the distance of view
  view : sets the default view
  
  implicit : for implict plots of f(x,y,z)
  0=off, 1=x, 2=y, 4=z, can be combined by adding
  values : values to be used for contour plots (default: z-values)
  
  style : plot style for markers (see plot2d for available styles)
  
  maps : expressions should be mapped (faster, if 0), functions
  are always mapped.
  
  contourcolor : color of contour lines
  contourwidth : width of contour lines
  color : color for markers and for shaded surfaces
  wirecolor : color for wire plots
  
  frame : If 0, no frame is drawn. If this is a vector, it must be of
  the form [xmin,xmax,ymin,ymax,zmin,zmax] and will be used as a
  frame for plots. The plot must fit into the frame then.
  framecolor : color of the 3D frame
  
  sframe : Sets the tick values for the axes. This is a vector of the
  same form as frame.
  
  Some settings are global
  
  fillcolor(11,3) : fill color for 3d surfaces (no hue).
  twosides(1) : show two different colors.
  
  Examples:
  
  >plot3d("x*y",r=1,title="z=x*y");
  >plot3d("x*y^2",>user,r=1,title="Press cursor keys or return!");
  >plot3d("x^2*y^3",r=0.9,zlabel="x^2*y^3",angle=30°,height=20°,zoom=3);
  >plot3d("x^2+y^3",angle=0°,>contour,>spectral);
  >plot3d("x^y-y^x",a=0,b=4,c=0,d=4,angle=40°,level=0,n=100);
  >plot3d("x^2+y^2",>wire,>anaglyph,title="Use Red/Cyan Glasses!");
  
  >plot3d("x^2+y^3+sin(z)^2-1",r=pi,implicit=4,zoom=3);
  
  >x=-1:0.05:1; y=x';
  >plot3d(x,x*y^2,y,>hue,angle=20°);
  >h=x^2+y^2;
  >plot3d(x,y,(y-x)/2,level=-2:0.1:2,values=h,hues=h/2,>spectral);
  
  >X=normal(3,1000);
  >plot3d(X[1],X[2],X[3],>points,zoom=3,>user,title="Press return or cursor key!");
  >Y=cumsum(X);
  >plot3d(Y[1],Y[2],Y[3],>wire,>user,zoom=3,title="Press return or cursor key!");
  
  >t=linspace(0,2,1000);
  >plot3d(sin(2pi*t),cos(2pi*t),t,>wire,>anaglyph);
  
  See: 
plot2d (Plot Functions plot2d and plot3d),
plot2d (Maxima Documentation)

Documentation Homepage