Changing tick placement and reversing axes

407 views
Skip to first unread message

SPSkinner

unread,
Apr 25, 2014, 10:05:32 AM4/25/14
to pyqt...@googlegroups.com
Dear All,

I am attempting to build a pyqtgraph app in which I can have the axis labels and ticks placed inside the plot window rather than outside and I would also like to reverse the scales on the axes.

Is there an easy way to do this or would I need to subclass AxisItem and code my own extensions?

Thanks

Simon

Luke Campagnola

unread,
Apr 26, 2014, 2:54:08 PM4/26/14
to pyqt...@googlegroups.com
On Fri, Apr 25, 2014 at 10:05 AM, SPSkinner <simon.p...@gmail.com> wrote:
I am attempting to build a pyqtgraph app in which I can have the axis labels and ticks placed inside the plot window rather than outside and I would also like to reverse the scales on the axes.

Is there an easy way to do this or would I need to subclass AxisItem and code my own extensions?

 
Here are a couple of ideas to get you started. Let me know if you run into issues that are not covered here

Option 1:

import pyqtgraph as pg
w = pg.GraphicsWindow()
vb = w.addViewBox()
grid = pg.GridItem()
vb.addItem(grid)
vb.invertY()

Option 2:

import pyqtgraph as pg

class ViewWithAxes(pg.ViewBox):
    def __init__(self):
        pg.ViewBox.__init__(self)
        self.invertY()
        self.axis1 = pg.AxisItem(orientation='right', linkView=self, maxTickLength=10)
        self.axis1.setParentItem(self)

    def resizeEvent(self, ev):
        self.axis1.setMinimumHeight(self.height())
        self.axis1.setMaximumHeight(self.height())
        return pg.ViewBox.resizeEvent(self, ev)

w = pg.GraphicsWindow()
vb = ViewWithAxes()
w.addItem(vb)

SPSkinner

unread,
Apr 27, 2014, 3:04:50 PM4/27/14
to pyqt...@googlegroups.com
Hi, 

Thanks for the fast response.  I have managed to flip the Y axis, but is there a way to flip the X axis as well? I noticed that there wasn't an invertY method for the AxisItem, but logically the function would be the same as for the Y so I could simply add a function, couldn't I?

Thanks

Simon

Luke Campagnola

unread,
Apr 28, 2014, 7:39:58 AM4/28/14
to pyqt...@googlegroups.com
On Sun, Apr 27, 2014 at 3:04 PM, SPSkinner <simon.p...@gmail.com> wrote:
I have managed to flip the Y axis, but is there a way to flip the X axis as well? I noticed that there wasn't an invertY method for the AxisItem, but logically the function would be the same as for the Y so I could simply add a function, couldn't I?

It takes a bit more than just the invert function. But since you are not the first person to ask for this, I have just added it to the develop branch. You can see the changes here if you are curious:  https://github.com/pyqtgraph/pyqtgraph/commit/c6f2e9c2a92cbdbf1c58738de9771b80cbbe54b9


Luke 
Reply all
Reply to author
Forward
0 new messages