Multiple Axes

../../../../_images/multiple_axes.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
46
47
48
49
50
51
52
53
54
55
# Plot lines in two different plots, with overlaid axis.

# Data
xs = numpy.linspace(0, 1, 256) * Angstrom
ys1 = numpy.linspace(-1, 1, 256) * eV
ys2 = numpy.linspace(1, -1, 256) ** 2 * Kelvin

# Create model1 and add line.
model1 = Plot.PlotModel(Angstrom, eV)
model1.title().setText('Multiple Axes')
model1.xAxis().setLabel('x')
model1.yAxis().setLabel('Energy')
model1.legend().setVisible(True)

line1 = Plot.Line(xs, ys1)
line1.setLabel('Line1')
line1.setColor('mediumpurple')
line1.setLineWidth(2)
model1.addItem(line1)

# Create model2 and add line.
model2 = Plot.PlotModel(Angstrom, Kelvin)
model2.xAxis().setLabel('x')
model2.yAxis().setLabel('Temperature')
model2.yAxis().setMirrored(True)
model2.legend().setVisible(True)

line2 = Plot.Line(xs, ys2)
line2.setLabel('Line2')
line2.setColor('royalblue')
line2.setLineWidth(2)
model2.addItem(line2)

# Autoscale.
model1.setLimits()
model2.setLimits()

# Create layout.
layout = Plot.OverlayLayout()
layout.setMode(Plot.LAYOUT_MODES.SHARE_X)

# Add main model.
frame1 = Plot.PlotFrame(use_frame_model=False)
frame1.addModel(model1)
layout.addItem(frame1)

frame2 = Plot.PlotFrame(use_frame_model=False)
frame2.addModel(model2)
layout.addItem(frame2)

# Show the plot for interactive editing.
Plot.show(layout)

# Save the plot (can also be saved to svg, pdf, jpeg or hdf5).
Plot.save(layout, 'multiple_axes.png')

References: Plot.PlotFrame, Plot.PlotModel, Plot.show, Plot.save, Plot.OverlayLayout, Plot.Line.

↩ Go back to Plots