You are a guest. Restricted access. Read more.
SCaVis manual

This is an old revision of the document!

Plot annotations

Data can be annotated using interactive legends and labels. Different styles for labels (including those for tick marks) are discussed in the Section plot_styles. In this section we will briefly discuss main components to annotate data points.

For annotations, use strings. You can include Greek or math symbols as explained below.

Greek symbols

All labels and legends or any string which can be shown on a canvas can contain Greek letters. The table below shows how to encode Greek letters:

Entity nameAppearanceEntity nameAppearanceEntity nameAppearance

Mathematical operators

All labels and legends or any string which can be shown on a canvas can contain math operators:

Entity nameAppearanceEntity nameAppearanceEntity nameAppearance

Simple labels

The package jhplot.shapes can be used to display several geometrical primitives, pictures, including the text labels. All of this works together with the HPlot canvas. You cannot interact with the mouse using such labels.

Interactive labels

You can annotate your figure on the HPlot canvas putting interactive labels, so you can move them around with the mouse and edit.

  • HLabel a standard single-line label
  • HLabelEq an interactive multiline label
  • HKey interactive key to annotate shown data

The text labels can be set manually or via the label property window (click on the interactive label to bring up a dialog). Subscripts and superscripts in the text should be included as for the standard LaTeX syntax.

can be shown as “X^{2}”

can be shown as “X_{2}”

To indicate over-line, use the reserved word “bar{}”:

can be shown as “bar{X}”

Symbols must be encoded using the entity reference notation as shown in the above sections. For example, the Greek “omega” should be written as “ω”

Interactive legends

Interactive legends are used to annotate data points, functions or histograms. Be default, once data are plotted, data annotation is also displayed using title of the data (getTitle()) as a text for the key.

Still, one can set legends for data manually. Look at the API of the HKey class.

In this example, we have disabled automatic legends and made legends using the HKey class. We plot 3 different objects, which we pass to the HKey to make legends.

Code example

  Download for this example is disabled for non-members
 1: from java.awt import *
 2: from java.util import Random
 3: from jhplot import *
 5: c1 =HPlot("Canvas")
 6: c1.visible()
 7: c1.setLegend(0) # remove automatic legends
 8: c1.setAutoRange()
10: h1 = H1D("hist1",20, -2.0, 2.0)
11: h1.setColor(Color(15,167,83))
12: h1.setPenWidth(2)
13: f1=F1D("50*x*x+100",-2,3)
15: p1= P1D("data1")
16: p1.setSymbol(6)
17: p1.setErrAll(0)
18: p1.setSymbolSize(10)
19: p1.setColor(
21: rand = Random()
22: for i in range(5000):
23:     h1.fill(rand.nextGaussian())
24:     if (i<20): p1.add(-2+0.4*rand.nextGaussian(),300+30*rand.nextGaussian())
26: c1.draw(f1)
27: c1.draw(h1)
28: c1.draw(p1)
30: k=HKey("histo1",h1)
31: c1.add(k)
33: k=HKey("data1",p1)
34: c1.add(k)
36: k=HKey("10*x*x",f1)
37: c1.add(k)
39: c1.update();

The position of legends are set automatically. This example generates the figure below:

The legend can show symbols, lines or filled areas, and in fact, their positions can be set manually. In fact, to make a legend, there is no need to use input plotted objects. Below we generate various legend types:

Code example

  Download for this example is disabled for non-members
 1: from java.awt import Color
 2: from jhplot  import *
 3: c1 = HPlot("Canvas",600,550)
 4: c1.removeAxes()
 5: c1.setRange(0,100,0,100)
 6: key = HKey("My symbol",15,100)
 7: c= Color(0,100,0)
 8: key.setKey(0,2.0,c)
 9: c1.add(hh)

Here we created an interactive label (type=0) at the position x=15,y=100 which shows a symbol (open circle). The type of the symbol (0) is set using the method “setKey”.

The figure below shows various types of the HKey symbols.

Legends are fully customizable. In the example below we change many attributes of legends

The figure was generated with the example code shown below. Here we change many default attributes of the standard legends using the Python codding:

Unregistered users have a limited access to this section. You can unlock advanced pages after becoming a full member. You can also request to edit this manual and insert comments.

LaTeX equations

If you are using HPlot, you can show complex LaTeX equations using the class HLabelEq. This example shows how to make such a label using NDC coordinate system. It also shows to to put an interactive label

Code example

  Download for this example is disabled for non-members
 1: from jhplot  import *
 2: from java.awt import *
 3: from java.util import Random
 5: c1 = HPlot("Canvas",600,400,1, 1)
 6: c1.visible(1)
 7: c1.setAutoRange()
 9: h1 = H1D("Simple1",30, -2, 2.0)
10: rand = Random()
11: # fill histogram
12: for i in range(1000):
13:       h1.fill(rand.nextGaussian())
14: c1.draw(h1)
15: c1.setAutoRange()
16: c1.setNameX("X_{sub}")
17: c1.setNameY("Y^{sup}")
18: c1.setName("Canvas title")
20: # set HLabel in the normilised coordinate system
21: lab=HLabel("HLabel F_{2}", 0.8, 0.8, "NDC")
22: lab.setColor(
23: c1.add(lab)
25: # show latex equation
26: lab=HLabelEq("int_{i=1}^{100}omega_{i}(x)dx+sum_{i=0}^{200}sqrt{i^2}", 0.15, 0.8, "NDC")
27: lab.setFontSize(16)
28: lab.setColor(;
29: c1.add(lab)
31: c1.update()

The output is shown here:


click here if you want to know more

click here if you want to know more

click here if you want to know more

A complete description of how to use Java, Jython and SCaVis for scientific analysis is described in the book Scientific data analysis using Jython and Java published by Springer Verlag, London, 2010 (by S.V.Chekanov)

One can comment and discuss this section after becoming a full member.

man/visual/plot_annotations.1376676760.txt.gz · Last modified: 2013/08/16 12:12 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