Skip to content

Commit

Permalink
feature: Use units in labels
Browse files Browse the repository at this point in the history
  • Loading branch information
giulioungaretti committed Feb 20, 2017
1 parent dfd48ab commit d2e4605
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
8 changes: 6 additions & 2 deletions qcodes/plots/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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):
"""
Expand Down
7 changes: 3 additions & 4 deletions qcodes/plots/pyqtgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions qcodes/plots/qcmatplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down

0 comments on commit d2e4605

Please sign in to comment.