Uni-HH / CS. / TAMS / Java / jfig
 
spacer jfig
spacer News
spacer Gallery

spacer Editor
spacer Custom editors
spacer Viewer / Bean
spacer Applet
spacer Presentations
spacer Plotting

spacer Webstart
spacer Download
spacer Documentation
 

You can also use jfig for simple function plotting via the jfig.utils.MHG class. Unlike the low-level API of most jfig classes (which are based on the internal coordinate systems with a fixed resolution of 2400 dpi), MHG allows you to specify your own custom coordinate transformation and a calling interface similar to the industry-standard Matlab Handle-Graphics functions (hence, MHG). For details and documentation about Matlab and its graphics see the www.mathworks.com website.

The following image shows a typical plot created via MHG, including axes, axes labels, grid, a line-plot, and markers:

Please check the gallery page for a few additional plotting examples. For each example, the Jython script (see below) used to create that figure is included, too.

Naturally, the plot functions in jfig are not meant as a fully-featured replacement of tools like Matlab, Mathematica, or gnuplot. Still, the provided functions should be useful for a variety of simple plotting needs, and you can use all jfig editing commands to edit, label, and modify your figures. Also, you can easily add your own functions with a little bit of Jython or Java programming.

Supported functions

At the moment, jfig.utils.MHG supports the following plot commands and functions:
  figure()           - create new figure window with default size
  figure( figure )   - make given figure the current figure
  gcf()              - return reference to current figure (or null)
  clf()              - clear current figure window
  close()            - close current figure window
  close( figure )    - close specified window
  closeAllFigures()  - close all figure windows
  getFigures()       - array with references to all figures

  reshape( xxyy[] )  - set window size to specified fraction of screen
  fullscreen()       - create new 'fullscreen' window
  hide( figure )     - hide the figure window, but don't close it
  show( figure )     - show the figure window
  doZoomFit()        - zoom fit of window contents to current size

  save( file )       - save current figure to specified file

  gca()              - return current axes (=coordinate transformation)
  cla()              - clear axes, reset transformation
  axis( xxyy[] )     - set world-coordinates transformation
  axis( string )     - set world-coordinates transformation
  title()            - set figure title
  xlabel()           - set label of x-axis
  ylabel()           - set label of y-axis
  plotGrid()         - plot a grid (grid lines at axis markers)
  plotCartesianAxes()- axes (markers at default or specified positions)

  line()             - plot a line (several variants)
  patch()            - plot a polygon (several variants)
  fill()             - plot and fill a polygon (several variants)
  plot()             - line or marker plot (several variants)
  stem()             - stem plot (several variants)
  bar()              - bar-graph plot (several variants)
  stairs()           - stair-step plot
  image()            - image-plot (matrix display)
  marker()           - plot a single marker
  text()             - plot a single text object

  color( string )    - parse a color from a string, e.g. 0xff0056
  color( r,g,b )     - return a rgb color 0..r,g,b..1
  colormap( name )   - set selected colormap, e.g. 'jet', 'autumn'
  getColormap()      - return reference to current colormap
  colorbar()         - plot colorbar
The example scripts provided below and on our gallery page also use the jfig.utils.Array class, which provides a variety of operations on arrays of double-precision values (i.e. the Java double[] data type). These come handy for interactive sessions, but are not required at all when you provide the data to be plotted from your own scripts or programs.

Scripting with Jython

Naturally, the plot-functions are best used within an interactive workspace that allows you to explore your data and play with different settings. One popular choice is to use the Jython environment, a Java-based implementation of the Python programming language, as the shell and interactive workspace. Just visit the Jython homepage at www.jython.org and download the current version of the Jython interpreter and class libraries. To use the jfig plot-functions, simply put both the Jython and the jfig3.jar software archives into your CLASSPATH, and start the interpreter:
  rem  this is for Windows, use similar code for Unix/Linux/Mac
  set CLASSPATH=c:\temp\jython.jar;c:\temp\jfig3.jar; ...
  cd c:\temp
  jython

  Jython 2.2a0 on java1.4.2 (JIT: null)
  Type "copyright", "credits" or "license" for more information.
  >>>
Now you can enter commands interactively into the Jython interpreter, using the Jython syntax. For example, type-in the following commands, where the variable `m' is used to reference the plot-functions in order to avoid global variables:
  from math import pi
  from jfig.utils import Array       # several array utilities
  from jfig.utils import MHG         # the plot functions
  m = MHG()                          # initalize the plot library,
                                     # reference via variable m
  N = 200
  x = Array.linspace(0,10,N)         # 200 values (0.0 .. 10.0)
  y = Array.cos(x)                   # vector with cos(x)
  z = Array.random(N)                # 200 random values, range [0,1]
  z = Array.add( z, -0.3 )           # shift to range [-0.3, 0.7]

  m.figure();                        # new plot window
  m.gca().autoscaleTight( x, y )     # default scaling
  m.plot( x, y, '-b' )               # solid-blue-line plot
  m.plot( x, z, '.r' )               # red-dot markers
  m.xlabel( 'x' )                    # x-axis label
  m.ylabel( 'sin(x), random data' )  # y-axis label
  m.plotCartesianAxes()              # axes
  m.plotGrid()                       # grid
  m.doZoomFit()
  
  from java.io import File
  m.save( File( 'plot1.fig' ))       # save figure
Click here to download an example figure file created by the above Jython-script. The resulting figure can be printed and exported in jfig as usual. For example, the following link demonstrates the corresponding PDF format file created via the iText-based export, while the PNG-format image shown above on top of this page was created from jfig via the built-in (javax.imageio-based) image export functions.

 
  29.01.2006   Impressum