Charts generation. More...
Classes | |
| class | Axis |
| Represents an axis of a chart encapsulated by an instance of XYChart. More... | |
| class | BoxChart |
| Provides tools to create and manage box-and-whisker plots. More... | |
| class | BoxSeriesCollection |
| This class stores data used in a umontreal.ssj.charts.CategoryChart. More... | |
| class | CategoryChart |
| This class provides tools to create charts from data in a simple way. More... | |
| class | ContinuousDistChart |
| This class provides tools to plot the density and the cumulative probability of a continuous probability distribution. More... | |
| class | CustomHistogramDataset |
| A dataset that can be used for creating histograms. More... | |
| class | DiscreteDistIntChart |
| This class provides tools to plot the mass function and the cumulative probability of a discrete probability distribution over the integers. More... | |
| class | EmpiricalChart |
| Provides tools to create and manage empirical plots, which are used to plot empirical distributions. More... | |
| class | EmpiricalRenderer |
| A renderer that draws horizontal lines between points and/or draws shapes at each data point to provide an empirical style chart. More... | |
| class | EmpiricalSeriesCollection |
| Stores data used in a EmpiricalChart. More... | |
| class | HistogramChart |
| Provides tools to create and manage histograms. More... | |
| class | HistogramSeriesCollection |
| Stores data used in a HistogramChart. More... | |
| class | MultipleDatasetChart |
| Provides tools to plot many datasets on the same chart. More... | |
| class | PlotFormat |
| Provide tools to import and export data set tables to and from Gnuplot, MATLAB and Mathematica compatible formats, or customized format. More... | |
| class | PPPlot |
| Provides PP-plot (probability-probability plot) objects that compare two probability distributions. More... | |
| class | QQPlot |
| This class implements QQ-plot (or quantile-quantile plot) objects that compare two probability distributions. More... | |
| class | ScatterChart |
| Provides tools to create and manage scatter plots. More... | |
| class | SSJCategorySeriesCollection |
| Stores data used in a CategoryChart. More... | |
| class | SSJXYSeriesCollection |
| Stores data used in a XYChart. More... | |
| class | XYChart |
| This class provides tools to create charts from data in a simple way. More... | |
| class | XYLineChart |
| Provides tools to create and manage curve plots. More... | |
| class | YListChart |
| Extends XYLineChart; each YListChart object is associated with a YListSeriesCollection data set. More... | |
| class | YListSeriesCollection |
| This class extends umontreal.ssj.charts.XYListSeriesCollection. More... | |
Functions | |
| XYListSeriesCollection () | |
| Stores data used in a XYLineChart or in other related charts, and provides complementary tools to draw simple curves. | |
| XYListSeriesCollection (double[][]... data) | |
| Creates a new XYListSeriesCollection instance with default parameters and given data series. | |
| XYListSeriesCollection (double[][] data, int numPoints) | |
| Creates a new XYListSeriesCollection instance with default parameters and given points data. | |
| XYListSeriesCollection (DoubleArrayList... data) | |
| Creates a new XYListSeriesCollection instance with default parameters and given data. | |
| XYListSeriesCollection (XYSeriesCollection data) | |
| Creates a new XYListSeriesCollection instance with default parameters and given data series. | |
Data control methods @{ | |
| int | add (double[] x, double[] y) |
| Adds a data series into the series collection. | |
| int | add (double[] x, double[] y, int numPoints) |
| Adds a data series into the series collection. | |
| int | add (double[][] data) |
| Adds a data series into the series collection. | |
| int | add (double[][] data, int numPoints) |
| Adds data series into the series collection. | |
| int | add (DoubleArrayList data) |
| Adds a data series into the series collection. | |
| String | getName (int series) |
| Gets the current name of the selected series. | |
| void | setName (int series, String name) |
| Sets the name of the selected series. | |
Rendering methods @{ | |
| void | enableAutoCompletion () |
| Enables the auto completion option. | |
| void | disableAutoCompletion () |
| Disables auto completion option. | |
| String | getMarksType (int series) |
| Returns the mark type associated with the seriesth data series. | |
| void | setMarksType (int series, String marksType) |
| Adds marks on the points of a data series. | |
| String | getDashPattern (int series) |
| Returns the dash pattern associated with the seriesth data series. | |
| void | setDashPattern (int series, String dashPattern) |
| Selects dash pattern for a data series. | |
| String | getPlotStyle (int series) |
| Gets the current plot style for the selected series. | |
| void | setPlotStyle (int series, String plotStyle) |
| Selects the plot style for a given series. | |
Charts generation.
This package contains utility classes to produce charts either for LaTeX or to be displayed on the computer screen, directly from a Java program. It was written mostly by students before 2010 and it is not perfect. For LaTeX, the package generates TikZ source code, which can be adjusted manually afterwards if needed.
The package is built over the open source JFreeChart software http://www.jfree.org/jfreechart/, which is distributed under the terms of the GNU Lesser General Public License (LGPL). It provides tools for the construction, visualization, and customization of XY plots, histograms, and empirical styled charts. It offers facilities to export charts to PGF/TikZ source code, which can be included into LaTeX documents http://sourceforge.net/projects/pgf. The user does not need to be familiar with the JFreeChart package or the TikZ syntax to use these tools, except if customization is required. For this, one may see the API specification of JFreeChart, and the reference manual of TikZ.
The two basic abstract classes of package charts are XYChart and CategoryChart. All other charts inherit from one of these two. Charts are managed by the mother class which contains the data tables in a SeriesCollection object, and the information about \(x\)-axis and \(y\)-axis in Axis instances. All these objects encapsulate JFreeChart instances along with some additional TikZ-specific attributes. The method XYChart.view displays charts on screen while the method toLatex formats and returns a String which contains the TikZ source code that can be written to a LaTeX file.
Several chart styles are available and each one is represented by a subclass of XYChart or of CategoryChart. The XYLineChart uses XYListSeriesCollection to plot curves and lines, the HistogramSeriesCollection class is used by HistogramChart to plot histograms, and the EmpiricalSeriesCollection is used by EmpiricalChart to plot empirical style charts. It is possible to draw a scatter plot or a box plot using ScatterChart or BoxChart respectively. These concrete subclasses have similar APIs, but they are specialized for different kinds of charts.
These charts can be customized using *SeriesCollection subclasses and Axis. First, one can use methods in the XYChart class for setting the range values and a background grid. One can also use the method getSeriesCollection() for subclasses of charts to obtain the dataset of the chart, which is represented by a *SeriesCollection object. This dataset can be customized in the following ways by calling methods on the series collection: selecting color, changing plot style (straight lines, curves, marks only, etc.), putting marks on points, setting a label and selecting the dash pattern (solid, dotted, dashed, …). The available properties depend on the type of chart. Moreover, objects representing the axes can be retrieved with XYChart.getXAxis for the \(x\)-axis, and XYChart.getYAxis for the \(y\)-axis. By using methods in Axis, many customizations are possible: setting a label to the axis, setting ticks labels and values (auto ticks, periodical ticks or manually defined ticks) and changing the twin axis position on the current axis to select where axes must appear. These settings are independent for each axis.
Each chart object from SSJ encapsulates a JFreeChart object: a XYChart instance contains a JFreeChart instance from JFreeChart API, a *SeriesCollection contains a XYDataset and a XYItemRenderer, and finally an Axis contains a NumberAxis. So any parameter proposed by JFreeChart is reachable through getter methods. However, changing the JFreeChart parameters directly may have no impact on the produced TikZ source code.
The two special classes ContinuousDistChart and DiscreteDistIntChart can be used to plot probability densities, mass functions, and cumulative probabilities for continuous or discrete distributions, which are implemented in package umontreal.ssj.probdist of SSJ.
The package charts provides additional tools for formatting data plot, and creating charts with multiple datasets. The PlotFormat class offers basic tools to import and export data from files. Supported file formats are GNUPlot and standard CSV, which is widely used and accepted by most mathematical softwares such as MATLAB and Mathematica. Customizing file input and output format is also possible. Finally MultipleDatasetChart provides tools to plot with different styles on the same chart.
For a series of examples, see the pdf documentation.
The following examples demonstrate how to build charts with this package.
A simple example of chart creation [normalchart]
The first program, displayed in Listing normalchart, shows the simplest way to export charts from data tables. First, a curve is defined with regularly spaced \(x\)-coordinates in method getPoints; it represents the curve \(y = e^{-x^2/2}/\sqrt{2\pi}\), the density of the standard normal probability distribution. Arrays points[0] contain the \(x\)-coordinates and points[1] the \(y\)-coordinates of the points. Figure normalchart-res presents the resulting chart if the produced TikZ code is added to a LaTeX document using the tikz package, and compiled using LaTeX or PdfLaTeX.
A simpler way to plot a probability density or a distribution function is to use the class umontreal.ssj.charts.ContinuousDistChart, as shown in Listing normaldist where however, the normal density will be plotted directly on the screen.
The normal density [normaldist]
The next example, displayed in Listing poissonchart, plots the probability mass function for a Poisson distribution with \(\lambda= 50\) by simply creating an instance of umontreal.ssj.charts.DiscreteDistIntChart. Figure poissonchart-res presents the resulting chart obtained from PdfLaTeX.
Probabilities of the Poisson distribution [poissonchart]
The next program, displayed in Listing simplechart, shows how to export several charts from data tables. First, three curves are defined with regularly spaced \(x\)-coordinates in methods getPoints*; they represent the curves \(y = \sqrt{x}\), \(y =
\cos(x)\) and \(y = x+2\), respectively. Array points[0] contains the \(x\)-coordinates and points[1] the \(y\)-coordinates of the points. Figure simplechart-res presents the resulting chart if the produced TikZ code is added to a LaTeX document using the tikz package, and compiled using LaTeX or PdfLaTeX.
Three curves on the same chart [simplechart]
The next example, given in Listing customchart, shows how to customize a chart. First, three curves are defined as in example simplechart above and the chart is created. Then the axes are customized by adding labels at chosen values on the \(x\)-axis. On the \(y\)-axis, successive labels are set regularly at points 1 unit apart. Then the data plot itself is customized. A new color is created in the RGB model for the first curve which also receives a label name and a dash plot style. Similarly, the other two curves receive their label name, plot style and color. Note that the third curve is drawn in the ORANGE color predefined in the AWT package of the standard Java toolkit. Finally, the charts are exported to a file in LaTeX format. If the file is compiled with LaTeX or PdfLaTeX, the resulting chart will appear as displayed in Figure customchart-res.
Code for creating and customizing a chart [customchart]
The next example, given in Listing empiricalchart, shows how to plot and customize empirical distributions. First, two empirical distributions are defined from a sample of points obtained from a uniform generator and a Beta \((3, 1)\) generator, both on the interval \([0, 1]\). Then an empirical chart is created to plot these two distributions. The first distribution is plotted in MAGENTA color with filled square marks from TikZ. The second distribution uses default color and plot marks. A background grid is also added with cells of size \(0.1\times0.1\). Finally, the charts are exported to a file in LaTeX format. Figure empiricalchart-res shows the resulting chart.
Creating and customizing empirical distribution charts [empiricalchart]
The next example, given in Listing histo1, shows how to plot a simple histogram. First, data is generated from a standard normal. Then the plot is customized: 80 bins are selected, and the range of the plot is set manually with bounds; the interval is \([-4, 4]\) for the \(x\)-coordinates, and \([0, 5000]\) for the \(y\)-coordinates. Finally, the histogram chart is viewed on the screen, then exported to file HistogramTest1.tex in LaTeX format. Figure histo1-res displays the resulting chart.
Source code creating a simple histogram [histo1]
The next example, given in Listing histochart, shows how to plot and customize histograms. First, the two histogram charts data1 and data2 are created. Then the data plots are customized: two colors are selected in the sRGB model from the java.awt.Color package. 40 bins are selected on the interval \([-6, 6]\) for the first histogram. The number of bins for the second histogram is set automatically. The range of the plot is set manually with bounds. Finally, the two histograms charts are exported to file HistogramChartTest.tex in LaTeX format. Figure histochart-res displays the resulting chart.
Source code creating and customizing histograms. [histochart]
The next example, given in Listing boxplot, shows how to create a box-and-whisker plot. First, two series of 1000 points are obtained from a lognormal distribution and from a Poisson distribution with \(\lambda=5\). These are passed to a BoxChart object, which creates the boxplot, which can be viewed on screen by executing the program. We find that the boxplot for the Poisson data (the box on the right of the chart) has median = 5 (the line inside the box), a mean = 5.009 (the center of the black circle) the first and the third quartiles at 3 and 6, while the lower and upper whiskers are at 0 and 10. Finally, there are outliers at 11 and 12 (the hollow circles) and extreme outliers (the triangle) at 13, outside the chart. We see that the Poisson data is skewed towards higher values. A similar description applies to the lognormal data (the box on the left of the chart), which is strongly skewed towards smaller values.
Source code creating a box-and-whisker plot. [boxplot]
| int umontreal.ssj.charts.add | ( | double[] | x, |
| double[] | y ) |
Adds a data series into the series collection.
Vector x represents the \(x\)-coordinates and vector y represents the
\(y\)-coordinates of the series.
| x | \(x_i\) coordinates. |
| y | \(y_i\) coordinates. |
Definition at line 288 of file XYListSeriesCollection.java.
| int umontreal.ssj.charts.add | ( | double[] | x, |
| double[] | y, | ||
| int | numPoints ) |
Adds a data series into the series collection.
Vector x represents the \(x\)-coordinates and vector y represents the
\(y\)-coordinates of the series. Only the first numPoints of x and y will be added to the new series.
| x | \(x_i\) coordinates. |
| y | \(y_i\) coordinates. |
| numPoints | Number of points to add |
Definition at line 306 of file XYListSeriesCollection.java.
| int umontreal.ssj.charts.add | ( | double | data[][] | ) |
Adds a data series into the series collection.
The input format of data is described in constructor XYListSeriesCollection(double[][] data).
| data | input data. |
Definition at line 348 of file XYListSeriesCollection.java.
| int umontreal.ssj.charts.add | ( | double | data[][], |
| int | numPoints ) |
Adds data series into the series collection.
The input format of data is described in constructor XYListSeriesCollection(double[][] data). Only the first numPoints of data (the first numPoints columns of the matrix) will be added to each new series.
| data | input data. |
| numPoints | Number of points to add for each new series |
Definition at line 363 of file XYListSeriesCollection.java.
| int umontreal.ssj.charts.add | ( | DoubleArrayList | data | ) |
Adds a data series into the series collection.
The input format of data is described in constructor XYListSeriesCollection (DoubleArrayList... data).
| data | data series. |
Definition at line 415 of file XYListSeriesCollection.java.
| void umontreal.ssj.charts.disableAutoCompletion | ( | ) |
Disables auto completion option.
Default status is disabled.
Definition at line 506 of file XYListSeriesCollection.java.
| void umontreal.ssj.charts.enableAutoCompletion | ( | ) |
Enables the auto completion option.
When this parameter is enabled, straight lines are used to approximate points on the chart bounds if the method isn’t able to display all points, because the user defined bounds are smaller than the most significant data point coordinate, for instance. It does not extrapolate the point sets, but simply estimates point coordinates on the curve at bound positions for a better visual rendering.
Definition at line 499 of file XYListSeriesCollection.java.
| String umontreal.ssj.charts.getDashPattern | ( | int | series | ) |
Returns the dash pattern associated with the seriesth data series.
| series | series index. |
Definition at line 540 of file XYListSeriesCollection.java.
| String umontreal.ssj.charts.getMarksType | ( | int | series | ) |
Returns the mark type associated with the seriesth data series.
| series | series index. |
Definition at line 516 of file XYListSeriesCollection.java.
| String umontreal.ssj.charts.getName | ( | int | series | ) |
Gets the current name of the selected series.
| series | series index. |
Definition at line 467 of file XYListSeriesCollection.java.
| String umontreal.ssj.charts.getPlotStyle | ( | int | series | ) |
Gets the current plot style for the selected series.
| series | series index. |
Definition at line 573 of file XYListSeriesCollection.java.
| void umontreal.ssj.charts.setDashPattern | ( | int | series, |
| String | dashPattern ) |
Selects dash pattern for a data series.
It is possible to use all the dash options provided by the TikZ package: "<tt>solid</tt>", "<tt>dotted</tt>", "<tt>densely dotted</tt>", "<tt>loosely dotted</tt>", "<tt>dashed</tt>", "<tt>densely dashed</tt>", "<tt>loosely dashed</tt>" and "<tt>only marks</tt>". If "<tt>only marks</tt>" is chosen, then method setMarksType must be called to choose the marks (which are blank by default).
| series | series index. |
| dashPattern | dash style. |
Definition at line 556 of file XYListSeriesCollection.java.
| void umontreal.ssj.charts.setMarksType | ( | int | series, |
| String | marksType ) |
Adds marks on the points of a data series.
It is possible to use any of the marks provided by the TikZ package, some of which are "<tt>*</tt>", "<tt>+</tt>" and "<tt>x</tt>". A blank character, used by default, disables marks. The PGF/TikZ documentation provides more information about placing marks on plots.
| series | series index. |
| marksType | mark type. |
Definition at line 530 of file XYListSeriesCollection.java.
| void umontreal.ssj.charts.setName | ( | int | series, |
| String | name ) |
Sets the name of the selected series.
| series | series index. |
| name | point set new name. |
Definition at line 477 of file XYListSeriesCollection.java.
| void umontreal.ssj.charts.setPlotStyle | ( | int | series, |
| String | plotStyle ) |
Selects the plot style for a given series.
It is possible to use all the plot options provided by the TikZ package. Some of which are: "<tt>sharp plot</tt>", which joins points with straight lines, "<tt>smooth</tt>", which joins points with a smoothing curve, "<tt>only marks</tt>", which does not join points, etc. The PGF/TikZ documentation provides more information about smooth plots, sharp plots and comb plots.
| series | series index. |
| plotStyle | plot style. |
Definition at line 589 of file XYListSeriesCollection.java.
| umontreal.ssj.charts.XYListSeriesCollection | ( | ) |
Stores data used in a XYLineChart or in other related charts, and provides complementary tools to draw simple curves.
For example, one may add or remove plots series and modify plot style. It extends extends SSJXYSeriesCollection and is linked with the JFreeChart XYSeriesCollection class to store data plots, and linked with the JFreeChart XYLineAndShapeRenderer` to render the plot. Each series must contain enough points to plot a nice curve. It is recommended to use about 30 points. However, some rapidly varying functions may require many more points. It can be used to draw scatter plots.
*/ public class XYListSeriesCollection extends SSJXYSeriesCollection { protected String[] marksType; // marks on points (+, x, *...) protected String[] dashPattern; // line dashing (solid, dotted, densely dotted, loosely dotted, dashed, densely dashed, loosely dashed, only marks) protected String[] plotStyle; // plot style (lines, curves...) private boolean autoCompletion = false;
/** Creates a new XYListSeriesCollection instance with an empty dataset.
Definition at line 62 of file XYListSeriesCollection.java.
| umontreal.ssj.charts.XYListSeriesCollection | ( | double | data[][], |
| int | numPoints ) |
Creates a new XYListSeriesCollection instance with default parameters and given points data.
If data is a \(n\)-row matrix, then the first row data \([0]\) represents the
\(x\)-coordinate vector, and every other row data \([i], i=1,…, n-1\), represents a \(y\)-coordinate set of points. Therefore, if the points represents curves to be plotted, data \([i][ ]\), \(i=0,…, n-1\), corresponds to \(n-1\) curves, all with the same \(x\)-coordinates. Only the first numPoints of data will be considered for each of the set of points.
| data | series of point sets. |
| numPoints | Number of points to plot |
Definition at line 154 of file XYListSeriesCollection.java.
| umontreal.ssj.charts.XYListSeriesCollection | ( | double... | data[][] | ) |
Creates a new XYListSeriesCollection instance with default parameters and given data series.
The input parameter data represents a set of plotting data.
For example, if one \(n\)-row matrix data1 is given as argument, then the first row data1 \([0]\) represents the
\(x\)-coordinate vector, and every other row data1 \([i], i=1,…, n-1\), represents a \(y\)-coordinate set for the points. Therefore matrix data1 \([i][j]\), \(i=0,…, n-1\), corresponds to \(n-1\) curves, all with the same \(x\)-coordinates.
However, one may want to plot several curves with
different
\(x\)-coordinates. In that case, one should give the curves as matrices with two rows. For examples, if the argument data is made of three 2-row matrices data1, data2 and data3, then they represents three different curves, data* \([0]\) being the \(x\)-coordinates, and data* \([1]\) the \(y\)-coordinates of the curves.
However, we may also consider the sets of points above
not as part of curves, but rather as several list of
points.
| data | series of point sets. |
Definition at line 98 of file XYListSeriesCollection.java.
| umontreal.ssj.charts.XYListSeriesCollection | ( | DoubleArrayList... | data | ) |
Creates a new XYListSeriesCollection instance with default parameters and given data.
The input parameter represents a set of data plots, the constructor will count the occurrence number \(Y\) of each value \(X\) in the DoubleArrayList, and plot the point \((X, Y)\). Each DoubleArrayList variable corresponds to a curve on the chart.
| data | series of point sets. |
Definition at line 195 of file XYListSeriesCollection.java.
| umontreal.ssj.charts.XYListSeriesCollection | ( | XYSeriesCollection | data | ) |
Creates a new XYListSeriesCollection instance with default parameters and given data series.
The input parameter represents a set of plotting data. Each series of the given collection corresponds to a curve on the plot.
| data | series of point sets. |
Definition at line 250 of file XYListSeriesCollection.java.