Skip to content

Commit 2d48b00

Browse files
AdriaanRoljenshnielsen
authored andcommitted
Added a failing test for PyQT plotting (passes <0.1.7, fails at later versions). (#805)
* Dont assume that unit attribute exists * Dont assume that full_name or nd_array exist either * Added a test for pyqtgraph plot * This may return a numpy array so explicitly chech against None
1 parent 6fd28b1 commit 2d48b00

2 files changed

Lines changed: 26 additions & 6 deletions

File tree

qcodes/plots/pyqtgraph.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -526,9 +526,9 @@ def fixUnitScaling(self, startranges: Optional[Dict[str, Dict[str, Union[float,i
526526
for i, plot in enumerate(self.subplots):
527527
# make a dict mapping axis labels to axis positions
528528
for axis in ('x', 'y', 'z'):
529-
if self.traces[i]['config'].get(axis):
530-
unit = self.traces[i]['config'][axis].unit
531-
if unit not in standardunits:
529+
if self.traces[i]['config'].get(axis) is not None:
530+
unit = getattr(self.traces[i]['config'][axis], 'unit', None)
531+
if unit is not None and unit not in standardunits:
532532
if axis in ('x', 'y'):
533533
ax = plot.getAxis(axismapping[axis])
534534
else:
@@ -546,18 +546,18 @@ def fixUnitScaling(self, startranges: Optional[Dict[str, Dict[str, Union[float,i
546546
ax.update()
547547

548548
# set limits either from dataset or
549-
setarr = self.traces[i]['config'][axis].ndarray
549+
setarr = getattr(self.traces[i]['config'][axis], 'ndarray', None)
550550
arrmin = None
551551
arrmax = None
552-
if not np.all(np.isnan(setarr)):
552+
if setarr and not np.all(np.isnan(setarr)):
553553
arrmax = setarr.max()
554554
arrmin = setarr.min()
555555
elif startranges is not None:
556556
try:
557557
paramname = self.traces[i]['config'][axis].full_name
558558
arrmax = startranges[paramname]['max']
559559
arrmin = startranges[paramname]['min']
560-
except (IndexError, KeyError):
560+
except (IndexError, KeyError, AttributeError):
561561
continue
562562

563563
if axis == 'x':

qcodes/tests/test_plots.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- just test "window creation"
77
"""
88
from unittest import TestCase, skipIf
9+
import numpy as np
910
import os
1011

1112
try:
@@ -44,6 +45,25 @@ def test_creation(self):
4445
plotQ = QtPlot(remote=False, show_window=False, interval=0)
4546
plotQ.add_subplot()
4647

48+
def test_simple_plot(self):
49+
plotQ = QtPlot(remote=False, show_window=False, interval=0)
50+
plotQ.add_subplot()
51+
52+
main_QtPlot = QtPlot(
53+
window_title='Main plotmon of TestQtPlot',
54+
figsize=(600, 400))
55+
56+
x = np.arange(0, 10e-6, 1e-9)
57+
f = 2e6
58+
y = np.cos(2*np.pi*f*x)
59+
60+
for j in range(4):
61+
main_QtPlot.add(x=x, y=y,
62+
xlabel='Time', xunit='s',
63+
ylabel='Amplitude', yunit='V',
64+
subplot=j+1,
65+
symbol='o', symbolSize=5)
66+
4767

4868
@skipIf(noMatPlot, '***matplotlib plotting cannot be tested***')
4969
class TestMatPlot(TestCase):

0 commit comments

Comments
 (0)