plotting.htmlTEXTMPadAʵee MathPad Manual _ Plotting

Plotting


Table of contents


Plotting functions


Xmin=-10; Xmax=10
Xdiv=2

plot 5*X

f(t) = t^3/10 - 5*t
plot f(X)
plot f(2*X)/10

label f(5):-12.500
Title = "Example Plot"
Ylabel = "f(X)"




Functions can be plotted by using the plot command and the special variable X (upper case). X is stepped between Xmin and Xmax with a resolution of Xsteps (default Xsteps=100). The calculated value for each X is plotted. This results in a good representation of the function as long as it is relatively smooth over the range being plotted. If the function is discontinuous or changing rapidly Xsteps can be increased to give a more accurate picture.

Various aspects of the plot are be controlled by several plot control variables. None of these special variables are required but usually at least Xmin and Xmax are specified.

An info line at the bottom of the plot window shows the lowest and highest Y values ("Ylo" and "Yhi") calculated during the plot. Clicking the mouse on the plot will show the trace number and the X,Y value of the plotted point nearest to the click.

The variables Ymin and Ymax can be used to set the Y axis limits. If Ymin and/or Ymax are not specified MathPad will auto-range based on Ylo and Yhi.

Multiple traces can be plotted simply by adding plot statements. Each new trace is drawn in a different color. Traces cycle through four colors: black, red, green and blue. The auto cycle can be overridden by setting the variable Tracecolor. For example Tracecolor=2 will plot all traces in red. Also see Marker symbols.

Axis ticks can be controlled by the variables Xdiv and Ydiv. If these variables are used they override the automatic axis. They specify the distance between labeled ticks in data units. The axis label format still assumes that "nice" divs (at most 2 digits of precision) will be used. This means that a div like .2 or .25 will work but a div of .234 will have rounded tick labels. If there are too many or too few divisions the axis will revert to automatic divisions.

Arbitrary text labels may be pasted into the plot window. Selecting "Paste Label" from the Edit menu will paste text from the clipboard into the upper left corner of the plot. Command-V will paste the label at the current mouse position if it is in the plot window. Labels can be moved by dragging with the mouse. Labels can be deleted by dragging them off the plot.

A label command can be used to put a line from the text window onto the plot as a movable label. The text following label is evaluated normally. This allows labels that will automatically update when the text is reevaluated.

The slabel command is similar except that it expects a string expression. The resulting string contents are placed on the plot as a movable label.

Special variables Xlabel, Ylabel and Title allow adding labels at preassigned locations. The plot size is adjusted to make room for these labels if they are present. These labels are not movable.

Grid lines can be turned on and off with Xshowgrid, Yshowgrid or with the Options... dialog.

Log axes can be set with the Options... dialog or with Xlogaxis or Ylogaxis. See the example Log Axes

A picture can be pasted from the clipboard into the plot to provide a background. The picture will be sized to fit inside the axis. See the example Navigation.

Multiple Axes


s(t) = 100*sin(t)/t



Xmin=-200; Xmax=200
Ymin=0
plot s(X)

newaxis
Xmin:=-2500:; Xmax:=2500:
Ymin:=?:-- enable autorange
plot s(X)





The newaxis command can be used to put more than one set of axes on a page. The plot control variables can be changed following a newaxis. They must be changed with an := assignment. All changes to plot control variables must appear before the first plot statement for the new axis.

Any plot control variables that are not assigned will keep their previous values. A variable can be set back to undefined by assigning "?"

The variable Ystrips can be used to preset the number of different axes that will be put on the page. The use of Ystrips is optional. It can be used to prevent extra redrawing of the plot window. Ystrips can either be set to the number of equal height strips (Ex. Ystrips=2) or it can be set to an array where the elements give a relative height for each strip. Ystrips = {1.7,1,1} specifies 3 strips, the 1st strip is given 70% more height.

Plotting arrays

The plot command can also plot points from 1D or 2D arrays.

Arrays can be given in 5 forms:

  1. array of y values {y1,y2,y3...}
  2. array of x,y pairs {{x1,y1},{x2,y2},{x3,y3},...}
  3. a pair of arrays {{x1,x2,...},{y1,y2,...}} (A 2 by 2 array is treated as {{x1,x2},{y1,y2}})
  4. parametric functions {fx(X),fy(X)} X steps 0 to 1.0
  5. array of y functions {fy1(X),fy2(X),fy3(X),...}
Xmin=0; Xmax=10; Ymin=0; Ymax=10

yarray={1,3,5,7,7,6,5}
plot yarray

xypairs = {{2,2},{2,8}, {8,8},{8,2},{2,2}}
plotline xypairs

xarray={4,4,5,6,6,6,7,8}
plotline {xarray,yarray}
plot {xarray,yarray}

For a 1D array {y1,y2,y3...} the element values are used for y. The points are plotted evenly spaced along the current X axis.

For 2D arrays, both x and y are taken from the array. When plotting x,y points, if Xmin and/or Xmax are not specified they will be auto-ranged. When plotting a mix of arrays and functions, the array should be plotted first to take advantage of X auto-ranging.

The plot command plots a marker at each point. The plotline command can be used to connect the points for any array plot. For {x,y} plots the points are connected in the order that they appear in the array. An undefined point causes the pen to be lifted. The pen is put down when the next defined point is found. If a single defined point is surrounded by undefineds it will not be plotted.

Arrays can be read in from data files.

Marker symbols

