Bars¶

1# Plot bars
2# This example creates a simple bar plot
3
4# Generate some dummy data.
5position = numpy.linspace(0, 1, 24) * Angstrom
6energy = (numpy.random.rand(24) + numpy.linspace(-1, 1, 24) ** 2) * eV
7
8# Create a model.
9model = Plot.PlotModel(Angstrom, eV)
10model.framing().setTitle('Plot Bars')
11model.legend().setVisible(True)
12model.xAxis().setLabel('Length')
13model.yAxis().setLabel('Energy')
14
15# Change y-axis autoscale padding.
16model.yAxis().setAutoscalePadding(0, 0.5)
17
18# Create and add vertical bar plot.
19bars = Plot.VerticalBar(position, energy)
20bars.setLabel('Bars')
21bars.setFaceColor('royalblue')
22model.addItem(bars)
23
24# Autoscale.
25model.setLimits()
26
27# Show the plot for interactive editing.
28Plot.show(model)
29
30# Save the plot (can also be saved to svg, pdf, jpeg or hdf5).
31Plot.save(model, 'bars.png')
References: Plot.save, Plot.show, Plot.PlotModel, Plot.VerticalBar.
↩ Go back to Plots