Use the following command to create a figure and assign it to a variable named "fig":
fig = figure.new();
plot is an attribute function of figure and can treat two vectors x and y as coordinates of the locations of a sequence of points in the 2d plane. Marks can be drawn at these locations, or lines and curves drawn through them. The command for plotting x and y data on figure fig is
fig.plot(x, y, linetype, linewidth, color, gray);where x and y are two vectors of the same length. The plot can be straight line segements joining the points, marks placed at the locations defined by x and y, or a smooth curve (a piece-wise cubic polynomial) through the dots. The type of the plot is specified by the argument linetype.
solid | -- | dotty | .... |
dash | - - - - | dashdot | --.--.--. |
dot | . . . . | circle | |
oval | square | ||
diamond | cross | ||
flake | asterisk | ||
triangle | dtriangle | ||
plus | +++ | curve | (smooth curve) |
linewidth is a number. The line to be drawn will be linewidth times as wide as the default linewidth. For example, to make the line twice as wide as the normal, use value 2.
color is a vector of three numbers between 0 and 1, with each component representing the intensity of red, green, or blue. gray is a number between 0 and 1.
It's not necessary to provide all the arguments to plot. The default values of linetype, linewidth, color, and gray are "solid", 1, [0, 0, 0], and 1. Therefore a simple call
fig.plot(x, y);will draw solid straight line segments through the (x, y) points; the width of the lines is 1 unit, and the color is black. This is because that when calling a function, you may provide only the first few arguments, the others will receive default values. For example,
xx = [0, 1, 2, 3, 4, 5]; yy = [0, 1, 0.5, 0.75, 0.625, 0.6875]; fig.plot(x, y);
To change the line type,
fig.plot(xx, yy, "oval");
To change the line width as well
fig.plot(xx, yy, "oval", 2);
If you just want to specify the line width, you still have to provide at least the first four arguments, but you can use default value for the third argument linetype
fig.plot(xx, yy, *, 2);
Named argument By the previous way of calling fig.plot, the order of arguments have to match the signature of the function. Alternatively, you can use named arguments. For example
fig.plot{x = xx, y = yy, linewidth = 2};Note that you can not only skip certain arguments, but don't have to follow any specific order of argument either. For example
fig.plot{y = yy, linewidth = 2, x = xx};However you still need to provide the correct names of the arguments, namely, x, y, linewidth, etc.
Example
xx = [0, 1, 2, 3, 4, 5]; yy = [0, 1, 0.5, 0.75, 0.625, 0.6875]; fig = figure.new(); fig.plot(xx, yy, *, *, colors.green); fig.plot(xx, yy*0.8, "curve", *, colors.purple); fig.plot(xx, yy*0.8, "oval"); fig.plot{x = xx, y = yy*0.3, linetype = "curve", color = colors.red}; fig.plot{x = xx, y = yy*0.3, linetype = "diamond", linewidth = 2, color = colors.olive}; fig.save("symbols.eps");
Some simple shapes can be drawn on the canvas without first defing data.
To draw a line segement you need to specify the starting and the end points.
fig.line(P0, P1, style, linetype, linewidth, color);where P0 and P1 are the starting and end points of the line segement. style is one of "-", "->", "<-", or "<->" which specifies whether one end or both ends of the line has an arrow. linetype is either "solid" or "dotty".
The command
fig.polygon(x, y, type, color);will draw a polygon given the x and y coordinates of the vertices. type can be "contour" or "solid", which specifies whether the polygon is hollow or solid.
The command
fig.rectangle(x, y, width, height, style, cornersize, type, color);will draw a rectangle given the x and y coordinates of the center, the width, and the height. style can be "plain", "rounded", or "beveled", which specifies the shape of the four corners of the rectangle. type can be either "contour" or "solid".
The command
fig.ellipse(ox, oy, a, b, theta, type, color);draws an ellipse. It place the center of the ellipse at the location whose coordinates are ox and oy. a and b are the long and short axes, theta is the angle between the long axis of the ellipse and the horizontal direction of the canavas, type is either "contour" or "solid".
Example
fig = figure.new(); fig.line([0, 0], [2, 2], "->"); fig.ellipse{ox = 0, oy = 0, a = 2, b = 1.5, theta = 0, color = colors.red}; fig.rectangle{x = 0, y = 0, width = 4, height = 3, color = colors.lime}; fig.style = "empty"; fig.save("objects.eps");
A figure has the following attributes that can be modified.
This is the setting surrounding the figure. It can be put in a nice box, can come the horizontal and vertical axes, or coordinate grids. This feature is called the ``style'' of the figure and the value is one of "boxed", "grid", "center", or "empty". To change the style of a figure to "center"
fig.style = "center";
It's the title of the figure, which is displayed on the top. The value should be a string. For example, to set the title of the figure to ``The cosmos''
fig.title = "The cosmos";
The label of the horizontal axis. The value should be a string. To set the xlabel to ``Time"
fig.title = "Time";
The label of the vertical axis. Works the same way as the horizontal axis.
This attribute is a function. It returns the width of the clipping area of the plot. The clipping area is a rectangular box. Anything out of the box is not shown on the actual image. The default values of xrange and yrange would try not to clipp off anything.
To check the xrange of the figure
r = fig.getXrange();
fig.getYrange.() returns the yrange of the clipping box of the plot.
A function attribute. To set the xrange to [-5, 5]
fig.setXrange([-5, 5]);
Similarly to setXrange, fig.setYrange(yr) sets the height of the clipping box to yr, which is vector of 2 numbers.
A character string can be printed anywhere in the graph. The location, size, and other attributes of the text can be specified, but it usually would take some trial and error to get it right or satisfactory. The following is the command for printing text
fig.print(x, y, contents, orientation, alignment, color, font, fontstyle, fontscale);where x and y are the coordinates of the location of the text, contents is the text to be printed (a string of characters). The other values are as follows:
argument | allowed values |
orientation | "portrait", "landscape" |
alignment | "left", "right", "center", "top", "bottom", |
font | "Helvetica", "Times", "Courier", "Symbol" |
fontstyle | "Regular", "Bold", "Italic", "BoldItalic" |
fontscale | positive number |
color | vector of three number between 0 and 1 |
You won't see any picture until you save the figure in a file. To save the figure as an encaspuslated postscript file, do fig.save(filename). For example
fig.save("flowering-times.eps");Note that most of the processing occurs when the figure is being saved, therefore if there's something wrong with the plotting commands, error messages usually are not produced until at this stage.
After a figure is saved, it still exists and more contents can be added to it and then it can be saved again.
If you're not satisfied with how a figure looks, you can erase everything in it by using clear. To delete all elements in a figure and leave it empty
fig.clear();Or you could simply redo fig = figure.new() -- the previous value of fig is destroyed.
A color a vector of length three with each element (a number between 0 and 1) representing the intensity of red, green, or blue. Sixteen colors are predefined in the global variable colors.
global.colors = { black = [0, 0, 0], gray = [0.5, 0.5, 0.5], silver = [0.75, 0.75, 0.75], white = [1, 1, 1], yellow = [1, 1, 0], lime = [0, 1, 0], aqua = [0, 1, 1], fuchsia = [1, 0, 1], red = [1, 0, 0], green = [0, 0.5, 0], blue = [0, 0, 1], purple = [0.5, 0, 0.5], maroon = [0.5, 0, 0], olive = [0.5, 0.5, 0], navy = [0, 0, 0.5], teal = [0, 0.5, 0.5] };To specify a color, one can give the rgb vector like
fig.plot(x = xx, y = yy, color = [0.5, 0.7, 0.2];or use one of the predefined colors like
fig.plot(x = xx, y = yy, color = colors.olive};
New color definition can be easily added to the global variable colors. For example:
global.colors.lavender = [0.6, 0.35, 0.73];
oz 2009-12-22