matplotlib极地图科学记数法

时间:2014-09-04 23:47:51

标签: matplotlib polar-coordinates

我正在尝试使用matplotlib绘制极坐标图,并希望执行以下操作: a)用科学记数法显示刻度标签 b)以指定的间隔显示半径圆。

任何人都可以给我建议如何做a)和b)使用下面的代码

import numpy as np
import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111, polar=True)

theta =[np.pi/3, np.pi/3]
theta2 =[np.pi/6, np.pi/6]

r = [0.0, 8.0e-04]
r2 = [0.0, 7.0e-04]
ax.plot(theta, r, 'r-', label ='Observed')
ax.plot(theta2, r2, 'b-', label ='Simulated')

ax.grid(True)

ax.legend(loc='upper center', bbox_to_anchor=(0.5, 1.25),
          ncol=3, fancybox=True, shadow=True)
plt.show()

1 个答案:

答案 0 :(得分:3)

对于指定径向刻度的位置,它非常简单 - 您只需设置rticks:

ax.set_rticks([0.0002, 0.0004, 0.0006, 0.0008])

格式化有两种选择,它取决于您希望如何显示标记。对于大小数字,默认格式化程序将自动切换为科学。如果你想改变它所考虑的阈值" small",你可以通过修改yaxis格式化器(y轴是径向轴)来做到这一点:

ax.yaxis.get_major_formatter().set_powerlimits((-3,4)) # Things smaller than 1e-3
                                                       # will be in scientific
                                                       # notation

然而,这对我来说看起来有点滑稽,它会把小小的" 1e-4"在情节的左上角。

因此,如果您想强制当前的径向刻度是科学记数,那么一种方法是使用您自己的格式。以下使用FormatStrFormatter

import matplotlib.ticker as ticker
# plotting code here
frmtr = ticker.FormatStrFormatter('%4.1e')
ax.yaxis.set_major_formatter(frmtr)

如果这不能完全符合您的要求,可以通过matplotlib.ticker提供大量选项。第二个格式化选项给我这个: outputplot

相关问题