<https://lh3.googleusercontent.com/-gAP0_Jp0-aw/V-tAqE3YBhI/AAAAAAAAABY/kQ6_856NotESHEO2mIDDGfbKt7qM9RIbACLcB/s1600/mplot.png>

I am new to pyqtgraph. I modified a multiaxis example that I found on the 
Internet and placed into a PyQt4 GraphicsView widget. The example shows the 
third axis before I embedded into the GUI, however when I embed, the third 
axis doesn't show up. I have read everything that I can find with no luck. 
Can someone please help? Ideally, I would like for the third axis to appear 
just to the right of the second axis.The graph is pictured above. Here is 
the code:


#imports
from PyQt4 import QtGui
from PyQt4 import QtCore
import ui_test  #Gui File
import sys
import pyqtgraph as pg

class Gui(QtGui.QMainWindow, ui_test.Ui_MainWindow):        
    def __init__(self):        
        super(self.__class__, self).__init__()        
        self.setupUi(self)  
        self.pg_plot()
        self.updateViews()
        self.plotdata()
        self.pushButton_movecursor.clicked.connect(self.movecursor)
    
    def pg_plot(self):          
        ## Switch to using white background and black foreground
        self.bepx = 30
        self.bepy = 800
        pg.setConfigOption('background', 'w')
        pg.setConfigOption('foreground', 'k')  
        lr = pg.LinearRegionItem([20,40], movable = False, brush = 
'#ffcccc33')  #Set linear region 
        self.p1 = pg.PlotItem()
        
        self.p1.addItem(lr)
        self.graphicsView.setCentralWidget(self.p1)
        self.p1.showGrid(x = True, y = True ,alpha = 0.3)  
        ## create a new ViewBox, link the right axis to its coordinate 
system
        self.p2 = pg.ViewBox()
        
        self.p1.showAxis('right')
        self.p1.scene().addItem(self.p2)
        self.p1.getAxis('right').linkToView(self.p2)
        self.p2.setXLink(self.p1)
        self.p1.getAxis('right').setLabel('eff', color='g')
        pg.LinearRegionItem([20,40])
        
        ## create third ViewBox. 
        ## this time we need to create a new axis as well.
        self.p3 = pg.ViewBox()
        ax3 = pg.AxisItem('right')
        self.p1.layout.addItem(ax3,2,3)
        self.p1.scene().addItem(self.p3)
        ax3.linkToView(self.p3)
        self.p3.setXLink(self.p1)
        ax3.setZValue(-10000)
        ax3.setLabel('Power', color='r')    
        
        self.arrow = pg.ArrowItem(angle=90)
        self.text = pg.TextItem(html='<div style="text-align: center"><span 
style="color: 'b' ;">^</span><br><span style="color: #000; font-size: 
16pt;">BEP</span></div>', anchor=(-0.3,1.3), border='w', fill=(255, 255, 
255, 100))
        self.p3.addItem(self.text)
        
        self.p3.addItem(self.arrow)
        self.text.setPos(self.bepx - 1.2, self.bepy - 530)
        ax3.setStyle(showValues=False)   #Not needed workig on gridlines
        
    ## Handle view resizing 
    def updateViews(self):
        ## view has resized; update auxiliary views to match
        
        self.p2.setGeometry(self.p1.vb.sceneBoundingRect())
        self.p3.setGeometry(self.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)
        self.p2.linkedViewChanged(self.p1.vb, self.p2.XAxis)
        self.p3.linkedViewChanged(self.p1.vb, self.p3.XAxis)
       
    def plotdata(self):
        #Plot Datapoints
        self.p1.plot([0,10,20,30,40,50], [1,2,4,8,16,32], pen = 'g')
        self.p2.addItem(pg.PlotCurveItem([0,10,20,30,40,50], 
[10,20,40,80,40,20], pen='b'))
        self.p3.addItem(pg.PlotCurveItem([0,10,20,30,40,50], 
[3200,1600,800,2500,200,100], pen='r'))
        self.bepx = 50
        self.bepy = 1000
        
    x = 1
    y = 1
    def movecursor(self):
        try:
            self.cursor.clear()
        except:
            pass
        self.x += 1
        if self.x > 50:
            self.x = 1
        self.y += 1
        if self.y > 30:
            self.y = 1
        
        self.cursor = self.p1.plot([self.x], [self.y], pen=None, 
symbol='+', color = 'b')
                
def main():
    app = QtGui.QApplication(sys.argv) 
    form = Gui() 
    form.show()  
    app.exec_() 
    
if __name__ == '__main__':  # if we're running file directly and not 
importing it
    main()  # run the main function





-- 
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/41952418-d3ce-47d5-946e-89f5ac4421f5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to