首页 > 解决方案 > 极坐标图matplotlib中的直线不接触

问题描述

我在 matplotlib 中做一个极坐标图,我想包括一条将圆一分为二的直线。我有(移除框架和网格)

ax = plt.subplot(projection='polar')
theta = [0.0, 2*np.pi/6, 4*np.pi/6, 6*np.pi/6, 8*np.pi/6, 10*np.pi/6]
thetarr = np.linspace(0,2.0*np.pi,100)
radarr = np.full(100, 1.0)

ax.plot(thetarr, radarr, linestyle='-', marker='', color='gray')
ax.plot(thetarr, radarr-0.4, linestyle='-', marker='', color='gray')
ax.plot(thetarr, radarr+0.4, linestyle='-', marker='', color='gray')
thetarr = np.full(50,5*np.pi/6)
radarr = np.linspace(0.0,1.4,50)
ax.plot(thetarr, radarr, linestyle='-', color='gray')
thetarr = np.full(50,11*np.pi/6)
ax.plot(thetarr, radarr, linestyle='-', color='gray')

plt.text(5*np.pi/6+0.02, 1.7, r'$J_{\theta}$', color='blue', fontsize=18)

ax.grid(False)
plt.yticks([0.4,0.85,1.3], ['-0.4','0','0.4'])
ax.set_rlabel_position(142)
theta = [0.0, 2*np.pi/6, 4*np.pi/6, 6*np.pi/6, 8*np.pi/6, 10*np.pi/6]
plt.xticks(theta, ['1', '2', '3', '4', '5', '6'], color='blue')
ax.get_xticklabels()[0].set_color("red")
ax.get_xticklabels()[3].set_color("red")
ax.spines['polar'].set_visible(False)

如果您看到我附加的图像,则线条不会在中心接触。有没有办法让它们在零处重合?(令人惊讶的是,我可以使用radarr 负的起始值,例如 -0.7。这也不能解决问题。)我试图调整这个答案,但效果不佳。我想它也必须是一个更容易的答案。Matplotlib 版本:matplotlib: 2.1.0

在此处输入图像描述

标签: pythonmatplotlib

解决方案


推荐阅读