Once a graph is shown on the HPlot canvas, one can insert a label. The HLabel class creates an interactive label with a text which can be added and shown in the 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 updateBy default, HLabel object will be inserted at 0.5 and 0.2 in the USER coordinate system, defined by the actual range of X or Y axis. Alternatively, one can set a label in a user-independent coordinate system, the so-called the normalized coordinate system, NDC. This coordinate system is independent of the window size and is defined with two numbers in the range from 0 to 1. One 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() and other methods. Check the API of jHPlot for mode details.
The position of the label can be adjusted using the mouse. A double click on the label triggers a label property windows to show up.
It should be noted that to put a legend, global title or title for axis, the HLable class is not necessary.
One can also insert simple labels using the HShapes class. It is impossible interact with such a label, but due to low memory consumption such labels could be rather useful. The Text class from the package jhplot.shapes allows to draw a simple label using Java 2D:
>>> from jhplot.shapes import Text >>> >>> .. define HPlot and plot something on it >>> lab=Text("Text label in USER system", 0.5, 0.2) >>> c1.add(lab) # add to c1 object >>> update(); # trigger changes on c1By default, the text label will be drawn in the USER coordinate system at X=0.5 and Y=0.2. If one needs 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 canvasAs before, one can set the text fonts, color and transparency level using setFont(Font), setColor(Color) and setTransparency(double) methods.