是否可以使用Matplotlib imshow()将2D数组显示为极坐标图? [英] Is it possible to display 2D array as polar plot using Matplotlib imshow()?
问题描述
我是matplotlib的新手(并且喜欢它!),但感到沮丧.我有一个表示为2D数组的极坐标网格.(行是径向截面,列是方位角截面)
I'm new to matplotlib (and am loving it!), but am getting frustrated. I have a polar grid represented as a a 2D array. (rows are radial sections, columns are azimuthal sections)
我已经能够使用 pyplot.imshow() 将二维数组显示为矩形图像(R vs. theta)和使用 pyplot.pcolor() 的极坐标图.但是,对于我正在使用的数组的大小,pcolor() 很慢,所以我希望能够使用 imshow() 将数组显示为极坐标网格.
I've been able to display the 2D array as both a rectangular image (R vs. theta) using pyplot.imshow() and as a polar plot using pyplot.pcolor(). However, pcolor() is painfully slow for the size of the arrays I'm using, so I want to be able to display the array as a polar grid using imshow().
使用pcolor(),这就像为子图设置polar = True一样简单.有什么方法可以使用imshow()将2D数组显示为极坐标图?无需对整个数组进行坐标变换?预先感谢
Using pcolor(), this is as simple as setting polar=True for the subplot. Is there any way to display the 2D array as a polar plot using imshow()? without having to do coordinate transformations on the entire array? Thanks in advance
推荐答案
经过一些研究,我发现了 pcolormesh() 函数,它已被证明明显比使用 pcolor() 快,并且可以与imshow() 的速度.
After some research I discovered the pcolormesh() function, which has proven to be significantly faster than using pcolor() and comparable to the speed of imshow().
这是我的解决方案:
import matplotlib.pyplot as plt
import numpy as np
#...some data processing
theta,rad = np.meshgrid(used_theta, used_rad) #rectangular plot of polar data
X = theta
Y = rad
fig = plt.figure()
ax = fig.add_subplot(111)
ax.pcolormesh(X, Y, data2D) #X,Y & data2D must all be same dimensions
plt.show()
这篇关于是否可以使用Matplotlib imshow()将2D数组显示为极坐标图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!