0

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)

polar contour plot

I have two formatting questions in mind:

  1. 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?

  2. 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([]), and ax.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: enter image description here

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()
Sid
  • 266
  • 5
  • 13

1 Answers1

0

For your first problem, just use the rticks from matplotlib (check out the demo too:

ax.set_rticks([0,20,40,60])
ax.tick_params(colors='white', axis="y", which='both') 

enter image description here

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)

Source: matplotlib different colors for each axis label, Set color for xticklabels individually in matplotlib

enter image description here

My Work
  • 2,143
  • 2
  • 19
  • 47
  • Is it possible to have some of the rtick values a different colour. I.e. notice how 0 is not very visible, is it possible to have just in red colour, while the others are white? – Sid Dec 12 '21 at 18:00
  • @Sid, does this https://stackoverflow.com/questions/24617429/matplotlib-different-colors-for-each-axis-label/24617650 or this https://stackoverflow.com/questions/21936014/set-color-for-xticklabels-individually-in-matplotlib help you? – My Work Dec 12 '21 at 18:18
  • Yes, that does help thanks for posting the links! – Sid Dec 12 '21 at 22:06
  • @Sid I also updated the answer – My Work Dec 13 '21 at 07:09