3.1 HPlot class. The main canvas

Assuming that all examples located in the directory macros/examples have been examined, now one can learn more about the Jython scripting using jHepWork. Click on Jython shell and type:

>>> from jhplot import HPlot
this imports the main class to build an interactive plot in 1D.

>>> c1=HPlot("Canvas")
this creates a default 600x400 canvas using the HPlot class. To display the canvas, execute the statement:

>>> c1=visible(1)
Note: in Jython, "1" means boolean "true", while 0 means "false". For BeanShell and Java, use "true" and "false" instead. If the canvas should not be shown, use c1=visible(0) for Jython (or c1=visible(false) for BeanShell). One can use also visible() instead of visible(1).

There are more constructors for this class:

>>> c1=HPlot("Canvas",600,400)
creates a canvas of the size 600 by 400 pixels (explicitly defined). To view the API of this class, type c1.doc() (it is assumed that you are connected to the Internet).

>>> c1=HPlot("Canvas", 600,400,1,2)
also creates a canvas of the size of 600 by 400 pixels. In addition, the last two numbers indicate that 2 plots will be plotted on the same canvas (try also 2 and 2, 3 and 2 etc). One can navigate to the current plot using the cd() method. For example, if one needs to plot a function or a histogram in the first region, use:

>>> c1.cd(1,1)
>>> c1.draw("object")    # here "object" is some object
If an object should be shown on the second graph, use

>>> c1.cd(1,2)
>>> c1.draw("object")    # here "object" is some object
By default, the HPlot canvas has the range between 0 and 1 for the X or Y axis. One should specify necessary range using the method setRange(X1,X2,Y1,Y2). Alternatively, one can set "auto-range" using the method setAutoRange().

Now, add some color and annotations. First, import Color from the Java AWT library and then set appropriate annotations:

>>> from java.awt import Color
>>>
>>> c1.setGTitle("Example of functions",Color.red) #put title
>>> c1.setNameX("X axis")
>>> c1.setNameY("Y axis")
>>> c1.setName("Canvas global title")
>>> c1.visible()                                   # make it visible
>>> c.setAutoRange()                               # set autorange
All the entries above are self-explanatory. One may add a background color for the canvas using:

>>> c1.setBackgroundColor(Color.yellow)
Specify custom fonts for the legends as:

>>> from java.awt import Font

>>> font=Font("Lucida Sans",Font.BOLD, 12)
>>> c1.setLegendFont(font)
One can further edit the global title by using the mouse. Read the documentation of the jHPlot package [11].