如何在极坐标图中使用颜色条?

时间:2019-04-08 09:44:51

标签: python matplotlib colorbar

我正在尝试在极坐标图中使用颜色条。我没明白这是我的简单极坐标图代码。

import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt

fig, ax = plt.subplots()

y2 = [96.31883883883884, 105.53807807807806, 96.4374174174175, 94.50975975975975, 82.67206206206207, 125.8472472472473, 126.62304304304303, 124.98103103103091, 117.13329329329326, 109.36357357357365, 107.02209209209208, 117.19069069069054, 96.31883883883884]
y3 = [242.29120120120174, 227.6075375375375, 220.69459459459455, 222.21662324649296, 225.59189189189183, 218.9322422422421, 219.08093093093117, 226.80649649649635, 229.3265965965969, 201.60476476476458, 196.92468468468442, 190.94575575575595, 242.29120120120174]
y4 = [31.625100401606428, 36.0695295295295, 35.989519038076125, 38.314428857715434, 40.236536536536505, 67.78894894894894, 68.63077077077074, 64.99336336336333, 63.45824824824829, 63.41446446446452, 61.0178978978978, 63.99864864864866, 31.625100401606428]

z = np.arange(0, 13)
theta1 = (2*np.pi/12)*z
ax1 = fig.add_axes([0.42, 0.36, 0.18, 0.30], polar=True, axisbg='white')
ax1.plot(theta1, y2, color='black', lw=2)       
ax1.plot(theta1, y3, color='blue', lw=2)        
ax1.plot(theta1, y4, color='green', lw=2)

ax1.set_rmax(500)

ax1.set_theta_zero_location('N')
ax1.set_xticklabels(['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW'], color='red')
plt.show()

1 个答案:

答案 0 :(得分:0)

该想法是创建数据的pcolormesh图。为此,首先需要定义theta和r的坐标数组。

import numpy as np
import matplotlib.pyplot as plt

y2 = [96.31883883883884, 105.53807807807806, 96.4374174174175, 94.50975975975975, 82.67206206206207, 125.8472472472473, 126.62304304304303, 124.98103103103091, 117.13329329329326, 109.36357357357365, 107.02209209209208, 117.19069069069054, 96.31883883883884]
y3 = [242.29120120120174, 227.6075375375375, 220.69459459459455, 222.21662324649296, 225.59189189189183, 218.9322422422421, 219.08093093093117, 226.80649649649635, 229.3265965965969, 201.60476476476458, 196.92468468468442, 190.94575575575595, 242.29120120120174]
y4 = [31.625100401606428, 36.0695295295295, 35.989519038076125, 38.314428857715434, 40.236536536536505, 67.78894894894894, 68.63077077077074, 64.99336336336333, 63.45824824824829, 63.41446446446452, 61.0178978978978, 63.99864864864866, 31.625100401606428]

theta = np.linspace(0, 2*np.pi, len(y2))
r = [1,2,3,4]

z = [y2,y3,y4]

fig=plt.figure()
ax = fig.add_subplot(111, polar=True)

pc = ax.pcolormesh(theta, r, z)

fig.colorbar(pc)

ax.set_theta_zero_location('N')
ax.set_xticklabels(['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW'], color='red')
plt.show()

enter image description here