python - matplotlib - 带有弧度角标签的极坐标图

标签 python numpy matplotlib polar-coordinates

我遇到的问题看起来很简单:每当我绘制极坐标图时,角度刻度由 ThetaFormatter 处理,以度为单位标记它们。

我知道这个question ,其中刻度标签替换为风玫瑰名称,并且此 example matplotlib 看起来像在笛卡尔坐标系中做我想做的,但我还没有找到如何在极坐标图中做同样的事情……这是最自然的地方!

这是极坐标图的一些简单示例:

from pylab import *
fig = figure()
axe = fig.gca(polar=True)
thetas = linspace(0,2*pi,200)
rhos = 3+cos(5*thetas)
axe.plot(thetas, rhos)
fig.show()

最佳答案

应该这样做:

>>> fig=plt.figure()
>>> axe=fig.gca(polar=True)
>>> thetas=linspace(0,2*pi,200)
>>> rhos=3+cos(5*thetas)
>>> axe.plot(thetas, rhos)
[<matplotlib.lines.Line2D object at 0x109a2b550>]
>>> xT=plt.xticks()[0]
>>> xL=['0',r'$\frac{\pi}{4}$',r'$\frac{\pi}{2}$',r'$\frac{3\pi}{4}$',\
    r'$\pi$',r'$\frac{5\pi}{4}$',r'$\frac{3\pi}{2}$',r'$\frac{7\pi}{4}$']
>>> plt.xticks(xT, xL)
([<matplotlib.axis.XTick object at 0x107bac490>, <matplotlib.axis.XTick object at 0x109a31310>, <matplotlib.axis.XTick object at 0x109a313d0>, <matplotlib.axis.XTick object at 0x109a31050>, <matplotlib.axis.XTick object at 0x1097a8690>, <matplotlib.axis.XTick object at 0x1097a8cd0>, <matplotlib.axis.XTick object at 0x1097a8150>, <matplotlib.axis.XTick object at 0x107bb8fd0>], <a list of 8 Text xticklabel objects>)
>>> plt.show()

enter image description here

关于python - matplotlib - 带有弧度角标签的极坐标图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21172228/

相关文章:

python - Matplotlib 自定义图例以显示正方形而不是矩形

python - 如何在 Python 中使用 Pandas 绘制条形图以比较具有多个变量的多个系统

python - 为什么循环不想继续

python - 如何修改文件的最后一行?

python - 计算矩阵乘法的子集

python - 某些列的 Pandas 平均值

python - 平衡 numpy 数组与过采样

当范围小于十年时,Matplotlib log colorbar minor ticks 消失

python - 使用Rasterio保存窗口图像(另存为jpg)

python - 从坐标元组列表中选择最小值