Plot Data using the IPython Client¶
Goal
Create or reuse a Waveform widget from the BEC IPython client, plot device data, adjust plot and curve properties, and retrieve plotted data.
Prerequisites¶
- BEC is running with a Dock Area.
- The
samxandbpm4idevices are available indev.
Device names
In these examples, samx is a simulated positioner motor and bpm4i is a
Beam Position Monitor.
1. Create a Waveform¶
Create a new Waveform in the default Dock Area:
wf = gui.bec.new(gui.available_widgets.Waveform)
If the profile already contains a Waveform, use the widget from the Dock Area namespace instead:
wf = gui.bec.Waveform
2. Plot device data¶
Plot bpm4i against the samx motor position:
wf.plot(device_x=dev.samx, device_y=dev.bpm4i)
Run a scan to produce live data:
scans.line_scan(dev.samx, -5, 5, steps=25, exp_time=0.1, relative=False)
3. Adjust the Waveform from IPython¶
The Waveform exposes plot properties through the same command interface:
wf.title = "bpm4i intensity during samx scan"
wf.x_label = "samx position"
wf.y_label = "bpm4i signal"
wf.x_grid = True
wf.y_grid = True
Curve items are also exposed below the Waveform when they are RPC-visible. Use get_curve(...) when you want an
explicit reference to a curve:
curve = wf.get_curve("bpm4i-bpm4i")
curve.set_color("#1f77b4")
curve.set_symbol("o")
curve.set_symbol_size(7)
curve.set_pen_width(2)
The same curve can usually also be reached through the Waveform namespace:
wf.bpm4i_bpm4i.set_color("red")
Discover available methods
Use tab completion on wf. or curve. to see exposed methods and properties. Use ? to inspect the docstring for
a method, for example wf.plot? or curve.set_color?.
4. Read plotted data back from the Waveform¶
The Waveform can also return the data that is currently plotted:
data = wf.get_all_data()
The result is a dictionary keyed by curve label:
data["bpm4i-bpm4i"]["x"]
data["bpm4i-bpm4i"]["y"]
Use this when you want to inspect a plotted curve, pass it to another Python package, or compare it with processed data.
GUI equivalent¶
You can configure the same device plot from the Waveform curve settings dialog:
- Open the Waveform curve settings dialog from the plot toolbar .
- Set the x-axis mode to
device. - Set the x-axis device to
samx. - Add a y-axis curve for
bpm4i. - Confirm the dialog and run the scan.
Result
The Waveform shows the device curve, and you can adjust the plot and curve properties from the BEC IPython client.
Related tasks¶
- Use Fit Waveform Data with DAP when you want to attach one or more DAP model curves to Waveform data.
- Use Use Simulated Models from the IPython Client
to make
bpm4iproduce predictable simulated data. - Use Access History with a Waveform to plot completed scans from history.
- Use Script GUI Interactions to combine BEC history access, Python analysis, and GUI plotting from a reusable function.