我正在尝试在pyqtgraph交互式绘图上制作十字形,这要归功于designer-qt5,它们已嵌入PyQt5 GUI中。我找到了工作
pyqtgraph中的“示例”中的代码。下面发布了一个简化的工作示例。现在,我希望得到同样的效果,但是问题似乎是我提升了
QGraphicsView()到设计器中的pg.PlotWidget,而不是pg.GraphicsWindow()?该代码对我不起作用,因为我的p1是“ pyqtgraph.widgets.PlotWidget.PlotWidget对象”,而在示例p1中是
“ pyqtgraph.graphicsItems.PlotItem.PlotItem.PlotItem对象”。
那我应该怎么做才能使这个例子适合我?
review1000 <- function(TOTALLISTINGS = NULL){
# tibble to return
to_return <- TOTALLISTINGS %>%
group_by(listing_id) %>%
summarise(
reviews1000 = sum(reviews_last30days[(calc.latitude>=(calc.latitude-500) | calc.latitude<=(calc.latitude+500))]))
return(to_return)
}
REVIEWPERAREA <- review1000(TOTALLISTINGS)
答案 0 :(得分:0)
我很抱歉听到这个声音!!!我自己修复!
重要的部分是:
plot_wg.proxy =代理
非常简单...
下面是该函数,该函数应适用于任何PlotWidget:
def cross_hair(self, plot_wg, log=False ):
global fit
################### TETS cross hair ############3
vLine = pg.InfiniteLine(angle=90, movable=False)#, pos=0)
hLine = pg.InfiniteLine(angle=0, movable=False)#, pos=2450000)
plot_wg.addItem(vLine, ignoreBounds=True)
plot_wg.addItem(hLine, ignoreBounds=True)
vb = plot_wg.getViewBox()
label = pg.TextItem()
plot_wg.addItem(label)
def mouseMoved(evt):
pos = evt[0] ## using signal proxy turns original arguments into a tuple
if plot_wg.sceneBoundingRect().contains(pos):
mousePoint = vb.mapSceneToView(pos)
if log == True:
label.setText("x=%0.3f, y1=%0.3f"%(10**mousePoint.x(), mousePoint.y()))
else:
label.setText("x=%0.3f, y1=%0.3f"%(mousePoint.x(), mousePoint.y()))
vLine.setPos(mousePoint.x())
hLine.setPos(mousePoint.y())
#print(mousePoint.x(),mousePoint.y())
plot_wg.getViewBox().setAutoVisible(y=True)
proxy = pg.SignalProxy(plot_wg.scene().sigMouseMoved, rateLimit=60, slot=mouseMoved)
plot_wg.proxy = proxy
proxy = pg.SignalProxy(plot_wg.scene().sigMouseMoved, rateLimit=60, slot=mouseMoved)
plot_wg.proxy = proxy
################### TETS cross hair ############3