qcodes.plots.pyqtgraph
Live plotting using pyqtgraph
- class qcodes.plots.pyqtgraph.TransformState(translate, scale, revisit)
Bases:
tuple
Create new instance of TransformState(translate, scale, revisit)
- count(value, /)
Return number of occurrences of value.
- index(value, start=0, stop=9223372036854775807, /)
Return first index of value.
Raises ValueError if the value is not present.
- revisit
Alias for field number 2
- scale
Alias for field number 1
- translate
Alias for field number 0
- class qcodes.plots.pyqtgraph.QtPlot(*args, figsize=(1000, 600), interval=0.25, window_title='', theme=((60, 60, 60), 'w'), show_window=True, remote=True, fig_x_position=None, fig_y_position=None, **kwargs)[source]
Bases:
BasePlot
Plot x/y lines or x/y/z heatmap data. The first trace may be included in the constructor, other traces can be added with QtPlot.add().
- For information on how
x/y/z *args
are handled seeadd()
in the base plotting class.
- Parameters
*args – shortcut to provide the x/y/z data. See BasePlot.add
figsize – (width, height) tuple in pixels to pass to GraphicsWindow default (1000, 600)
interval – period in seconds between update checks default 0.25
theme – tuple of (foreground_color, background_color), where each is a valid Qt color. default (dark gray, white), opposite the pyqtgraph default of (white, black)
fig_x_pos – fraction of screen width to place the figure at 0 is all the way to the left and 1 is all the way to the right. default None let qt decide.
fig_y_pos – fraction of screen width to place the figure at 0 is all the way to the top and 1 is all the way to the bottom. default None let qt decide.
**kwargs – passed along to QtPlot.add() to add the first data trace
- proc = None
- max_len = 100
- plots: Deque[qcodes.plots.pyqtgraph.QtPlot] = deque([], maxlen=100)
- rpg = None
- clear()[source]
Clears the plot window and removes all subplots and traces so that the window can be reused.
- add_to_plot(subplot=1, **kwargs)[source]
Add a trace the plot itself (typically called by self.add, which incorporates args into kwargs, so the subclass doesn’t need to worry about this). Data will be in x, y, and optionally z.
Should be implemented by a subclass, and each call should append a dictionary to self.traces, containing at least {‘config’: kwargs}
- update_plot()[source]
Update the plot itself (typically called by self.update). Should be implemented by a subclass
- save(filename=None)[source]
Save current plot to filename, by default to the location corresponding to the default title.
- Parameters
filename (Optional[str]) – Location of the file
- add(*args, updater=None, **kwargs)
Add one trace to this plot.
- Parameters
args – optional way to provide x/y/z data without keywords If the last one is 1D, may be y or x, y If the last one is 2D, may be z or x, y, z
updater – a callable (with no args) that updates the data in this trace if omitted, we will look for DataSets referenced in this data, and call their sync methods.
kwargs – after inserting info found in args and possibly in set_arrays into x, y, and optionally z, these are passed along to self.add_to_plot.
- Returns
Plot handle for trace
Examples
To use custom labels and units pass for example:
>>> plot.add(x=set, y=amplitude, >>> xlabel="set", >>> xunit="V", >>> ylabel= "Amplitude", >>> yunit ="V")
- Array shapes for 2D plots:
x:(1D-length m), y:(1D-length n), z: (2D- n*m array)
- add_updater(updater, plot_config)
Add an updater to the plot.
- Parameters
updater (Callable) – callable (with no args) that updates the data in this trace if omitted, we will look for DataSets referenced in this data, and call their sync methods.
plot_config (dict) – this is a dictionary that gets populated inside add() via expand_trace(). The reason this is here is to fetch from the data_set the sync method to use it as an updater.
- autorange(reset_colorbar: bool = False) None [source]
Auto range all limits in case they were changed during interactive plot. Reset colormap if changed and resize window to original size.
- Parameters
reset_colorbar – Should the limits and colorscale of the colorbar be reset. Off by default
- static expand_trace(args, kwargs)
Complete the x, y (and possibly z) data definition for a trace.
Also modifies kwargs in place so that all the data needed to fully specify the trace is present (ie either x and y or x and y and z)
Both
__init__
(for the first trace) and theadd
method support multiple ways to specify the data in the trace:- As
*args
: add(y)
oradd(z)
specify just the main 1D or 2D data, with the setpoint axis or axes implied.add(x, y)
oradd(x, y, z)
specify all axes of the data.
- And as
**kwargs
: add(x=x, y=y, z=z)
you specify exactly the data you want on each axis. Any but the last (y or z) can be omitted, which allows for all of the same forms as with*args
, plus x and z or y and z, with just one axis implied from the setpoints of the z data.
This method takes any of those forms and converts them into a complete set of kwargs, containing all of the explicit or implied data to be used in plotting this trace.
- Parameters
- Raises
ValueError – if the shape of the data does not match that of args
ValueError – if the data is provided twice
- As
- get_default_title()
Get the default title, which for a plot is just a list of DataSet locations. A custom title can be set when adding any trace (via either __init__ or add. these kwargs all eventually end up in self.traces[i][‘config’]) and it looks like we will take the first title we find from any trace… otherwise, if no trace specifies a title, then we combine whatever dataset locations we find.
Note: (alexj): yeah, that’s awkward, isn’t it, and it looks like a weird implementation, feel free to change it 👼
- Returns
the title of the figure
- Return type
- static get_label(data_array)
Look for a label in data_array falling back on name.
- halt()
Stop automatic updates to this plot, by canceling its update widget
- latest_plot = None
Auto-updating plot connected to a Jupyter notebook
- replace(*args, updater=None, **kwargs)
Clear all content and add new trace.
- Parameters
args – optional way to provide x/y/z data without keywords If the last one is 1D, may be y or x, y If the last one is 2D, may be z or x, y, z
updater – a callable (with no args) that updates the data in this trace if omitted, we will look for DataSets referenced in this data, and call their sync methods.
**kwargs – passed on to self.add()
- update()
Update the data in this plot, using the updaters given with MatPlot.add() or in the included DataSets, then include this in the plot.
This is a wrapper routine that the update widget calls, inside this we call self.update() which should be subclassed
- fixUnitScaling(startranges: Optional[Dict[str, Dict[str, Union[float, int]]]] = None)[source]
Disable SI rescaling if units are not standard units and limit ranges to data if known.
- Parameters
startranges – The plot can automatically infer the full ranges array parameters. However it has no knowledge of the ranges or regular parameters. You can explicitly pass in the values here as a dict of the form {‘paramtername’: {max: value, min:value}}
- For information on how