plot and a residual plot at the bottom with a shared axis

87 views
Skip to first unread message

Trifon Trifonov

unread,
Oct 19, 2020, 2:05:17 PM10/19/20
to pyqtgraph

Can somebody please advice how to get a plot like this (attached):

Details are not important, I just need a plot and a residual plot at the bottom. Important is also that the x-axis must be one shown at the residual plot.


I want the same effect for these two plot in the Exo-Striker tool (attached 2)

Thanks a lot!


RV_plot.png
ES1_new.png

Ognyan Moore

unread,
Oct 19, 2020, 2:35:38 PM10/19/20
to pyqt...@googlegroups.com
My first try would be to use a GraphicsLayout and add the two plots that way

layout = pg.GraphicsLayout()
topPlot = pg.PlotDataItem(*args, **kwargs)
bottomPlot = pg.PlotDataItem(*args, **kwargs, axisItems={'bottom', axis})
layout.addItem(topPlot, row=0)
layout.addItem(bottomPlot, row=1)

# layout.layout is QGraphicsGridLayout, which has more sizing methods that may be handy, like setting fixed heights
layout.layout.setRowFixedHeight(1, 200)  # guessing 200 pixels, set the height to whatever you want

Would that accomplish what you're looking for?

--
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 pyqtgraph+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/252f2f18-e4c2-4c38-b00d-3727f9d9bd48n%40googlegroups.com.

Trifon Trifonov

unread,
Oct 21, 2020, 4:52:00 PM10/21/20
to pyqtgraph
Thanks, Ognyan,

Unfortunatly, I am still puzzled how to make it, even with your seemingly logical example.

I guess my problem comes from the fact that I promoted a QtDesigner's QGraphicsView widget to pyqtgraph PlotWidget().


E.g. a minimal example is:


"""""""""""""""""""""""""""
    def initialize_plots(self):
        global p1

        p1  = self.graphicsView_timeseries_RV # which is a PlotWidget

"""""""""""""""""""""""""""
   def update_RV_plots(self):
        global fit, p1

        p1.plot(clear=True,)
            
        model_curve = p1.plot(fit.fit_results.model_jd,y_model,
        pen={'color': fit.colors[-1], 'width': self.rv_model_width.value()},enableAutoRange=True, #symbolPen={'color': 0.5, 'width': 0.1}, symbolSize=1,symbol='o',
        viewRect=True, labels =  {'left':'RV', 'bottom':'JD'})
        
        model_curve.setZValue(self.RV_model_z.value())
        

        error_list = fit.fit_results.rv_model.rv_err


        for i in range(max(fit.filelist.idset)+1):
            p1.plot(fit.fit_results.rv_model.jd[fit.filelist.idset==i],fit.fit_results.rv_model.rvs[fit.filelist.idset==i],
            pen=None, #{'color': colors[i], 'width': 1.1},
            symbol=fit.pyqt_symbols_rvs[i],
            symbolPen={'color': fit.colors[i]+"%02x"%int(fit.pyqt_color_alpha_rvs[i])
, 'width': 1.1},
            symbolSize=fit.pyqt_symbols_size_rvs[i],enableAutoRange=True,viewRect=True,
            symbolBrush=fit.colors[i]+"%02x"%int(fit.pyqt_color_alpha_rvs[i])
            )

            err1 = pg.ErrorBarItem(x=fit.fit_results.rv_model.jd[fit.filelist.idset==i],
                                   y=fit.fit_results.rv_model.rvs[fit.filelist.idset==i],symbol='o',
            top=error_list[fit.filelist.idset==i],
            bottom=error_list[fit.filelist.idset==i],
            beam=0.0, pen=fit.colors[i]+"%02x"%int(fit.pyqt_color_alpha_rvs[i]))  

            p1.addItem(err1)
 

edmondo.g...@gmail.com

unread,
Oct 22, 2020, 6:50:55 AM10/22/20
to pyqtgraph
Promote it to a GraphicLayout, then add plots to it:
gl = <your graphic layout from a promoted  QGraphicView>

p1 = gl.addPlot(0,0) # it will contain your data
p2 = gl.addPlot(1,0) # it will contain the error

Then you may need to link the axis so that scrolling one scroll also the second. You may have to give different heights to the plots, etc. 

Trifon Trifonov

unread,
Jul 12, 2021, 11:25:44 AM7/12/21
to pyqtgraph
Dear All, I am back to this problem.

Thanks to Edmondo and Ognyan I have some progress, but now the question is how to revert back to a single plot.

I have:

test_one_plot.png

And

#######################


......
......
        l = pg.GraphicsLayout()                                                             
        p1.setCentralItem(l)                                                                                                                        

        p00 = l.addPlot(0, 0)                                                                
        p00.hideAxis('bottom')                                                              
        p01 = l.addPlot(1, 0)                                                                
        p01.setXLink(p00)                                                                     

        p00.showAxis('top')
        p00.showAxis('right')
        p01.showAxis('top')
        p01.showAxis('right')

..... (and code below)....
#######################


When I trigger "RV plot add o-c"

I get this:

test_two_plots.png

Which is great!


However, how to revert back to the single plot?


The best I could figure out was:

        if self.RV_plot_add_o_c.isChecked():
            self.update_RV_plot_with_o_c()            
        else:
            try:
                p1.scene().removeItem(p00)
                p1.scene().removeItem(p01)
            except:
                pass
            self.update_RV_plot()
        self.update_RV_plot_o_c()


But this simply removes p00 and  p01,  leaving an empty scene, i.e.:

test_two_plots2.png

I want when I set "RV plot add o-c" ==False, to get back to the original plot.


i.e I want to keep the original p1 and only plot on top p00,p01 until I decide to remove them?
Reply all
Reply to author
Forward
0 new messages