Multiple yAxis in same plot?

48 views
Skip to first unread message

Carlos Gálvez

unread,
Jul 28, 2021, 8:07:12 AM7/28/21
to pyqtgraph
Hey guys, I'm here again with a pyqt-graph question. I want to do a BarGraph with the same xAxis but two different yAxis (left and right) related to the same values. For example in the left yAxis the % and in the right axis the values. So the left axis must be [0,1] and the right [0, yMax]. I've done some work on this but I'm stuck. In the following code I make two bargraphitem and I thinks that's not what I want. 

        resultWindow = pg.plot()
        resultWindow.setBackground('w')
        resultWindow.setXRange(0,16, 0.05)
        resultWindow.setYRange(0, 1, 0.05)
        plot1 = resultWindow.getPlotItem()
        plot1.showGrid(True, True)
        
       
        plot2 = pg.ViewBox()
        plot1.showAxis('right')
        plot1.scene().addItem(plot2)
        plot1.getAxis('right').linkToView(plot2)
        plot2.setXLink(plot1)
        plot1.getAxis('right').setLabel('Frecuencia')
    
        probabilities = [0,0, 0.5, 0.5]
        bargraph = pg.BarGraphItem(x=range(pow(2,qbits)), height = probabilities, width = 0.6, brush ='g')
        bargraph2 = pg.BarGraphItem(x=range(pow(2,qbits)), height = [0,0,100,100], width = 0.6, brush = 'r')
        plot1.addItem(bargraph)
        plot2.addItem(bargraph2)
        #updateViews()
        #plot1.vb.sigResized.connect(updateViews)

        
        titleLabel = QLabel("Histograma \n")
        vLayout = QVBoxLayout()
        vLayout.setContentsMargins(5,5,5,5)
        vLayout.addWidget(titleLabel)
        vLayout.addWidget(resultWindow)
        resultDialog.setLayout(vLayout)

Thanks in advance.
Reply all
Reply to author
Forward
0 new messages