Transformed Line

../../../../_images/transformed_line.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
# Plot a line with two transformed lines.

# Dummy data.
x = numpy.linspace(0, 1, 256) * Angstrom
y = numpy.linspace(-1, 1, 256) ** 2 * eV

# Create and tweak model.
model = Plot.PlotModel(Angstrom, eV)
model.title().setText('Plot Transformed Lines')
model.xAxis().setLabel(r'$\Delta_X$')
model.yAxis().setLabel(r'$\varepsilon$')
model.legend().setVisible(True)

# Create line and add to model.
line = Plot.Line(x, y)
line.setLabel('Line')
line.setLineWidth(2)
line.setColor('royalblue')
model.addItem(line)

# Create step.
step = Plot.TransformedLine(y_expression='sign(gradient(y/eV)) * eV')
line.addItem(step)
step.setLabel('Sign of gradient')
step.setLineWidth(0.5)

# Create cumulative sum.
integral = Plot.TransformedLine(y_expression='cumsum(y) * gradient(x/Angstrom)')
line.addItem(integral)
integral.setLabel('Integral')
integral.setLineStyle('--')

# Autoscale.
line.setVisible(True)
model.setLimits('y', -1.2, 1.2)

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

References: Plot.TransformedLine, Plot.PlotModel, Plot.save, Plot.show, Plot.Line.

↩ Go back to Plots