Michael Thomas Flanagan's Java Scientific Library

Plotter Class:      Graph Drawing Application

     

Last update: 27 July 2008
Main Page of Michael Thomas Flanagan Java Scientific Library

This application reads the data needed for plotting one or several graphs from a text file. The graph/s are plotted on the same set of x y axes and displayed in a window. The graph is resized when the window is resized, maximized when the window is maximized and restored when the window is hidden and then restored. It is a free standing compilation that calls the constructor and several of the methods of the class PlotGraph. Related classes:

INSTRUCTIONS FOR THE USE OF PLOTTER

RUNNING THE PROGRAM
The downloaded application, Plotter.java, simply needs compiling and running, e.g.

                    javac Plotter.java
                    java Plotter

A file selection box will then appear with which you selec the file containing the input data (see below for the format of the input file).

TEXT FILE CONTAINING THE DATA
FILE TYPE
The data input file must be in text file format.

FILE NAME
The text file may be called any name that the user chooses. Obviously it must be a valid name within the operating system in use.

FILE FORMAT
The following format must be adopted [comments are in square brackets]:

graph title [a single line followed by a line return, may contain spaces]

x-axis legend [a single line followed by a line return, may contain spaces]

x-axis units [e.g. V, a single line followed by a line return, may contain spaces]

y-axis legend [a single line followed by a line return, may contain spaces]

y-axis units [e.g. A, a single line followed by a line return, may contain spaces]

number of curves [followed by a line return]

number of points on the curve with maximum number of points [followed by a line return]

number of points on first curve [followed by a line return]

x-value of the first point on the first curve [followed by a space] y-value of the first point on the first curve [followed by a line return]

x-value of the second point on the first curve [followed by a space] y-value of the second point on the first curve [followed by a line return]
. . . . .
. . . . .

x-value of the last point on the first curve [followed by a space] y-value of the last point on the first curve [followed by a line return]

[then, if more than one curve]
number of points on second curve [followed by a line return]

x-value of the first point on the second curve [followed by a space] y-value of the first point on the second curve [followed by a line return]

x-value of the second point on the second curve [followed by a space] y-value of the second point on the second curve [followed by a line return]
. . . . .
. . . . .

x-value of the last point on the second curve [followed by a space] y-value of the last point on the second curve [followed by a line return]

[and so on for all curves]



The number of points on the different curves may be different.
As all curves are scaled as a set it is not sensible to attempt to plot two curves, whose values differ significantly in magnitude, on the same set of axes.

Example of an input file
I - V curve - experiment 1
Voltage
V
Current
A
2
10
10
0.0 0.0
1.0 1.0
2.0 4.0
3.0 9.0
4.0 16.0
5.0 25.0
6.0 36.0
7.0 49.0
8.0 64.0
9.0 81.0
5
0.0 0.0
1.5 2.0
2.5 5.0
3.5 10.0
4.5 17.0

GRAPH WINDOW
The graph window may be resized by using the mouse and cursor to drag on the edges of the window.
When the window is resized the graph/s are resized.
When the window is maximized the graph/s are maximized.
When the window is hidden and then restored the graph/s are restored.
Clicking on the close icon [cross icon in the top right hand corner of the window] closes the window and the program is exited.
The curves, drawn through the data points, are 200 linked points calculated using a natural cubic spline on the data points.
The point symbols area:
                    curve 1: data points are plotted as open circles.
                    curve 2: data points are plotted as open squares.
                    curve 3: data points are plotted as open diamonds.
                    curve 4: data points are plotted as filled circles.
                    curve 5: data points are plotted as filled squares.
                    curve 6: data points are plotted as filled diamonds.
                    curve 7: data points are plotted as x crosses.
                    curve 8: data points are plotted as + crosses.
This sequence is repeated for further curves.

CLOSING THE WINDOW AND EXITING THE PROGRAM
The graph window may be closed and the program exited by clicking on the window close icon [cross icon in the top right hand corner of the window].

OBTAINING GREATER CONTROL OVER GRAPH APPEARENCE
The class, PlotGraph, gives greater control over the appearence of the graph and allows several graph windows to be created from the same application. You will need to write your own application if you use PlotGraph.



This page was prepared by Dr Michael Thomas Flanagan