public class GnuPlot extends JFrame
GnuPlot provides methods for handling gnuplot data. Additionally this
class can be used as an interface to gnuplot in order to actually plot data.addData methods, you are able either to retrieve the
gnuplot data file (as String - getData - or saved to a file -
saveData) or to plot the data by invoking gnuplot.
Once the plot is created, it can be retrieved as an Image object by getImage, saved
to a png file by saveImage or presented interactively to the screen (by setting the
visible property to true).
Multiple data can be added as well as another gnuplot object can be merged.
If the plot is shown in the JFrame, it can be saved by rightclicking on the frame or
pressing F3 / CTRL-S.
Axes,
Serialized FormWindow.TypeComponent.BaselineResizeBehaviorEXIT_ON_CLOSECROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSORBOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTDISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSEABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH| Constructor and Description |
|---|
GnuPlot()
The constructor sets the DefaultCloseOperation of this JFrame to DISPOSE_ON_CLOSE.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addCommand(String... command)
Adds commands to the list of commands which are given to gnuplot by invoking
plot |
Axes |
addData(Axes axes)
Adds data in order to plot it.
|
Axes |
addData(Collection col,
String[] dataLabels,
String[] styles)
Adds data in order to plot it.
|
Axes |
addData(Object[] arr,
boolean transposed,
String[] dataLabels,
String[] styles)
Adds data in order to plot it.
|
Axes |
addData(Object arr,
String[] dataLabels,
String[] styles)
Adds data in order to plot it.
|
void |
clearData()
Clears the loaded data.
|
List<Axes> |
getAxes()
Returns the Axes object containing the data, labels and styles.
|
Collection<String> |
getCommands()
Returns the list of commands, e.g. if you want to remove some command from it.
|
List<String> |
getData()
Returns the data in gnuplot data file format as list containing the data for each added axes.
|
String |
getDefaultStyle()
The defaultStyle is used, when no style is defined for an column in an axes object.
|
BufferedImage |
getImage()
Return the plotted data as image.
|
String |
getPlotCommand(List<File> files)
Returns the plot command for a given filename
|
boolean |
isAccessible()
Returns whether or not gnuplot is accessible
|
void |
merge(GnuPlot gnuplot)
Merges another gnuplot object with this one by add its axes and copy its default style to the
axes (if they have no style).
|
void |
paint(Graphics g) |
void |
plot()
Calls gnuplot to plot the data.
|
List<File> |
saveData(File file)
Saves the gnuplot data to one ore more files.
|
void |
saveImage(File file)
Saves the plotted data to a png file.
|
void |
setDefaultStyle(String defaultStyle)
The defaultStyle is used, when no style is defined for an column in an axes object.
|
getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, remove, repaint, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setIconImage, setJMenuBar, setLayeredPane, setLayout, setTransferHandler, updateaddNotify, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setBackground, setCursor, setExtendedState, setMaximizedBounds, setMenuBar, setOpacity, setResizable, setShape, setState, setTitle, setUndecoratedaddPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBackground, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOpacity, getOwnedWindows, getOwner, getOwnerlessWindows, getShape, getToolkit, getType, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isAutoRequestFocus, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isOpaque, isShowing, isValidateRoot, pack, postEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setAutoRequestFocus, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImages, setLocation, setLocation, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, setType, setVisible, show, toBack, toFrontadd, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusDownCycle, validateaction, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, dispatchEvent, enable, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocusInWindow, resize, resize, revalidate, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setMaximumSize, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycleequals, getClass, hashCode, notify, notifyAll, wait, wait, waitgetFont, postEventpublic GnuPlot()
public void addCommand(String... command)
plotcommand - the gnuplot command (e.g. set xrange [0:100])public Collection<String> getCommands()
public void clearData()
public Axes addData(Collection col, String[] dataLabels, String[] styles)
col - the collections array with the datadataLabels - label for each value columnstyles - additional styles for each value columnpublic Axes addData(Axes axes)
axes - an axes object with data to plotpublic Axes addData(Object arr, String[] dataLabels, String[] styles)
arr - the data matrix to plotstyles - additional styles for each value columndataLabels - label for each value columnpublic Axes addData(Object[] arr, boolean transposed, String[] dataLabels, String[] styles)
arr - the data matrix to plottransposed - if the given matrix is transposedstyles - additional styles for each value columndataLabels - label for each value columnpublic void merge(GnuPlot gnuplot)
gnuplot - the gnuplot object to merge withpublic List<Axes> getAxes()
public String getPlotCommand(List<File> files)
files - a list (parallel to axes) of files containing the gnuplot datapublic BufferedImage getImage()
public void saveImage(File file) throws IOException
file - the file to save the png fileIOExceptionpublic List<String> getData()
public List<File> saveData(File file) throws IOException
file - where to save to fileIOExceptionpublic boolean isAccessible()
public void plot()
throws IOException
loadData has to be invoked first. A temporary file
is created in the working directory to hold the data (for compatibility with cygwin, this file
is not created by File.createTempFile) and deleted after plotting. If the JFrame
is visible, it will be repainted. The commands are given to gnuplot via its stdin, the plotted
image is retrieved via its stdout.
The name(s) of the temporary files are hashCode()i.gnuplot. If there is only one
file created, i is omitted.
IOExceptionpublic String getDefaultStyle()
public void setDefaultStyle(String defaultStyle)
defaultStyle - the defaultStyle to setCopyright © 2007–2021. All rights reserved.