Line And Annotations

../../../../_images/line_and_annotations.png
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Plot line with annotations.
# This example creates a simple plot with a line.

# The line data.
position = numpy.linspace(0, 1, 256) * Angstrom
energy = numpy.linspace(-1, 1, 256) ** 2 * eV

# Create a model.
model = Plot.PlotModel(Angstrom, eV)
model.title().setText('Plot a Line')
model.xAxis().setLabel('Length')
model.yAxis().setLabel('Energy')
model.legend().setVisible(True)

# Create and add line.
line = Plot.Line(position, energy)
line.setLabel('Line')
line.setColor('mediumpurple')
model.addItem(line)

# Add arrow and label annotations.
model.addItem(Plot.Arrow(0.5 * Angstrom, 0.2 * eV, 0.5 * Angstrom, 0.05 * eV))
model.addItem(Plot.Label(0.5 * Angstrom, 0.2 * eV, 'Minimum'))

# Autoscale limits.
model.setLimits()

# Show the plot for interactive editing.
Plot.show(model)

# Save the plot (can also be saved to svg, pdf, jpeg or hdf5).
Plot.save(model, 'line_and_annotations.png')

References: Plot.Arrow, Plot.Label, Plot.PlotModel, Plot.save, Plot.show, Plot.Line.

↩ Go back to Plots