Producing a polar plot

2,278 views
Skip to first unread message

k.bes...@gmail.com

unread,
Jan 8, 2014, 3:51:38 AM1/8/14
to pyqt...@googlegroups.com
Hello,
I am using pyqtgraph for a small project, where I need to plot several data sources in "real time". The orthogonal plotting works great, but I also need a polar plot.
Could you please comment if this is feasible with pyqqtgraph and what should be the best approach I should take to produce a polar plot.
I suspect I would need to override some of the methods, but a starting point would be great.

Luke Campagnola

unread,
Jan 8, 2014, 9:42:56 AM1/8/14
to pyqt...@googlegroups.com
PyQtGraph does not have anything built-in for handling polar plots. The easiest approach at present is to just transform the data yourself before plotting, and use a combination of lines and circles to draw the grid. For example:

import pyqtgraph as pg

plot = pg.plot()
plot.setAspectLocked()

# Add polar grid lines
plot.addLine(x=0, pen=0.2)
plot.addLine(y=0, pen=0.2)
for r in range(2, 20, 2):
    circle = pg.QtGui.QGraphicsEllipseItem(-r, -r, r*2, r*2)
    circle.setPen(pg.mkPen(0.2))
    plot.addItem(circle)

# make polar data
import numpy as np
theta = np.linspace(0, 2*np.pi, 100)
radius = np.random.normal(loc=10, size=100)

# Transform to cartesian and plot
x = radius * np.cos(theta)
y = radius * np.sin(theta)
plot.plot(x, y)

 

k.bes...@gmail.com

unread,
Jan 8, 2014, 10:11:49 AM1/8/14
to pyqt...@googlegroups.com
Great!
I just ran your example and it looks like it will do job for me. I was so reluctant to switch to matplotlib, as pyqtgraph worked so well for me .
Many Thanks
Reply all
Reply to author
Forward
0 new messages