You are a guest. Restricted access. Read more.
Command disabled: recent
SCaVis manual

Graphical canvases

Every data container of SCaVis can either

  • plottable (extends the class Plottable and can be shown on the canvaces.
  • not plottable, i.e. represent pure data. Almost all non-plottable objects they can be converted to plottable objects

You can check if the object is plottable if it implements the method is3D (it is 3D object or 2D). Here is the example:

>>from jhplot import *
>>print p.is3D()

It returns false (not a 3D object), i.e. it belongs to objects which can only plotted on 2D canvaces.

>>from jhplot import *
>>p=PND() # 2D array
>>print p.is3D()

You will see the error “AttributeError: 'jhplot.PND' object has no attribute 'is3D'.

Plottable objects can be shown on canvaces. Below we summarize the SCaVis canvases which can be used to display data, functions and other graphical objects (axes, labels, keys, arrows) using Java/Jython:

Canvas Description
Plot Plot data and functions using MatLab syntax. Can be used to plot X-Y array,P1D,F1D.
HPlot 2D canvas and contour plots for H1D, P1D, F1D objects and other graphical primitives. H2D can be shown as a desity plot.
HPlotter a similar 2D canvas but has a different look and feel since originate from the JAS (FreeHEP). It has also support for H1D, P1D, F1D. H2D can be shown as a density plot or contour plots (several styles). Plot regions are more interactive than for the HPlot class and there is a better integration with Jaida/FreeHEP libraries
HPlotJas 2D canvas based on Jas2. Accepts H1D, P1D, F1D. H2D for plotting. Useful for interactive rebinning of 1d array and interactive non-linear regression (fits)
HPlotJa 2D canvas with interactive editor for drawing diagrams. It has also support for H1D, P1D, F1D as well as for graphical primitives and Feynman diagrams
SPlot a light-weight 2D canvas with a support for H1D, P1D, F1D as well as for the standard Java arrays
HPlot2D is used for contour (or density) plots in 2D for classes H2D, P2D, F2D
HPlot3D is used for plotting data in 3D H2D, P3D, F2D
HPlotXYZ is used for plotting data and geometrical objects in 3D using OpenGL. Can be used to show H2D, P3D, F2D
HPlot3DP is used for plotting parametric and non-parametric functions such as FPR
HPlotMX for plotting parametric and non-parametric functions
HChart is used for showing 2D and 3D charts, lines, functions, histograms. Also has a support for P1D and H1D histograms. This canvas supported by the Android version of SCaVis (see this section).
HGraph is used for showing interconnected graphs.
HPlotRT to show data in real time as traces
HZirkel is used for interactive geometry (see this topic)

In addtion, one can use several external libraries for plotting data:

Library Description
JFreeChart To plot data and charts
Waterloo scientific library To plot data in chart using interactive canvaces

Such large number of canvases is mainly due to the fact that they are designed for somewhat different tasks and originate from different packages. But the good thing is that thy often share same methods and constructors, so changing the style of the plots can be simply done by replacing the constructor keeping the same plotting methods.

General features

Despite the large number of supported canvaces, all methods used to create interactive plots are rather similar. For most examples to be discussed, we will use the HPlot canvas, but very similar methods also can be used for HPlotter, HPlotJa etc. canvases.

Typically, you can build a canvas like this:

from jhplot *
c1 = HPlot("Canvas",600,400,2,1) # canvas size 600x400, 2 plot regions
c1.visible(100,200)  # make it visible and position at 100 , 200 pixels on the screen
c1.setAutoRange()    # autorange for X
c1.draw(object1)     # draw object1 (H1D,F1D,P1D etc)
c1.draw(object2)     # draw a new object
c1.export("figure.pdf") # export to PDF file

This code create a canvas with the size 600×400 (in pixels), it has 2 pads to show data. The method visible(100,200) make the canvas visible and sets its location on the screen at position 100 (in X from left conner) and 200 (from top) in pixels. If you want a default position, jut call “visible()”. Then you can draw any mathematical object or data. Then you can export the image to vector format. Now you are ready to plot functions, histograms and datasets. See documentation of HPlot in HPlot. It should be noted the HPlot canvas can be replaced by any other canvas described above.

Several plots regions

These canvases can be used to show several pads (plot regions) with plotted objects. Specify the number of divisions in X and Y in the constructors. The navigate to a specific plot region using the method “cd()”. Here is example of how to create 2×2 pads on a single canvas:

  URL link to this snippet
 1: from jhplot  import *
 3: c1 = HPlot("Canvas",500,400,2,2)
 4: c1.visible()
 5: c1. setRangeAll(0,10,0,10)
 6: h1 = P1D("Simple")
 9: h1.add(5,6);  c1.draw(h1)
12: h1.add(4,3); c1.draw(h1)
15: h1.add(3,3); c1.draw(h1)
18: h1.add(2,1); c1.draw(h1)
19: c1.export ("example.pdf")

This works for HPlot, HPlotJa, HPlot3D and many other pads.

Here we use the same X and Y ranges. One can use “setAutoRange()” (after each “cd()”) method to set autorange for each pad. Also, try “setRange(xmin,xmax,ymin,ymax)” to set fixed ranges for each pads. it shows 4 pads with data points.

The plots are fully customizable, i.e. one can change any attribute (axis, label, ticks, ticks label). Read the section plot_styles about how to change various attributes and make different presentation styles.

Exporting to images

When functions, data_structures, histograms or diagrams are shown, one can create an image using the menu [File]-[Export]. One can also save image in a file using the method “export” to a variety of vector graphics formats as well as bitmap image formats.

In the example below, we save an instance of the HPlot class to a PDF file:

>>> c1.export('image.pdf')

we export drawings on the canvas HPlot (c1 represents its instance) into a PDF file. One can also export it into PNG, JPEG, EPS, PS etc. formats using the appropriate extension for the output file name.

As example, simply append the statement “c1.export('')” at the end of code snippets shown in sections functions, data_structures, histograms or diagrams, and your image will be saved to a PostScript file “”.

Images can be generated in a background (without a pop-up frame with the canvas). For this, use the method “c1.visible(0)”, where “0” means Java false.

Sergei Chekanov 2010/03/07 17:38

man/visual/graphics.txt · Last modified: 2014/09/21 23:10 by admin
CC Attribution-Share Alike 3.0 Unported
Powered by PHP Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0 Valid HTML5