Hi Jona,
Thanks for the swift reply!
I am aware that you can get the PlotItem() from the PlotWidget object. I am
not sure if this is useful, but
below I shared my actual code.Shortly, I tried:
p1vb = p1.getPlotItem()
vb = p1vb.vb #(to get the ViewBox, later needed in mousePoint =
vb.mapSceneToView(pos))
but still I cant get the needed effect on my plot.
def update_RV_plots(self):
global fit, p1,p2
p1.plot(clear=True,)
p2.plot(clear=True,)
self.check_RV_symbol_sizes()
if len(fit.filelist.idset)==0:
return
if self.jitter_to_plots.isChecked():
error_list = self.add_jitter(fit.fit_results.rv_model.rv_err,
fit.filelist.idset)
else:
error_list = fit.fit_results.rv_model.rv_err
p1.addLine(x=None, y=0, pen=pg.mkPen('#ff9933', width=0.8))
#p1.addLine(x=None, y=fap, pen=pg.mkPen('k', width=0.8,
style=QtCore.Qt.DotLine)) for ii,fap in enumerate(np.array([0]) ) ]
if fit.doGP == True:
y_model = fit.fit_results.model + fit.gp_model_curve[0]
y_model_o_c = fit.gp_model_curve[0]
else:
y_model = fit.fit_results.model
y_model_o_c = np.zeros(len(y_model))
p1.plot(fit.fit_results.model_jd,y_model,
pen={'color': 0.5, 'width': 1.1},enableAutoRange=True,
#symbolPen={'color':
0.5, 'width': 0.1}, symbolSize=1,symbol='o',
viewRect=True, labels = {'left':'RV', 'bottom':'JD'})
if fit.doGP == True:
pfill = pg.FillBetweenItem(p1.plot(fit.fit_results.model_jd, fit
.fit_results.model + fit.gp_model_curve[0]+fit.gp_model_curve[2]),
p1.plot(fit.fit_results.model_jd, fit
.fit_results.model + fit.gp_model_curve[0]-fit.gp_model_curve[2]),
brush = pg.mkColor(244,140,66,128))
p1.addItem(pfill)
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], 'width': 1.1},
symbolSize=fit.pyqt_symbols_size_rvs[i],enableAutoRange=True,
viewRect=True,
symbolBrush=fit.colors[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',
#height=error_list[fit.filelist.idset==i],
top=error_list[fit.filelist.idset==i],
bottom=error_list[fit.filelist.idset==i],
beam=0.0, pen=fit.colors[i])
p1.addItem(err1)
################### TEST cross hair ############
# p1.setAutoVisible(y=True)
cross = True
if cross ==True:
#cross hair
vLine = pg.InfiniteLine(angle=90, movable=False)
hLine = pg.InfiniteLine(angle=0, movable=False)
p1.addItem(vLine, ignoreBounds=True)
p1.addItem(hLine, ignoreBounds=True)
p1vb = p1.getPlotItem()
vb = p1vb.vb
# print(vb)
label = pg.LabelItem(justify='right')
p1.addItem(label)
data1 = fit.fit_results.rv_model.rvs
def mouseMoved(evt):
pos = evt[0] ## using signal proxy turns original
arguments into a tuple
print(pos)
if p1.sceneBoundingRect().contains(pos):
mousePoint = vb.mapSceneToView(pos)
index = int(mousePoint.x())
if index > 0 and index < len(data1):
label.setText("%s %s" % (mousePoint.x(), data1[
index]))
vLine.setPos(mousePoint.x())
hLine.setPos(mousePoint.y())
proxy = pg.SignalProxy(p1.scene().sigMouseMoved, rateLimit=60,
slot=mouseMoved)
################### TEST cross hair ############
On Thursday, May 9, 2019 at 1:20:27 PM UTC+2, Jona Joachim wrote:
>
> Hi Trifon,
> you can get the PlotItem using the getPlotItem() method of your PlotWidget.
>
> p1 = graphicsView.getPlotItem()
>
>
> Kind regards,
> Jona Joachim
>
> On Thursday, 9 May 2019 11:35:50 UTC+2, Trifon Trifonov wrote:
>>
>> I am trying to make a cross hair on my pyqtgraph interactive plots, which
>> are embedded in a PyQt5 GUI thanks to the designer-qt5. I found a working
>> code in the pyqtgraph "examples". A simplified WORKING example is posted
>> below. Now I want the same, but the problem seems to be that I promoted a
>> QGraphicsView() to a pg.PlotWidget in the designer, instead of
>> pg.GraphicsWindow()? The Code does not work for me because my p1 is
>> "pyqtgraph.widgets.PlotWidget.PlotWidget object" while in the example p1 is
>> "pyqtgraph.graphicsItems.PlotItem.PlotItem.PlotItem object".
>>
>>
>> So what should I do to make this example work for me?
>>
>>
>>
>>> import numpy as np
>>> import pyqtgraph as pg
>>> from pyqtgraph.Qt import QtGui, QtCore
>>> from pyqtgraph.Point import Point
>>>
>>> pg.setConfigOption('background', '#ffffff')
>>> pg.setConfigOption('foreground', 'k')
>>> pg.setConfigOptions(antialias=True)
>>>
>>> app = QtGui.QApplication([])
>>> win = pg.GraphicsWindow()
>>> win.setWindowTitle('pyqtgraph example: crosshair')
>>> label = pg.LabelItem(justify='right')
>>> win.addItem(label)
>>> p1 = win.addPlot(row=1, col=0)
>>>
>>> p1.setAutoVisible(y=True)
>>>
>>> #create numpy arrays
>>> #make the numbers large to show that the xrange shows data from 10000 to
>>> all the way 0
>>> data1 = 10000 + 15000 * pg.gaussianFilter(np.random.random(size=10000), 10)
>>> + 3000 * np.random.random(size=10000)
>>>
>>> p1.plot(data1, pen="r")
>>>
>>> #cross hair
>>> vLine = pg.InfiniteLine(angle=90, movable=False)
>>> hLine = pg.InfiniteLine(angle=0, movable=False)
>>> p1.addItem(vLine, ignoreBounds=True)
>>> p1.addItem(hLine, ignoreBounds=True)
>>>
>>> vb = p1.vb
>>>
>>> print(p1)
>>> print(vb)
>>>
>>> def mouseMoved(evt):
>>> pos = evt[0] ## using signal proxy turns original arguments into a
>>> tuple
>>> if p1.sceneBoundingRect().contains(pos):
>>> mousePoint = vb.mapSceneToView(pos)
>>> index = int(mousePoint.x())
>>> if index > 0 and index < len(data1):
>>> label.setText("<span style='font-size: 12pt'>x=%0.1f, <span
>>> style='color: green'>y2=%0.1f</span>" % (mousePoint.x(), data1[index]))
>>> vLine.setPos(mousePoint.x())
>>> hLine.setPos(mousePoint.y())
>>>
>>> proxy = pg.SignalProxy(p1.scene().sigMouseMoved, rateLimit=60,
>>> slot=mouseMoved)
>>> #p1.scene().sigMouseMoved.connect(mouseMoved)
>>>
>>> ## 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/cee4ebb8-443d-4c5f-a87e-3dd6b9945af2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.