繁体   English   中英

将径向轴标签放在极坐标图matplotlib的行的前面

[英]Bring radial axes labels in front of lines of polar plot matplotlib

我正在尝试在极坐标图上获取径向(或y轴)标签,使其位于图形上绘制的线的顶部。 现在,它们位于线下并被掩盖。

在此处输入图片说明

这是仅一个城市和一行的代码的简化版本:

fig, ax = plt.subplots(figsize=(10,6) , nrows=1, ncols=1,subplot_kw=dict(projection='polar'))
rmax = 15
rticks = np.arange(9,rmax,1.5)
rticklabel = np.arange(18,rmax*2,3).astype(int)

theta = np.arange(0,6.3, 0.17) #plots a circle
r = np.ones(len(theta))*(21/2)
ax.plot(theta, r,c='r', linestyle='-',linewidth = 4,zorder=1)

ax.set_rmax(rmax)
ax.set_rticks(rticks)  # less radial ticks

ax.set_xticklabels([])  
ax.set_rlabel_position(285)  # get radial labels away from plotted line
ax.grid(True)

ax.set_facecolor('white') 
ax.yaxis.grid(color='silver', linestyle=':',linewidth = 1.5,zorder=10)
ax.set_yticklabels(rticklabel,fontsize=12,zorder=10) #this zorder does nothing

我已经尝试过了:

plt.rcParams["axes.axisbelow"] = False

如我所愿,这将文本放在最前面,但是,它也带来了网格线。 我希望那些人留在彩色线后面。

我也尝试过更改yaxis网格的zorder,但这不起作用。

多数解决方案不适用于极轴。 有什么建议么?

不幸的是,网格和标签的zorder似乎与轴的zorder绑定在一起: https ://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.grid.html

即使不是很优雅,一种可能的解决方案是自己绘制网格线

fig, ax = plt.subplots(figsize=(10,6) , nrows=1, ncols=1,subplot_kw=dict(projection='polar'))
rmax = 15
rticks = np.arange(9,rmax,1.5)
rticklabel = np.arange(18,rmax*2,3).astype(int)

theta = np.arange(0,6.3, 0.17) #plots a circle
r = np.ones(len(theta))*(21/2)
ax.plot(theta, r,c='r', linestyle='-',linewidth = 4,zorder=2)

ax.set_rticks(rticks)  # less radial ticks

ax.set_xticklabels([])  
ax.set_rlabel_position(285)  # get radial labels away from plotted line
ax.xaxis.grid(True)
ax.yaxis.grid(False)

ax.set_facecolor('white') 
ax.set_yticklabels(rticklabel,fontsize=12,zorder=10) #this zorder does nothing
ax.yaxis.set_zorder(10)
#ax.yaxis.grid(color='silver', linestyle=':',linewidth = 1.5,zorder=10)

x = np.arange(0,2*np.pi,0.05)
y = np.outer( np.ones(x.shape), rticks)
ax.plot( x,y, zorder=1, color='silver', linestyle=':')
ax.set_ylim(0,rmax)

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM