From 9113e2bac955a5cf3757f7e2d82d2e67d58e9b8f Mon Sep 17 00:00:00 2001 From: Jens Hedegaard Nielsen Date: Thu, 28 Sep 2017 14:48:57 +0200 Subject: [PATCH 1/4] Dont assume that unit attribute exists --- qcodes/plots/pyqtgraph.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qcodes/plots/pyqtgraph.py b/qcodes/plots/pyqtgraph.py index bfd4c200072..8c86a6954c1 100644 --- a/qcodes/plots/pyqtgraph.py +++ b/qcodes/plots/pyqtgraph.py @@ -527,8 +527,8 @@ def fixUnitScaling(self, startranges: Optional[Dict[str, Dict[str, Union[float,i # make a dict mapping axis labels to axis positions for axis in ('x', 'y', 'z'): if self.traces[i]['config'].get(axis): - unit = self.traces[i]['config'][axis].unit - if unit not in standardunits: + unit = getattr(self.traces[i]['config'][axis], 'unit', None) + if unit is not None and unit not in standardunits: if axis in ('x', 'y'): ax = plot.getAxis(axismapping[axis]) else: From d0c044bafe895ac8a7af7474911d20cb2ee08494 Mon Sep 17 00:00:00 2001 From: Jens Hedegaard Nielsen Date: Thu, 28 Sep 2017 16:51:45 +0200 Subject: [PATCH 2/4] Dont assume that full_name or nd_array exist either --- qcodes/plots/pyqtgraph.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/qcodes/plots/pyqtgraph.py b/qcodes/plots/pyqtgraph.py index 8c86a6954c1..1c54e75fe60 100644 --- a/qcodes/plots/pyqtgraph.py +++ b/qcodes/plots/pyqtgraph.py @@ -546,10 +546,10 @@ def fixUnitScaling(self, startranges: Optional[Dict[str, Dict[str, Union[float,i ax.update() # set limits either from dataset or - setarr = self.traces[i]['config'][axis].ndarray + setarr = getattr(self.traces[i]['config'][axis], 'ndarray', None) arrmin = None arrmax = None - if not np.all(np.isnan(setarr)): + if setarr and not np.all(np.isnan(setarr)): arrmax = setarr.max() arrmin = setarr.min() elif startranges is not None: @@ -557,7 +557,7 @@ def fixUnitScaling(self, startranges: Optional[Dict[str, Dict[str, Union[float,i paramname = self.traces[i]['config'][axis].full_name arrmax = startranges[paramname]['max'] arrmin = startranges[paramname]['min'] - except (IndexError, KeyError): + except (IndexError, KeyError, AttributeError): continue if axis == 'x': From 4ee11673c6a9e3e43121d1bea72f3e83812dafaa Mon Sep 17 00:00:00 2001 From: Adriaan Date: Fri, 20 Oct 2017 14:30:27 +0200 Subject: [PATCH 3/4] Added a test for pyqtgraph plot --- qcodes/tests/test_plots.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/qcodes/tests/test_plots.py b/qcodes/tests/test_plots.py index 0e85d960d02..78ec6983014 100644 --- a/qcodes/tests/test_plots.py +++ b/qcodes/tests/test_plots.py @@ -6,6 +6,7 @@ - just test "window creation" """ from unittest import TestCase, skipIf +import numpy as np import os try: @@ -44,6 +45,25 @@ def test_creation(self): plotQ = QtPlot(remote=False, show_window=False, interval=0) plotQ.add_subplot() + def test_simple_plot(self): + plotQ = QtPlot(remote=False, show_window=False, interval=0) + plotQ.add_subplot() + + main_QtPlot = QtPlot( + window_title='Main plotmon of TestQtPlot', + figsize=(600, 400)) + + x = np.arange(0, 10e-6, 1e-9) + f = 2e6 + y = np.cos(2*np.pi*f*x) + + for j in range(4): + main_QtPlot.add(x=x, y=y, + xlabel='Time', xunit='s', + ylabel='Amplitude', yunit='V', + subplot=j+1, + symbol='o', symbolSize=5) + @skipIf(noMatPlot, '***matplotlib plotting cannot be tested***') class TestMatPlot(TestCase): From a4f926c7b5bf9ed797f5f1ff81de5e1489ed4ebc Mon Sep 17 00:00:00 2001 From: Jens Hedegaard Nielsen Date: Mon, 23 Oct 2017 10:12:36 +0200 Subject: [PATCH 4/4] This may return a numpy array so explicitly chech against None --- qcodes/plots/pyqtgraph.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qcodes/plots/pyqtgraph.py b/qcodes/plots/pyqtgraph.py index 1c54e75fe60..7512a4ba0c6 100644 --- a/qcodes/plots/pyqtgraph.py +++ b/qcodes/plots/pyqtgraph.py @@ -526,7 +526,7 @@ def fixUnitScaling(self, startranges: Optional[Dict[str, Dict[str, Union[float,i for i, plot in enumerate(self.subplots): # make a dict mapping axis labels to axis positions for axis in ('x', 'y', 'z'): - if self.traces[i]['config'].get(axis): + if self.traces[i]['config'].get(axis) is not None: unit = getattr(self.traces[i]['config'][axis], 'unit', None) if unit is not None and unit not in standardunits: if axis in ('x', 'y'):