Skip to content

Commit

Permalink
Added a failing test for PyQT plotting (passes <0.1.7, fails at later…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
AdriaanRol authored and jenshnielsen committed Oct 23, 2017
1 parent 6fd28b1 commit 2d48b00
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
12 changes: 6 additions & 6 deletions qcodes/plots/pyqtgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,9 +526,9 @@ 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):
unit = self.traces[i]['config'][axis].unit
if unit not in standardunits:
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'):
ax = plot.getAxis(axismapping[axis])
else:
Expand All @@ -546,18 +546,18 @@ 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:
try:
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':
Expand Down
20 changes: 20 additions & 0 deletions qcodes/tests/test_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- just test "window creation"
"""
from unittest import TestCase, skipIf
import numpy as np
import os

try:
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 2d48b00

Please sign in to comment.