Linegroup

../../../../_images/linegroup.png
 1# Plot thousands of lines with a LineGroup.
 2
 3# Dummy data
 4xs = numpy.linspace(0, 1, 256) * Angstrom
 5
 6# Create oscillating lines.
 7constants = numpy.arange(1024)
 8xs_mesh, constants_mesh = numpy.meshgrid(xs.inUnitsOf(Angstrom), constants)
 9ys = numpy.sin(40 * numpy.pi * numpy.cos(constants_mesh) * xs_mesh) + constants_mesh
10
11# Create and tweak model.
12model = Plot.PlotModel(x_unit=Angstrom)
13model.xAxis().setLabel('Position')
14model.framing().setTitle('Plot Many Lines')
15model.legend().setVisible(True)
16
17# Create line group and lines.
18group = Plot.LineGroup()
19model.addItem(group)
20
21for i in range(1024):
22    line = Plot.Line(xs, ys[i, :])
23    line.setLineWidth(0.6)
24    line.setColor(Plot.Colors[i])
25    group.addItem(line)
26
27# Autoscale.
28model.setLimits('y', 0, 200)
29
30# Show the plot for interactive editing.
31Plot.show(model)
32
33# Save the plot (can also be saved to svg, pdf, jpeg or hdf5).
34Plot.save(model, 'linegroup.png')

References: Plot.save, Plot.show, Plot.Line, Plot.Colors, Plot.PlotModel, Plot.LineGroup.

↩ Go back to Plots