简体   繁体   English

Pyqtgraph:如何绘制椭圆或圆

[英]Pyqtgraph: How do I plot an ellipse or a circle

I would like plot circles or ellipses in Pyqtgraph gl.GLViewWidget().我想在 Pyqtgraph gl.GLViewWidget() 中绘制圆圈或椭圆。 However I did not find a function to do that.但是我没有找到一个函数来做到这一点。 Anyone know the way to do that?有人知道这样做的方法吗?

import numpy as np
import pyqtgraph as pg
image = np.random.normal(size=(500, 400))
plt1 = pg.PlotWidget()
plt1_imageitem = pg.ImageItem(image)
plt1.addItem(plt1_imageitem)
roi_circle = pg.CircleROI([250, 250], [120, 120], pen=pg.mkPen('r',width=2))
# roi_circle.sigRegionChanged.connect(circle_update)
plt1.addItem(roi_circle)
plt1.show()

As a regular user of pyqtgraph I do not believe that it has functions for generating circles or ellipses.作为 pyqtgraph 的普通用户,我不相信它具有生成圆或椭圆的功能。 I believe that you would have to define the circle and ellipse functions yourself and generate the points of the circle or ellipse from those.我相信您必须自己定义圆和椭圆函数,并从中生成圆或椭圆的点。

There is functionality to be able to make shapes in pyqtgraph without having to use the ROI's - the ROI's seem to have movable anchor points which may be undesirable in some applications.有一种功能可以在 pyqtgraph 中制作形状而无需使用 ROI - ROI 似乎具有可移动的锚点,这在某些应用程序中可能是不受欢迎的。 Have not tested as applied to widgets though, but sharing this in case it is useful.虽然尚未测试适用于小部件,但分享它以防万一它有用。

I just did something along these lines我只是按照这些思路做了一些事情

import pyqtgraph as pg

win = pg.GraphicsLayoutWidget(show=True, title="Plotting")
p = win.addPlot(title='')

p_ellipse = pg.QtGui.QGraphicsEllipseItem(0, 0, 10, 20)  # x, y, width, height
p_ellipse.setPen(pg.mkPen((0, 0, 0, 100)))
p_ellipse.setBrush(pg.mkBrush((50, 50, 200)))

p.addItem(p_ellipse)

and it worked for me它对我有用

https://pyqtgraph.narkive.com/c1jAyVhn/draw-rectangles-and-lines https://pyqtgraph.narkive.com/c1jAyVhn/draw-rectangles-and-lines

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM