Contour

../../../../_images/contour1.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
# Plot contour
# This example creates a contour plot.

# Generate some dummy data.
xs = numpy.linspace(0, 2, 24) * Angstrom
ys = numpy.linspace(0, 2, 30) * Angstrom

x_mesh, y_mesh = numpy.meshgrid(xs.inUnitsOf(Angstrom), ys.inUnitsOf(Angstrom))
heights = (x_mesh ** 2 + y_mesh ** 2 * (1 - y_mesh)) * nm

# Create a model and apply some settings.
model = Plot.PlotModel(Angstrom, Angstrom)
model.title().setText('Plot Contour')
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 contour plot.
contour = Plot.Contour(xs, ys, heights)
contour.setLabel('Contour')
contour.setLevels(16)
contour.setLimits(-4, 4)
contour.setLabelsVisible(True)
model.addItem(contour)

# Autoscale.
contour.setLimits()
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, 'contour.png')

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

↩ Go back to Plots