Density For Weighted Lines

../../../../_images/density_for_weighted_lines.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
35
36
37
38
39
40
41
42
43
44
# Plot weighted lines as a density
# This example creates a highly efficient and responsive density plot for plotting weighted lines.

# Generate some dummy data.
xs = numpy.linspace(0, 1, 256) * Angstrom

# Create oscillating lines.
constants = numpy.arange(16)
xs_mesh, constants_mesh = numpy.meshgrid(xs.inUnitsOf(Angstrom), constants)
ys = numpy.sin(constants_mesh**2 * xs_mesh) + 3 * constants_mesh

# Create oscillating weights.
weights = numpy.sin(constants_mesh[::-1, :]**2 * xs_mesh) + 1.5

# Create a model and apply some settings.
model = Plot.PlotModel(x_unit=Angstrom)
model.title().setText('Plot Density')
model.xAxis().setLabel('x')
model.yAxis().setLabel('y')

# Change x- and y-axis autoscale padding.
model.xAxis().setAutoscalePadding(0, 0)
model.yAxis().setAutoscalePadding(0, 0)

# Create and add density with a multiline resampler.
density = Plot.Density(xs, ys)
density.setWeights(weights)
# The resampler upsamples the lines from 256 to 4000 points.
density.setResampler(Plot.MultiLineResampler(sampling=4000))
density.setColor('purple')
density.setBroadening(2)
density.setDpi(72)
density.setLimits(0, 2)

model.addItem(density)

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

References: Plot.Density, Plot.PlotModel, Plot.save, Plot.show, Plot.MultiLineResampler.

↩ Go back to Plots