Multiple Y Axis for single plot window

5,095 views
Skip to first unread message

Stefan H

unread,
Mar 18, 2013, 4:58:33 PM3/18/13
to pyqt...@googlegroups.com
Hello,

Is there any possibilty to have multiple Y Axis for a PlotWidget containing different line graphs.

For e.g. I might have a live view showing a voltage and a current line plot. I want to add 2 axis to the left of the plot.

Stefan H

unread,
Mar 18, 2013, 5:02:39 PM3/18/13
to pyqt...@googlegroups.com
For e.g. how to generate a plot somehow like this: http://matplotlib.org/examples/axes_grid/demo_parasite_axes2.html ?

Luke Campagnola

unread,
Mar 19, 2013, 11:54:44 AM3/19/13
to pyqt...@googlegroups.com
This is possible, but it takes a little work. There is an earlier discussion of related issues here:

And I've uploaded an example of adding an extra axis here:

This will eventually become a built-in feature, but I don't have time to put it together at the moment.

Luke

Stefan H

unread,
Mar 19, 2013, 3:46:38 PM3/19/13
to pyqt...@googlegroups.com
Hi Luke,

Thanks a lot for your example, this was excactly what I was looking for. I switched to your development branche, because your example requires the signal "sigResized" which seems to be not present on the mainline.

Stefan

Blot Romain

unread,
Dec 10, 2013, 9:55:00 AM12/10/13
to pyqt...@googlegroups.com
Hi,

I simply put your example in a method "yyyAxisPlot" and I don't understand why the third axe is not display (see attached). Can you give me a hand please.

BTW : thanks for doing pyqtgraph. It is very useful.

Romain
multiplotYaxes.py

Luke Campagnola

unread,
Dec 10, 2013, 1:30:47 PM12/10/13
to pyqt...@googlegroups.com
On Tue, Dec 10, 2013 at 9:55 AM, Blot Romain <blot....@gmail.com> wrote:
Hi,

I simply put your example in a method "yyyAxisPlot" and I don't understand why the third axe is not display (see attached). Can you give me a hand please.


Simple mistake: when adding an item to a layout, PyQt does not add a new reference to the item. Consequently, ax3 is collected as soon as yyyAxisPlot exits. An easy solution is just to add `pw.ax3 = ax3`.
 

Blot Romain

unread,
Dec 11, 2013, 3:45:01 AM12/11/13
to pyqt...@googlegroups.com
Works perfect! Thx

Blot Romain

unread,
Dec 11, 2013, 7:29:09 AM12/11/13
to pyqt...@googlegroups.com
Also, I try to add a legend with :

    #legends
    legend
= pg.LegendItem()
    legend
.setParentItem(pw.graphicsItem())
    legend
.addItem(p1,"item 1")
    legend
.addItem(p2,"item 1")
    legend
.addItem(p3,"item 2")

but it is not working because of viewbox. Any idea?

Romain

Luke Campagnola

unread,
Dec 11, 2013, 11:27:32 AM12/11/13
to pyqt...@googlegroups.com
On Wednesday, December 11, 2013 7:29:09 AM UTC-5, Blot Romain wrote:
Also, I try to add a legend with :

    #legends
    legend
= pg.LegendItem()
    legend
.setParentItem(pw.graphicsItem())
    legend
.addItem(p1,"item 1")
    legend
.addItem(p2,"item 1")
    legend
.addItem(p3,"item 2")

but it is not working because of viewbox. Any idea?

I do not understand--what is "not working" ? The following works as expected:

import pyqtgraph as pg
pw = pg.plot()
p1 = pw.plot([1,4,2,3], pen='r')
p2 = pw.plot([4,2,3,1], pen='g')
p3 = pw.plot([2,3,1,4], pen='b')

Blot Romain

unread,
Dec 11, 2013, 11:41:02 AM12/11/13
to pyqt...@googlegroups.com
Thanks for your answer.
This works for me too. But for my multiplotYaxes.py example (see attached above) I got this error :  
 
opts = self.item.opts
AttributeError: 'ViewBox' object has no attribute 'opts'

Luke Campagnola

unread,
Dec 11, 2013, 1:49:14 PM12/11/13
to pyqt...@googlegroups.com
On Wed, Dec 11, 2013 at 11:41 AM, Blot Romain <blot....@gmail.com> wrote:
Thanks for your answer.
This works for me too. But for my multiplotYaxes.py example (see attached above) I got this error :  
 
opts = self.item.opts
AttributeError: 'ViewBox' object has no attribute 'opts'



I see. The problem is that your p1, p2, p3 are PlotItems and ViewBoxes, whereas legend.addItem() requires a PlotCurveItem or PlotDataItem as its first argument.
 
Reply all
Reply to author
Forward
0 new messages