0

I'm doing a polar plot in matplotlib and I want to include a straight line that divides the circle in two. I have (removing the frames and the grids)

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)

If you see my attached image, the lines do not touch at the center. Is there any way to make them coincide at zero? (Surprisingly, I can use in radarr negative starting values like -0.7. This don't solves the problem either.) I have tried to adapt this answer but it does not work well. I suppose it has to be a more easier answer also. Matplotlib ver: matplotlib: 2.1.0

enter image description here

user2820579
  • 3,261
  • 7
  • 30
  • 45
  • 4
    Your problem is not reproducible. Are you running the latest matplotlib version? Are you making other changes to the plot (e.g. drawing at negative r-values)? It seems in your test, `rmin` isn't zero anymore. You can explicitly set `ax.set_rmin(0)` so the center of the plot has `r==0`. Note that default an axis with the r-values gets labeled ticks, which would help figure out their range (you can leave this on while testing and turn them off once everything is clear). – JohanC Jun 01 '21 at 14:17
  • 2
    Ah ok... it was the version problem. There's the code anyway, but I think I will close the question... – user2820579 Jun 01 '21 at 15:48
  • Nono, `radarr = np.full(100, 1.0)` so `radarr-0.4` is not negative (it's 0.6). It was the version issue... – user2820579 Jun 01 '21 at 15:50

1 Answers1

0

Try: ax.set_ylim(radarr.min(), radarr.max())

or specify a suitable range(the bottom limit and the top limit) by yourself,

such as:

ax.set_ylim(0., 1.47)