在Matplotlib极坐标图中设置径向轴

6
我正在极坐标图上绘制方位角-俯仰角曲线,其中俯仰角是径向分量。默认情况下,Matplotlib将径向值从中心0绘制到周长90。我希望相反,即90度在中心。我尝试使用ax.set_ylim(90,0)调用设置限制,但这会导致抛出LinAlgError异常。ax是从add_axes调用中获取的轴对象。 是否可以做到这一点,如果可以,我需要做什么? 编辑:这是我现在正在使用的。基本绘图代码取自Matplotlib示例之一。
# radar green, solid grid lines
rc('grid', color='#316931', linewidth=1, linestyle='-')
rc('xtick', labelsize=10)
rc('ytick', labelsize=10)

# force square figure and square axes looks better for polar, IMO
width, height = matplotlib.rcParams['figure.figsize']
size = min(width, height)
# make a square figure
fig = figure(figsize=(size, size))
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], projection='polar', axisbg='#d5de9c')

# Adjust radius so it goes 90 at the center to 0 at the perimeter (doesn't work)
#ax.set_ylim(90, 0)

# Rotate plot so 0 degrees is due north, 180 is due south

ax.set_theta_zero_location("N")

obs.date = datetime.datetime.utcnow()
az,el = azel_calc(obs, ephem.Sun())
ax.plot(az, el, color='#ee8d18', lw=3)
obs.date = datetime.datetime.utcnow()
az,el = azel_calc(obs, ephem.Moon())
ax.plot(az, el, color='#bf7033', lw=3)

ax.set_rmax(90.)
grid(True)

ax.set_title("Solar Az-El Plot", fontsize=10)
show()

这导致的结果是一个图表: enter image description here

你已经有哪些代码了?这可能会极大地帮助回答你的问题(特别是第二部分)。 - user707650
我想这可以通过一个映射函数来完成,反转径向坐标并手动设置径向标签。这样足够了吗?还是你真的想重新定义径向轴? - Pablo Navarro
1个回答

4

我成功地将径向轴反转了。为了匹配新的轴,我不得不重新映射半径:

fig = figure()
ax = fig.add_subplot(1, 1, 1, polar=True)

def mapr(r):
   """Remap the radial axis."""
   return 90 - r

r = np.arange(0, 90, 0.01)
theta = 2 * np.pi * r / 90

ax.plot(theta, mapr(r))
ax.set_yticks(range(0, 90, 10))                   # Define the yticks
ax.set_yticklabels(map(str, range(90, 0, -10)))   # Change the labels

请注意,这只是一种技巧,轴仍然以中心的0和周边的90为基准。您将需要使用映射函数来绘制所有变量。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接