How to change the axis and gridline style?

31 views
Skip to first unread message

JJ

unread,
May 23, 2019, 3:49:58 AM5/23/19
to pyqtgraph
  • How can I change the color and width of the axis items and the gridlines?
  • How can I show plain lines on the top and right without the labels?
I have tried the following:
self.myplot.showAxis('right')
self.myplot.showAxis('top')

However, this shows additional x, y values on the top and right AND messes up the zoom behavior in one-mouse mode.
I just want to show a plain line on the top and right.

Patrick

unread,
May 23, 2019, 11:43:10 PM5/23/19
to pyqtgraph
Hi,

To answer the second point, something like
self.myplot.getAxis("top").setStyle(tickLength=0, showValues=False)
will draw just a plain line as an axis.

I knew you were going to ask the first point... :) Unfortunately there is just one "pen" parameter to AxisItem which controls the color of the axis line, grid lines and labels. So this probably doesn't do what you want:
self.myplot.getAxis("bottom").setPen({"color": (255, 0, 0), "width": 5})
I can't see an easy way to change this. The easiest would be to do it by subclassing AxisItem, and just overriding the drawPicture method with different hardcoded pens for axis lines, and grid lines. A nicer way would be to put the options in the constructor of course... When you create a PlotItem (eg with graphicsLayout.addPlot(...) method, you can pass in instances of your custom AxisItem(s) you have created for it to use.

Patrick
Reply all
Reply to author
Forward
0 new messages