Density

../../../../_images/density1.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
45
# Plot density
# This example creates a highly efficient and responsive density plot.

# Generate some dummy data.
N = int(1e6)

xs = numpy.zeros(2 * N)
ys = numpy.zeros(2 * N)

xs[:N] = numpy.random.normal(loc=0.8, scale=0.2, size=N)
xs[N:] = numpy.random.normal(loc=0.2, scale=0.2, size=N)

ys[:N] = numpy.random.normal(loc=0.4, scale=0.2, size=N)
ys[N:] = numpy.random.normal(loc=0.7, scale=0.25, size=N)

xs = xs * Angstrom
ys = ys * Angstrom

# Create a model and apply some settings.
model = Plot.PlotModel(Angstrom, Angstrom)
model.framing().setTitle('Plot Density')
model.xAxis().setLabel('x')
model.yAxis().setLabel('y')

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

# Create and add density plot.
density = Plot.Density(xs, ys)
density.setBroadening(1)
density.setColorMode(Plot.COLOR_MODES.COLOR_MAP)
density.setDpi(150)
density.setLimits(0, 5)
model.addItem(density)

# Autoscale.
model.setLimits('x', 0, 1)
model.setLimits('y', 0, 1)

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

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

↩ Go back to Plots