I am using GridSpec to create a grid of polar contour plots in matplotlib. To aid with the visuals, I am trying the customise the appearance of the contour plots. See this single polar plot as an example (MWE below)
I have two formatting questions in mind:
How can I customise the r axis to show only 0,20,40, and 60 values? How can I also make these numbers display in white?
When plotting multiple polar plots, I am choosing to remove the axes and ticks on the other by using
ax.grid(False)
,ax.set_xticklabels([])
, andax.set_yticklabels([])
. However a white bar along theta = 0 remains, which I would like to remove. See this image as an example of what I mean:
MWE
import matplotlib.pyplot as plt
import numpy as np
from matplotlib import gridspec
gs=gridspec.GridSpec(1,1)
gs.update(wspace=0.205, hspace=0.105)
fig=plt.figure(figsize=(500/72.27,450/72.27))
X = np.arange(0, 70, 10)
Y = np.radians(np.linspace(0, 360, 20))
r, theta = np.meshgrid(X,Y)
Z1 = np.random.random((Y.size, X.size))
ax=fig.add_subplot(gs[0,0], projection='polar')
cax=ax.contourf(theta, r, Z1, 10)
plt.show()
CodePudding user response:
For your first problem, just use the
Full code:
import matplotlib.pyplot as plt
import numpy as np
from matplotlib import gridspec
gs=gridspec.GridSpec(1,1)
gs.update(wspace=0.205, hspace=0.105)
fig=plt.figure(figsize=(500/72.27,450/72.27))
X = np.arange(0, 70, 10)
Y = np.radians(np.linspace(0, 360, 20))
r, theta = np.meshgrid(X,Y)
Z1 = np.random.random((Y.size, X.size))
ax=fig.add_subplot(gs[0,0], projection='polar')
cax=ax.contourf(theta, r, Z1, 10)
ax.set_rticks([0,20,40,60])
ax.tick_params(colors='white', axis="y", which='both')
plt.show()
Update: to have the ticks in a different colour, use what I mentioned in the comment:
colors = ['r', 'white', 'white', 'r']
for ytick, color in zip(ax.get_yticklabels(), colors):
ytick.set_color(color)