Skip to content

Recent change to PyQTgraph plotting API breaks plotting with units #769

@AdriaanRol

Description

@AdriaanRol

I just merged QCoDeS master into our fork of QCoDeS and found that it breaks our live plotting.
I'll try to go to 0.1.7 now so that I have recent changes that I require.

Digging a bit deeper it seems that this is related to a change introduced by 35400a6

I have attached the relevant part of my traceback pointing to the problem.
I'll also add the relevant lines of codes with a bit more context below.

d:\githubrepos\pycqed_py3\pycqed\measurement\measurement_control.py in measure(self, *kw)
    171     def measure(self, *kw):
    172         if self.live_plot_enabled():
--> 173             self.initialize_plot_monitor()
    174 
    175         for sweep_function in self.sweep_functions:

d:\githubrepos\pycqed_py3\pycqed\measurement\measurement_control.py in initialize_plot_monitor(self)
    570                                      subplot=j+1,
    571                                      color=color_cycle[j % len(color_cycle)],
--> 572                                      symbol='o', symbolSize=5)
    573                 self.curves.append(self.main_QtPlot.traces[-1])
    574                 j += 1

d:\githubrepos\qcodes\qcodes\plots\base.py in add(self, updater, *args, **kwargs)
     89         # TODO(giulioungaretti): replace with an explicit version, see expand trace
     90         self.expand_trace(args, kwargs)
---> 91         self.add_to_plot(**kwargs)
     92         self.add_updater(updater, kwargs)
     93 

d:\githubrepos\qcodes\qcodes\plots\pyqtgraph.py in add_to_plot(self, subplot, **kwargs)
    147         if prev_default_title == self.win.windowTitle():
    148             self.win.setWindowTitle(self.get_default_title())
--> 149         self.fixUnitScaling()
    150 
    151     def _draw_plot(self, subplot_object, y, x=None, color=None, width=None,

d:\githubrepos\qcodes\qcodes\plots\pyqtgraph.py in fixUnitScaling(self, startranges)
    528             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:
    532                         if axis in ('x', 'y'):

AttributeError: 'list' object has no attribute 'unit'

This is the method that hits the offending line when adding a plot.

    def initialize_plot_monitor(self):
        # new code
        if self.main_QtPlot.traces != []:
            self.main_QtPlot.clear()
        self.curves = []
        xlabels = self.sweep_par_names
        xunits = self.sweep_par_units
        ylabels = self.detector_function.value_names
        yunits = self.detector_function.value_units

        j = 0
        if (self._persist_ylabs == ylabels and
                self._persist_xlabs == xlabels) and self.persist_mode():
            persist = True
        else:
            persist = False
        for yi, ylab in enumerate(ylabels):
            for xi, xlab in enumerate(xlabels):
                if persist:  # plotting persist first so new data on top
                    yp = self._persist_dat[
                        :, yi+len(self.sweep_function_names)]
                    xp = self._persist_dat[:, xi]
                    if len(xp) < self.plotting_max_pts():
                        self.main_QtPlot.add(x=xp, y=yp,
                                             subplot=j+1,
                                             color=0.75,  # a grayscale value
                                             symbol='o', symbolSize=5)
                self.main_QtPlot.add(x=[0], y=[0],
                                     xlabel=xlab,
                                     xunit=xunits[xi],
                                     ylabel=ylab,
                                     yunit=yunits[yi],
                                     subplot=j+1,
                                     color=color_cycle[j % len(color_cycle)],
                                     symbol='o', symbolSize=5)
                self.curves.append(self.main_QtPlot.traces[-1])
                j += 1
            self.main_QtPlot.win.nextRow()

For reference self.main_QtPlot is below. from qcodes.plots.pyqtgraph import QtPlot

            self.main_QtPlot = QtPlot(
                window_title='Main plotmon of {}'.format(self.name),
                figsize=(600, 400))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions