Linegroup

../../../../_images/linegroup1.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
33
34
# Plot thousands of lines with a LineGroup.

# Dummy data
xs = numpy.linspace(0, 1, 256) * Angstrom

# Create oscillating lines.
constants = numpy.arange(1024)
xs_mesh, constants_mesh = numpy.meshgrid(xs.inUnitsOf(Angstrom), constants)
ys = numpy.sin(40 * numpy.pi * numpy.cos(constants_mesh) * xs_mesh) + constants_mesh

# Create and tweak model.
model = Plot.PlotModel(x_unit=Angstrom)
model.xAxis().setLabel('Position')
model.framing().setTitle('Plot Many Lines')
model.legend().setVisible(True)

# Create line group and lines.
group = Plot.LineGroup()
model.addItem(group)

for i in range(1024):
    line = Plot.Line(xs, ys[i, :])
    line.setLineWidth(0.6)
    line.setColor(Plot.Colors[i])
    group.addItem(line)

# Autoscale.
model.setLimits('y', 0, 200)

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

References: Plot.PlotModel, Plot.save, Plot-Colors_c, Plot.LineGroup, Plot.Line, Plot.show.

↩ Go back to Plots