Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matplotlib set_rmax and set_rticks not working

I am using python3 in an anaconda jupyter notebook and am plotting graphs in polar coordinates. I want all the graphs to have the same rmax and rticks, but when I set them, they are not applied and the points aren't plotted correctly. Here is my code, without and then with them.

%pylab inline
X = asarray([[0.23, 0.73],[0.22, 1.16],[0.18, 1.86],[0.17, 2.39],[0.24, 2.74],[0.16, 3.43],[0.16, 3.87],[0.13, 4.39],[0.14, 5.00],[0.17, 5.53]])

ax0 = subplot(111, projection='polar')
ax0.plot(X[:,1], X[:,0], 'r+')
show()

ax1 = subplot(111, projection='polar')
ax1.set_rmax(0.8)
ax1.set_rticks([0.2, 0.4, 0.6, 0.8])
ax1.plot(X[:,1], X[:,0], 'r+')
show()

Here are the plots.

enter image description here enter image description here

like image 297
Shenan Avatar asked Sep 05 '25 22:09

Shenan


1 Answers

The problem is that you are first setting the rmax and then plotting your polar chart. So once you plot, the limits are automatically adjusted and your set rmax and rticks are overwritten.

The solution is to first plot and then set the rmax and rticks as shown below.

ax1 = plt.subplot(111, projection='polar')
ax1.plot(X[:,1], X[:,0], 'r+')
ax1.set_rmax(0.8)
ax1.set_rticks([0.2, 0.4, 0.6, 0.8])

enter image description here

like image 160
Sheldore Avatar answered Sep 08 '25 10:09

Sheldore