DMelt:Plots/8 Plot Annotations

From HandWiki
Limitted access. First login to DataMelt if you are a full DataMelt member. Then login to HandWiki as a user.

Plot annotations

Data can be annotated using interactive legends and labels. 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
&alpha;α&beta; β &gamma; γ
&delta; δ &epsi; ε &zeta; ζ
&eta; η &theta; θ &thetav; ϑ
&iota; ι &kappa; κ &lambda; λ
&mu; μ &nu; ν &xi; ξ
&pi; π &piv; ϖ &rho; ρ
&sigma; σ &sigmav; ς &tau; τ
&upsi; υ &phi; φ &phiv; ϕ
&chi; χ &psi; ψ &omega; ω
&Gamma; Γ &Delta; Δ &Theta; Θ
&Lambda; Λ &Xi; Ξ &Pi; Π
&Sigma; Σ &Upsi; ϒ &Phi; Φ
&Psi; Ψ &Omega; Ω


Mathematical operators

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


Entity nameAppearanceEntity nameAppearanceEntity nameAppearance
&perp;&plusmn; ± &or;
&forall;&exist;&inf; &inf;


You can find more symbols in Unicode Consortium for HTML symbols.

Alternatively, you can use characters using numbers. See the unicode table unicode table When defining a Unicode character, use "&", followed by "#", then a number and then close it with a semi-column. For example, the string:

s="W^{ &#8723;}"

will show a W boson with minus and plus sign, <html>∓</html>.

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 jhplot.HPlot jhplot.HPlot canvas. You cannot interact with the mouse using such labels.

Interactive labels

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

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.

  • "X^{2}" will be shown as [math]\displaystyle{ X^{2} }[/math]
  • "X_{2}" will be displayed as [math]\displaystyle{ X_{2} }[/math]

To indicate over-line, use the reserved word #bar{}. For example, to display [math]\displaystyle{ \overline{X+Y} }[/math], use #bar{X+Y}. To display a square root $\sqrt{X+Y}$, use #sqrt{X+Y}.

To make a space between characters, use the usual space. To make a back-space, use the predefined keyword #bs2{}. This creates a backspace with the width of one character. To make a smaller backspace, equal to 1/2 of the character width, use #bs1{}.

One can mix this syntax to show complicated mathematical equations in the labels.

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

This is a small example that shows data points and create labels using mathematical symbols and Greek letters.

The Jython / Python script that creates this figure is given below. You can use the Java syntax to create a similar plot.

which shows this image:

DMelt example: An example of a plot with mathematical symbols and greek letters

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 jhplot.HKey jhplot.HKey class.

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

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

DMelt example: HKey key shown on HPlot

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.

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".

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

DMelt example: Multiple objects and manually setting interactive keys with HKey

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

LaTeX equations

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

The output is shown here:

DMelt example: Annotations on 2D canvaces. Show a LaTeX equation