Contents Previous Next

6.5 Scatter plots

Scatter plots are very simple; they plot a number of points specified by their X- and Y-coordinate. Each point is stroked on the image with a mark as with line plots. The stroked marks can also be connected with an optional line.


Sidenote: Even though it is only scatter plot that was designed to be used with X,Y plots it is perfectly possible to use use both X,Y coordinates for bar and line plots as well.

Even though you would normally supply X-coordinates it is still perfectly possible to use a text-scale for X-coordinates to just enumerate the points. This is especially useful when using the "Impuls" type of scatter plot as is shown below.

Scatter pots are created by including the jpgraph extension "jpgraph_scatter.php" and then creating an instance of plot type of ScatterPlot(). To specify the mark you want to use you access the mark with the instance variable "mark" in the scatter plot. The default is to use an unfilled small circle.

To create a scatter plot you will create an instance

A simple example using just default values will illustrate this



Figure 1: The simplest possible scatter plot [src]

We can easily adjust the size and colors for the markers to get another effect as shown below



Figure 2: The simplest possible scatter plot with adjusted marks [src]

Another possible variant of scatter plot is impuls-scatter plots. This is a variant of normal scatter plot where each mark have a line from the mark to the Y=0 base line. To change a scatter plot into an impuls scatter plot you have to call the method SetImpuls() on the scatter plot.

This type of plots are often used to illustrate signals in conjunction with digital signal processing. The following two examples illustrates simple use of impuls plots.



Figure 3: A simple impuls plot [src]

The next example shows how to modify the color and width of the impuls plot



Figure 4: A modified impuls plot [src]


Sidebar: You may draw impuls graphs without any mark by specifying the mark type as (-1) . That way only the impuls lines will be drawn.
As a final touch we show two more advanced impuls graphs . In these graphs we have used more advanced formatting for the Y-axis labels as well as adjusted the position of the axis position.



Figure 5: In this imuplsplot we have adjusted the position of the X-axis to the bottom and also added more decimals to the labels on the Y-axis [src]



Figure 6: In this impuls plot we have also added a lineplot with a dotted line style. [src]

6.6 Field plots

A variant of scatter plot is the so called Field Plots this is basically a scatter plot where each scatter point is an arrow with a direction between 0 to 359 degrees. This effectively allows the visualization of 3 parameters at each point (x,y,angle). As an additional bonus there is also possible to define a callback for each scatter plot to also define the color for each point.

To create a field plot you create an instance of FieldPlot in the same way as you created a normal scatter plot. The arguments to this method are Y-coordinate, X-coordinate and angle. To specify a callback you use FieldPlot::SetCallback()

The following example (and code) illustrates the usage of the field plot type.



Figure 7: Example of the Field plot type [src]

In addition to the parameters mentioned above you can also adjust both the general size of the arrow and also the specific size of the arrowhead. The arrow size is specified in pixels and the arrow head is specified as an integers between 0 and 10. These sizes are specified with a call to FieldPlot::arrow::SetSize()


Contents Previous Next