ymmx
ymmx

Reputation: 4967

Pyqtgraph: How do I plot an ellipse or a circle

I would like plot circles or ellipses in Pyqtgraph gl.GLViewWidget(). However I did not find a function to do that. Anyone know the way to do that?

Upvotes: 1

Views: 4474

Answers (3)

roshambo
roshambo

Reputation: 347

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. 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

Upvotes: 4

Tobias
Tobias

Reputation: 34

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()

Upvotes: 1

John Lunzer
John Lunzer

Reputation: 361

As a regular user of pyqtgraph I do not believe that it has functions for generating circles or ellipses. 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.

Upvotes: 1

Related Questions