【问题标题】:Set radial axis on Matplotlib polar plots在 Matplotlib 极坐标图上设置径向轴
【发布时间】:2012-08-22 14:08:33
【问题描述】:

我正在极坐标图上绘制方位角-仰角曲线,其中仰角是径向分量。默认情况下,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()

由此产生的情节是

【问题讨论】:

  • 你已经有什么代码了?这可能对回答您的问题有很大帮助(尤其是第二部分)。
  • 我想这可以通过反转径向坐标的映射函数和手动设置径向标签来完成。这是否足够,或者您真的想重新定义径向轴?

标签: python matplotlib


【解决方案1】:

我设法把他的径向轴倒置了。我不得不重新映射半径,以匹配新轴:

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

请注意,这只是一个 hack,轴仍然是 0 在中心和 90 在周边。您必须对正在绘制的所有变量使用映射函数。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-22
    • 2010-09-18
    • 1970-01-01
    • 2022-10-13
    • 1970-01-01
    • 2014-03-13
    • 2019-08-25
    • 1970-01-01
    相关资源
    最近更新 更多