diff --git a/qcodes/plots/base.py b/qcodes/plots/base.py index 654ed42d8c4..5e403373d62 100644 --- a/qcodes/plots/base.py +++ b/qcodes/plots/base.py @@ -79,7 +79,9 @@ def add(self, *args, updater=None, **kwargs): 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 + self.add_to_plot. + To use custom labels and units pass for example: + >>> plot.add(x=set, y=amplitude, xlabel=("set", "s"), ylabel= ("Amplitude", "V")) Array shapes for 2D plots: x:(1D-length m), y:(1D-length n), z: (2D- n*m array) @@ -171,8 +173,10 @@ def get_label(self, data_array): """ # TODO this should really be a static method - return (getattr(data_array, 'label', '') or + name = (getattr(data_array, 'label', '') or getattr(data_array, 'name', '')) + unit = getattr(data_array, 'unit', '') + return name, unit def expand_trace(self, args, kwargs): """ diff --git a/qcodes/plots/pyqtgraph.py b/qcodes/plots/pyqtgraph.py index 79671456980..c19213115da 100644 --- a/qcodes/plots/pyqtgraph.py +++ b/qcodes/plots/pyqtgraph.py @@ -346,17 +346,16 @@ def _update_labels(self, subplot_object, config): """ for axletter, side in (('x', 'bottom'), ('y', 'left')): ax = subplot_object.getAxis(side) - unit = config[axletter].unit - # pyqtgraph doesn't seem able to get labels, only set # so we'll store it in the axis object and hope the user # doesn't set it separately before adding all traces + if axletter+'label' in config and not ax._qcodes_label: - label = config[axletter+'label'] + label, unit = config[axletter+'label'] ax._qcodes_label = label ax.setLabel(label, unit) if axletter in config and not ax._qcodes_label: - label = self.get_label(config[axletter]) + label, unit = self.get_label(config[axletter]) if label: ax._qcodes_label = label ax.setLabel(label, unit) diff --git a/qcodes/plots/qcmatplotlib.py b/qcodes/plots/qcmatplotlib.py index 135edac3c9e..b050f3c2f2b 100644 --- a/qcodes/plots/qcmatplotlib.py +++ b/qcodes/plots/qcmatplotlib.py @@ -110,9 +110,11 @@ def _get_axes(self, config): def _update_labels(self, ax, config): if 'x' in config and not ax.get_xlabel(): - ax.set_xlabel(self.get_label(config['x'])) + name, unit = self.get_label(config['x']) + ax.set_xlabel("{} ({})".format(name, unit)) if 'y' in config and not ax.get_ylabel(): - ax.set_ylabel(self.get_label(config['y'])) + name, unit = self.get_label(config['y']) + ax.set_ylabel("{} ({})".format(name, unit)) def update_plot(self): """