Double X Axis pyqtgraph

590 views
Skip to first unread message

Dimitri Linten

unread,
Aug 12, 2014, 5:45:58 AM8/12/14
to pyqt...@googlegroups.com

Hi,

I am transforming my code from using matplotlib to Pyqygraph

I am struggelig with the creation of a double X axis graph.

My current code is 

from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph as pg
from numpy import *
import sys

app = QtGui.QApplication([])

# Data : plot in a double X axis :  top (Leak data) and bottom (V data), I on Y axis
V = array([0,0.02,0.6,0.8,0.9,1,2,3,4,5])
I = array([0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9])
Leak =array([0.0000501,0.0000502,0.0000501,0.0000503,0.00005,0.00005,0.000055,0.000055,0.000065,0.0001])

pg.mkQApp()
pw = pg.PlotWidget()
pw.show()
p1 = pw.plotItem
p2 = pg.ViewBox()
p1.scene().addItem(p2)
p2.setGeometry(p1.vb.sceneBoundingRect())
p1.showAxis('top') # This results in shift of the second plot
p1.getAxis('top').linkToView(p2)
p2.setYLink(p1)
p1.plot(V,I)
p2.addItem(p1.plot(Leak,I, pen= 'b'))

sys.exit(app.exec_())

With the method above, I seem to create a systematic offset when plotting the data: I should get a shared Y data plot, but the data plotted  on the top axis has an offset.

Any idea what I am doing wrong ?

Thank you in advance

Regards

Dimitri


Dimitri Linten

unread,
Aug 12, 2014, 9:27:59 AM8/12/14
to pyqt...@googlegroups.com
I fixed it based on previous post

## Handle view resizing 
def updateViews():
    ## view has resized; update auxiliary views to match
    global p1, p2
    p2.setGeometry(p1.vb.sceneBoundingRect())
    
    ## need to re-update linked axes since this was called
    ## incorrectly while views had different shapes.
    ## (probably this should be handled in ViewBox.resizeEvent)
    p2.linkedViewChanged(p1.vb, p2.YAxis)


updateViews()
p1.vb.sigResized.connect(updateViews)
Reply all
Reply to author
Forward
0 new messages