qcodes.plots.base

Live plotting in Jupyter notebooks

class qcodes.plots.base.BasePlot(interval=1, data_keys='xyz')[source]

Bases: object

latest_plot = None

Auto-updating plot connected to a Jupyter notebook

Parameters
  • interval (int) – period in seconds between update checks default 1

  • data_keys (str) – sequence of keys in trace config can contain data that we should look for updates in. default ‘xyz’ (treated as a sequence) but add more if for example marker size or color can contain data

clear()[source]

Clears the plot window and removes all subplots and traces so that the window can be reused.

replace(*args, updater=None, **kwargs)[source]

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()

add(*args, updater=None, **kwargs)[source]

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_to_plot(**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}

add_updater(updater, plot_config)[source]

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.

get_default_title()[source]

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

str

static get_label(data_array)[source]

Look for a label in data_array falling back on name.

Parameters

data_array (DataArray) – data array to get label from

Returns

label or name of the data_array

Return type

str

static expand_trace(args, kwargs)[source]

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 the add method support multiple ways to specify the data in the trace:

As *args:
  • add(y) or add(z) specify just the main 1D or 2D data, with the setpoint axis or axes implied.

  • add(x, y) or add(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
  • args (Tuple[DataArray]) – positional args, as passed to either __init__ or add

  • kwargs (Dict(DataArray]) – keyword args, as passed to either __init__ or add. kwargs may contain non-data items in keys other than x, y, and z.

Raises
  • ValueError – if the shape of the data does not match that of args

  • ValueError – if the data is provided twice

update()[source]

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

update_plot()[source]

Update the plot itself (typically called by self.update). Should be implemented by a subclass

halt()[source]

Stop automatic updates to this plot, by canceling its update widget

save(filename=None)[source]

Save current plot to filename

Parameters

filename (Optional[str]) – Location of the file