Subsections

15 Text labels

15.1 Interactive text labels. HLabel class

Once a graph is shown on HPlot canvas, one can insert a label. creates an interactive label with a text which can be added and shown in HPlot canvas. To make it visible, call the ``update()'' method. Here is a typical example:

>>> lab=HLabel("HLabel in NDC", 0.5, 0.2)
>>> c1.add(lab) # add it to HPlot object
>>> c1.update() # trigger update

By default, HLabel will be inserted in the 0.5 and 0.2 position in the user coordinate system (). Alternatively, one can set a label is in an user-independent coordinate system, the so-called the normalized coordinate system, . This system coordinate is independent of the window size and is defined with two numbers in the range from 0 to 1. You can study this system by clicking on the middle mouse button. The status panel should indicate the mouse position in the NDC system.

The same label in the NDC system should be created as:

>>> lab=HLabel("HLabel in NDC", 0.5, 0.2, ``NDC'')
You can modify the label attributes using the ``setFont()'', ``setColor()'' etc. methods. Check the API of JHPlot for mode details.

The position of the label can be adjusted using the mouse. Double click on the label will trigger a label property windows to show up.

The text label can be set manually or via the label property window. Subscripts and superscripts in the text should be included as for the standard LaTeX. To indicate over-line, use the reserved word #bar{symbol}.

Symbols for the jHepWork labels must be encoded in HTML using the entity reference notation. See ARENA projecthttp://www.w3.org/Arena/tour/symbols.html for details

It should be noted that to put a legend, global title or title for axis, you do not need to use the HLable class.

15.2 Simple text labels using JAVA 2D

One can also put more simple labels using the . It is impossible interact with such a label, but due to low memory consumption such labels are rather useful. The from the package ``jhplot.shapes'' allows to draw a simple label using JAVA 2D:

>>> from jhplot.shapes import *
>>> .. define HPlot and plot something on it
>>> lab=Text("HLabel in USER system", 0.5, 0.2)
>>> c1.add(lab)   # add to c1 object
>>> update();     # trigger changes on c1

By default, the text label will be drawn in the user coordinate system at X=0.5 and Y=0.2. If you want to use the NDC system, use the method setPosCoord(``NDC'').

>>> lab=Text("Text in the NDC system", 0.5, 0.2)
>>> lab.setPosCoord(``NDC'').
>>> lab=Text("Text in USER system", 0.5, 0.2)
>>> lab.setPosCoord(``USER'').
>>> .. add and update the canvas

As before, one can set the text fonts, color and transparency level using ``setFont(Font f)'', ``setColor(Color c)'' and ``setTransparency(double a)'' methods.