Forcing update of axis tick strings in pyqtgraph

59 views
Skip to first unread message

pthomas

unread,
Feb 4, 2021, 3:07:37 PM2/4/21
to pyqtgraph
I am collaborating on code that uses a custom class for the time axis:

class TimeStringAxis(pg.AxisItem):
    def __init__(self, orientation='bottom', **kwargs):
        super().__init__(orientation, **kwargs)
        self.tick_strings_mode = 1

    def tickSpacing(self, minVal, maxVal, size):
        span = abs(maxVal - minVal)
        for major, minordiv in const.TICK_SPACINGS:
            if span >= 3*major:
                break
        return [
            (major, 0),
            (major/minordiv, 0),
        ]

    def tickStrings(self, values, scale, spacing):
        if self.tick_strings_mode == 0:
            return values
        elif self.tick_strings_mode == 1:
            return [str(util.TDStr(t)) for t in values]
        else:
            return values

    def setTickStringsMode(self, mode):
        self.tick_strings_mode = mode
        self.update()

The current goal is to be able to change the format of the tick strings from the plot context menu. The issue is that the tick strings do not update until a zoom or pan changes the range. Calling update doesn't seem to do anything. Is there a means to force the axis to repaint after the call to setTickStringsMode?

Patrick

unread,
Feb 4, 2021, 9:20:19 PM2/4/21
to pyqtgraph
Hi,

Try adding self.picture = None into your setTickStringsMode() method. I think the paint uses a rasterised buffer which simply gets redrawn on updates unless the buffer is cleared. So your self.update() is probably actually working - see the paint() method in AxisItem.

Patrick

Patrick Thomas

unread,
Feb 4, 2021, 10:17:50 PM2/4/21
to pyqt...@googlegroups.com
Yes, that works. Thank you!

--
You received this message because you are subscribed to a topic in the Google Groups "pyqtgraph" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pyqtgraph/0ELS5lFkm_U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pyqtgraph+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/81f9e277-6185-4f56-b12b-6b010d82883en%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages