I'm trying to plot 2 different plots in a single graph window (Sample Code 
given below). I'm using ViewBox to bring an independent 2nd y axis but I'm 
unable to apply log scale on both x and the y axis for the 2nd plot being 
plotted through View Box. Also please let me know if I can add a legend for 
the 2ns plot in vb as well !!! Can I have any solution please ?  
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
import numpy as np
import pandas as pd

pg.mkQApp()

pw = pg.PlotWidget()
legend = pw.plotItem.legend
pw.plotItem.addLegend(offset=(50, 10))
pw.plotItem.addLegend()
pw.setLogMode(x=True, y=True)


pw.show()
pw.setWindowTitle('pyqtgraph example: MultiplePlotAxes')
p1 = pw.plotItem
p1.setLabels(left='axis 1')

## create a new ViewBox, link the right axis to its coordinate system
p2 = pg.ViewBox()

p1.showAxis('right')
p1.setLogMode(x=True, y=True)
p1.scene().addItem(p2)

p1.getAxis('right').linkToView(p2)

p1.getAxis('right').setLogMode(True)
p1.getAxis('left').setLogMode(False)
p1.getAxis('bottom').setLogMode(True)
#p1.getAxis('bottom').linkToView(p2)
#p2.setXLink(p1)
p1.getAxis('right').setTicks(False)  #.setLabel('axis2', color='#0000ff')


## 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.XAxis)



updateViews()
p1.vb.sigResized.connect(updateViews)

x = [0.00189308411214953, 0.0586856074766355, 0.113585046728972, 
0.172270654205607, 0.229063177570093, 0.751554392523364, 0.804560747663551, 
0.863246355140187]

y1 = [20.4519856776661, 2.36731824818362, 1.37059599828579, 
0.893434884015263, 0.654398170298103, 0.16233537659946, 0.136188319914979, 
0.12445839587513]

y2 = [100.206092906091, 10.7767052017243, 6.7863521253753, 5.06574658107859, 
4.13195800053371, 3.54173495603609, 3.12977548096585, 0.109898121408567]


p1.plot(x,y1, name = 'First Curve')


p2.addItem(pg.PlotCurveItem(x,y2, name = 'SecondCurve', pen='b'))


## Start Qt event loop unless running in interactive mode or using pyside.
if __name__ == '__main__':
    import sys

    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
        QtGui.QApplication.instance().exec_()

-- 
You received this message because you are subscribed to the Google Groups 
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pyqtgraph/ac0c2335-5c1e-499f-a267-37472deec2cdn%40googlegroups.com.

Reply via email to