Skip to content

Commit 817433c

Browse files
giulio ungarettigiulioungaretti
authored andcommitted
fix: Allow partial kwargs else fall back to data
1 parent 6993229 commit 817433c

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

qcodes/plots/pyqtgraph.py

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -348,23 +348,42 @@ def _update_labels(self, subplot_object, config):
348348
"""
349349
Updates x and y labels, by default tries to extract label from
350350
the DataArray objects located in the trace config. Custom labels
351-
can be specified the **kwargs "xlabel" and "ylabel"
351+
can be specified the **kwargs "xlabel" and "ylabel". Custom units
352+
can be specified using the kwargs xunit, ylabel
352353
"""
353354
for axletter, side in (('x', 'bottom'), ('y', 'left')):
354355
ax = subplot_object.getAxis(side)
356+
# danger: 🍝
357+
# find if any kwarg from plot.add in the base class
358+
# matches xlabel or ylabel, signaling a custom label
359+
if axletter+'label' in config and not ax._qcodes_label:
360+
label = config[axletter+'label']
361+
else:
362+
label = None
363+
364+
# find if any kwarg from plot.add in the base class
365+
# matches xunit or yunit, signaling a custom unit
366+
if axletter+'unit' in config and not ax._qcodes_label:
367+
unit = config[axletter+'unit']
368+
else:
369+
unit = None
370+
371+
# find ( more hope to) unit and label from
372+
# the data array inside the config
373+
if axletter in config and not ax._qcodes_label:
374+
# now if we did not have any kwark gor label or unit
375+
# fallback to the data_array
376+
if unit is None:
377+
_, unit = self.get_label(config[axletter])
378+
if label is None:
379+
label, _ = self.get_label(config[axletter])
380+
355381
# pyqtgraph doesn't seem able to get labels, only set
356382
# so we'll store it in the axis object and hope the user
357383
# doesn't set it separately before adding all traces
358-
359-
if axletter+'label' in config and not ax._qcodes_label:
360-
label, unit = config[axletter+'label']
361-
ax._qcodes_label = label
362-
ax.setLabel(label, unit)
363-
if axletter in config and not ax._qcodes_label:
364-
label, unit = self.get_label(config[axletter])
365-
if label:
366-
ax._qcodes_label = label
367-
ax.setLabel(label, unit)
384+
ax._qcodes_label = label
385+
ax._qcodes_unit = unit
386+
ax.setLabel(label, unit)
368387

369388
def update_plot(self):
370389
for trace in self.traces:

0 commit comments

Comments
 (0)