简体   繁体   中英

Customise polar contour plot axes style

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:

  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: 在此处输入图像描述

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()

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') 

在此处输入图像描述

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM