# Drawing the Graph

PLplot can draw graphs consisting of points with optional error bars, line segments or histograms. Functions which perform each of these actions may be called after setting up the plotting environment using `plenv`. All of the following functions draw within the box defined by `plenv`, and any lines crossing the boundary are clipped. Functions are also provided for drawing surface and contour representations of multi-dimensional functions. See Chapter 3 for discussion of finer control of plot generation.

## Drawing Points

`plpoin` and `plsym` mark out n points (x[i], y[i]) with the specified symbol. The routines differ only in the interpretation of the symbol codes. `plpoin` uses an extended ASCII representation, with the printable ASCII codes mapping to the respective characters in the current font, and the codes from 0–31 mapping to various useful symbols. In `plsym` however, the code is a Hershey font code number. Example programs are provided which display each of the symbols available using these routines.

 ` plpoin`(n, x, y, code);

 ``` plsym ```(n, x, y, code);

 `n` (PLINT, input) The number of points to plot. `x, y` (PLFLT *, input) Pointers to arrays of the coordinates of the n points. `code` (PLINT, input) Code number of symbol to draw

## Drawing Lines or Curves

PLplot provides two functions for drawing line graphs. All lines are drawn in the currently selected color, style and width. See the Section called Setting Line Attributes in Chapter 3 for information about changing these parameters.

`plline` draws a line or curve. The curve consists of n-1 line segments joining the n points in the input arrays. For single line segments, `pljoin` is used to join two points.

 ``` plline ```(n, x, y);

 `n` (PLINT, input) The number of points. `x, y` (PLFLT *, input) Pointers to arrays with coordinates of the n points.

 ``` pljoin ```(x1, y1, x2, y2);

 `x1, y1` (PLFLT, input) Coordinates of the first point. `x2, y2` (PLFLT, input) Coordinates of the second point.

## Writing Text on a Graph

`plptex` allows text to be written within the limits set by `plenv`. The reference point of a text string may be located anywhere along an imaginary horizontal line passing through the string at half the height of a capital letter. The parameter `just` specifies where along this line the reference point is located. The string is then rotated about the reference point through an angle specified by the parameters `dx` and `dy`, so that the string becomes parallel to a line joining (x, y) to (x+dx, y+dy).

 ``` plptex ```(x, y, dx, dy, just, text);

 `x, y` (PLFLT, input) Coordinates of the reference point. `dx, dy` (PLFLT, input) These specify the angle at which the text is to be printed. The text is written parallel to a line joining the points (x, y) to (x+dx, y+dy) on the graph. `dx, dy` (PLFLT, input) These specify the angle at which the text is to be printed. The text is written parallel to a line joining the points (x, y) to (x+dx, y+dy) on the graph. `just` (PLFLT, input) Determines justification of the string by specifying which point within the string is placed at the reference point (x, y). This parameter is a fraction of the distance along the string. Thus if `just` = 0.0, the reference point is at the left-hand edge of the string. If `just` = 0.5, it is at the center and if `just` = 1.0, it is at the right-hand edge. `text` (char *, input) Pointer to the string of characters to be written.

## Area Fills

Area fills are done in the currently selected color, line style, line width and pattern style.

`plfill` fills a polygon. The polygon consists of n vertices which define the polygon.

 ``` plfill ```(n, x, y);

 `n` (PLINT, input) The number of vertices. `x, y` (PLFLT *, input) Pointers to arrays with coordinates of the n vertices.

## More Complex Graphs

Functions `plbin` and `plhist` are provided for drawing histograms, and functions `plerrx` and `plerry` draw error bars about specified points. There are lots more too (see Chapter 19).