Line And Annotations¶

1# Plot line with annotations.
2# This example creates a simple plot with a line.
3
4# The line data.
5position = numpy.linspace(0, 1, 256) * Angstrom
6energy = numpy.linspace(-1, 1, 256) ** 2 * eV
7
8# Create a model.
9model = Plot.PlotModel(Angstrom, eV)
10model.framing().setTitle('Plot a Line')
11model.xAxis().setLabel('Length')
12model.yAxis().setLabel('Energy')
13model.legend().setVisible(True)
14
15# Create and add line.
16line = Plot.Line(position, energy)
17line.setLabel('Line')
18line.setColor('mediumpurple')
19model.addItem(line)
20
21# Add arrow and label annotations.
22model.addItem(Plot.Arrow(0.5 * Angstrom, 0.2 * eV, 0.5 * Angstrom, 0.05 * eV))
23model.addItem(Plot.Label(0.5 * Angstrom, 0.2 * eV, 'Minimum'))
24
25# Autoscale limits.
26model.setLimits()
27
28# Show the plot for interactive editing.
29Plot.show(model)
30
31# Save the plot (can also be saved to svg, pdf, jpeg or hdf5).
32Plot.save(model, 'line_and_annotations.png')
References: Plot.Label, Plot.Line, Plot.Arrow, Plot.PlotModel, Plot.show, Plot.save.
↩ Go back to Plots