nspyre.gui.widgets.flex_line_plot
Module Contents
Classes
Qt widget for flexible plotting of 1D user data. |
- class nspyre.gui.widgets.flex_line_plot.FlexLinePlotWidget(timeout=1, data_processing_func=None, init_kwargs=None, add_plot_kwargs=None)
Qt widget for flexible plotting of 1D user data. It connects to an arbitrary data set stored in the
DataServer
, collects and processes the data, and offers a variety of user-controlled plotting options.The user should push a dictionary containing the following key/value pairs to the corresponding
DataSource
object sourcing data to theDataServer
:key:
title
, value: Plot title stringkey:
xlabel
, value: X label stringkey:
ylabel
, value: Y label stringkey:
data_series
, value: Dictionary where keys are a data series name, and values are data as a list of 2D numpy arrays of shape (2, n). The two rows represent the x and y axes, respectively, of the plot, and the n columns each represent a data point.
You may use np.NaN values in the data arrays to represent invalid entries, which won’t contribute to the data averaging. An example is given below:
from nspyre import DataSource, StreamingList with DataSource('my_dataset') as ds: channel_1_data = StreamingList([np.array([[1, 2, 3], [12, 12.5, 12.25]]), np.array([[4, 5, 6], [12.6, 13, 11.2]])]) channel_2_data = StreamingList([np.array([[1, 2, 3], [3, 3.3, 3.1]]), np.array([[4, 5, 6], [3.4, 3.6, 3.5]])]) my_plot_data = { 'title': 'MyVoltagePlot', 'xlabel': 'Time (s)', 'ylabel': 'Amplitude (V)', 'data_series': { 'channel_1': channel_1_data 'channel_2': channel_2_data } } ds.push(my_plot_data)
- Parameters:
timeout (float) – Timeout for
pop()
.data_processing_func (Optional[Callable]) – Function to do any post-processing of the data popped by the
DataSink
. Takes one argument, which is theDataSink
.init_kwargs (Optional[Dict]) – Keyword arguments to pass to the underlying
LinePlotWidget
init method.add_plot_kwargs (Optional[Dict]) – Keyword arguments to pass to the underlying
add_plot()
method.
- line_plot
Underlying LinePlotWidget.
- add_plot(name, series, scan_i, scan_j, processing)
Add a new subplot. Thread safe.
- Parameters:
name (str) – Name for the new plot.
series (str) – The data series name pushed by the
DataSource
, e.g.channel_1
for the example given inFlexLinePlotWidget
scan_i (str) – String value of the scan to start plotting from.
scan_j (str) –
String value of the scan to stop plotting at. Use Python list indexing notation, e.g.:
scan_i = '-1'
,scan_j = ''
for the last elementscan_i = '0'
,scan_j = '1'
for the first elementscan_i = '-3'
,scan_j = ''
for the last 3 elements.
processing (str) – ‘Average’ to average the x and y values of scans i through j, ‘Append’ to concatenate them.
- remove_plot(name)
Remove a subplot. Thread safe.
- Parameters:
name (str) – Name of the subplot.
- hide_plot(name)
Hide a subplot. Thread safe.
- Parameters:
name (str) – Name of the subplot.
- show_plot(name)
Show a previously hidden subplot. Thread safe.
- Parameters:
name (str) – Name of the subplot.