When arrays are plotted using plot each point is plotted as a marker symbol. Each trace uses a different symbol and color.

 

Markers and colors cycle so that many different traces can be plotted and each will be given a unique colored symbol.

Control variables can be used to override the default cycle. The variable Marker can be used to set which marker is used. The variable Markersize can be used to increase or decrease the size of marker symbols. Markersize=2 gives a marker that is roughly twice the default size. Tracecolor can be used to control the color of the markers and traces. The four trace colors are: 1-black, 2-red, 3-green and 4-blue.

These control variables can be changed between each trace using :=. They can also be set to an array that specifies a separate value for each trace. If an array is used there must be enough elements to specify all traces plotted.

If a valid marker is specified for a plotline trace, both markers and connecting lines will be plotted. If a marker of zero is specified for a plot trace, connecting lines will be drawn with no markers.

Parametric Equations

For {fx(X),fy(X)} Xmin and Xmax specify the range of fx() values that will be plotted. The variable X is stepped from 0 to 1.0 regardless of Xmin and Xmax. The values of X can be scaled to produce an independent variable that is used to calculate both x and y.

-- run deg 0 to 360 in 10° steps
deg=X*360; Xsteps=36

x(angle)=cos(angle)
y(angle)=sin(angle)

Xmin:=-1.1:; Xmax:=1.1:
Ymin:=-1.1:; Ymax:=1.1:

plot {x(deg),y(deg)}
plotline {x(deg),y(deg)}
Parametric plots can also be done by defining an array for the independent variable.

deg[i] = (i-1)*10 dim[37]-- run deg 0 to 360 in 10° steps

Polar coordinates

There is no built-in support for polar plots but it is easy to define a function to convert to cartesian coordinates. Polar functions can be plotted as parametric equations.
polar(r,theta) = {r*cos(theta),r*sin(theta)}

cardoid(theta) = 1-cos(theta)
deg[i] = (i-1) dim[361]-- run deg 0 to 360

Xmin=-2; Xmax=2; Ymin=-2; Ymax=2
plotline polar(cardoid(deg),deg)


A graphic of a polar grid can be created with a draw program and pasted in as a background. The grid must be drawn so that it will align properly with the axes used.

Plotting a family of curves

An array of 3 or more functions will be plotted as multiple traces. X is stepped from Xmin to Xmax for each function.
f(x)[i] = i/(x+i) dim[10]
Xmin=0; Xmax=20
plot f(X)

Plotting surfaces



Arrays representing surfaces can be displayed with the image command. Each array element is displayed as a tile filled with a color corresponding to its value. See the example
Images

The XFun viewsurf can be used to show a 3D projection of a surface. See the example 3D plotting.

Plot Output

The plot can be printed. For printing, the plot is re-sized to the page regardless of the current plot window size. Printing is done at the highest printer resolution so it may be useful to increase Xsteps for a smoother plot. The Options... dialog controls whether the info line is included.

The font can be changed with the Edit menu when the plot window is in front.

The plot window zoom box sets the window to the current printer page aspect. This allows a crude print preview so you can position labels appropriately for printout.

Graphics Export

The Save Plot... menu item allows you to save the plot window as a PICT file. You can set the size and scaling of the PICT.

PICT files at the default 72dpi resolution tend to look jaggy when printed or enlarged. Scaling up or changing the resolution allows the export of higher resolution plots. The treatment of PICT resolutions varies widely with application so you may need to experiment to find what works best with the application you are exporting to.

Save Plot... also allows you to use QuickTime to save directly in different graphics formats such as BMP,JPEG and TIFF. You should see an Export... button in the dialog if Quicktime 3.0 or better is installed on your system. The number of output formats available will depend on which QuickTime converters are installed.

The plot can be copied to the clipboard as a PICT. The "Copy Plot" menu items are enabled when the plot window is in front. The clipboard image will be the same size as the current plot window size. The "Copy Plot at 4X" command scales the image up to provide a higher resolution image for applications that can import and re-size PICTs. For applications that support high resolution PICTs, use the Options.. dialog to set Copy at 288dpi. This will change the menu item so that the plot will be copied at high resolution without having to re-size it.



Plot control variable summary

X independent variable
Xmin=n minimum value for X axis
Xmax=n maximum value for X axis
Xsteps=n resolution for stepping X values
Xdiv=n distance between axis ticks
Xlabel="label" add X axis label
Xlogaxis=on use log X axis
Xshowgrid=onshow vertical grid lines
Xticklabels=offsuppress X axis numeric tick labels
 
Ymin=n minimum value for Y axis
Ymax=n maximum value for Y axis
Ydiv=n distance between axis ticks
Ylabel="label" add Y axis label
Ylogaxis=on use log Y axis
Yshowgrid=on show horizontal grid lines
Yticklabels=offsuppress Y axis numeric tick labels
 
Zmin=n image data minimum
Zmax=n image data maximum
Zlabel="label" add Z axis label
Zlogaxis=on log image data
Zshowbar=offsuppress Z color bar
 
Ystrips=n preset the number of different axes
Ystrips={1,2,...} preset relative height of each strip
Title="label" add label at top of page
 
Tracecolor=1-black, 2-red, 3-green, 4-blue
Marker=
Markersize=2.0use double size markers

ddf0&ASLM PreferencesaR+ ?5Ȯ7,)Monaco9Monaco9$???ddf3ZPRefSTR#&SPRF2$ <$ font & size