Bars

../../../../_images/bars.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
# Plot bars
# This example creates a simple bar plot

# Generate some dummy data.
position = numpy.linspace(0, 1, 24) * Angstrom
energy = (numpy.random.rand(24) + numpy.linspace(-1, 1, 24) ** 2) * eV

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

# Change y-axis autoscale padding.
model.yAxis().setAutoscalePadding(0, 0.5)

# Create and add vertical bar plot.
bars = Plot.VerticalBar(position, energy)
bars.setLabel('Bars')
bars.setFaceColor('royalblue')
model.addItem(bars)

# Autoscale.
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, 'bars.png')

References: Plot.VerticalBar, Plot.PlotModel, Plot.save, Plot.show.

↩ Go back to Plots