Density For Weighted Lines¶

1# Plot weighted lines as a density
2# This example creates a highly efficient and responsive density plot for plotting weighted lines.
3
4# Generate some dummy data.
5xs = numpy.linspace(0, 1, 256) * Angstrom
6
7# Create oscillating lines.
8constants = numpy.arange(16)
9xs_mesh, constants_mesh = numpy.meshgrid(xs.inUnitsOf(Angstrom), constants)
10ys = numpy.sin(constants_mesh**2 * xs_mesh) + 3 * constants_mesh
11
12# Create oscillating weights.
13weights = numpy.sin(constants_mesh[::-1, :]**2 * xs_mesh) + 1.5
14
15# Create a model and apply some settings.
16model = Plot.PlotModel(x_unit=Angstrom)
17model.framing().setTitle('Plot Density')
18model.xAxis().setLabel('x')
19model.yAxis().setLabel('y')
20
21# Change x- and y-axis autoscale padding.
22model.xAxis().setAutoscalePadding(0, 0)
23model.yAxis().setAutoscalePadding(0, 0)
24
25# Create and add density with a multiline resampler.
26density = Plot.Density(xs, ys)
27density.setWeights(weights)
28# The resampler upsamples the lines from 256 to 4000 points.
29density.setResampler(Plot.MultiLineResampler(sampling=4000))
30density.setColor('purple')
31density.setBroadening(2)
32density.setDpi(72)
33density.setLimits(0, 2)
34
35model.addItem(density)
36
37# Autoscale.
38model.setLimits()
39
40# Show the plot for interactive editing.
41Plot.show(model)
42
43# Save the plot (can also be saved to svg, pdf, jpeg or hdf5).
44Plot.save(model, 'density_for_weighted_lines.png')
References: Plot.Density, Plot.PlotModel, Plot.show, Plot.MultiLineResampler, Plot.save.
↩ Go back to Plots