我在格式化极坐标图theta网格时遇到一些麻烦。最外面的圆圈似乎比其他圆圈更细,有什么办法可以纠正它?我注意到删除set_rmax可以解决此问题,但会导致半径网格线超出圆的范围-我不想要它。下面的代码示例。
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.add_axes([0, .15, 1, .75],
frameon=False,
projection='polar',
rlabel_position=22.5,
theta_offset=(-np.pi / 2))
theta = list(map(lambda x: x * np.pi / 180,
[i for i in range(0, 360, 15)]))
values = [i for i in range(0, 24)]
values2 = [i for i in range(24, 0, -1)]
ax.plot(theta, values, label='zzz')
ax.plot(theta, values2, label='xxx')
ax.set_rticks([i * 24 / 4 for i in range(0, 5)])
ax.set_yticklabels([])
ax.set_thetagrids(angles=[0, 30, 60, 90, 120, 150, 180,
210, 240, 270, 300, 330],
labels=list(map(lambda x: str(x)
+ u'\N{DEGREE SIGN}',
[0, 30, 60, 90, 120, 150, 180])))
fig.legend(frameon=False,
loc='lower left',
ncol=1)
ax.set_rmax(24)
plt.show()
答案 0 :(得分:1)
您关闭了极坐标图的框。因此,甚至没有显示出最外圈。再次打开框架,然后将外圆的颜色设置为灰色,即可获得理想的效果。
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.add_axes([0, .15, 1, .75],
frameon=True,
projection='polar',
rlabel_position=22.5,
theta_offset=(-np.pi / 2))
theta = list(map(lambda x: x * np.pi / 180,
[i for i in range(0, 360, 15)]))
values = [i for i in range(0, 24)]
values2 = [i for i in range(24, 0, -1)]
ax.plot(theta, values, label='zzz')
ax.plot(theta, values2, label='xxx')
ax.set_rticks([i * 24 / 4. for i in range(0, 5)])
ax.set_yticklabels([])
ax.set_thetagrids(angles=[0, 30, 60, 90, 120, 150, 180,
210, 240, 270, 300, 330],
labels=list(map(lambda x: str(x)
+ u'\N{DEGREE SIGN}',
[0, 30, 60, 90, 120, 150, 180])))
fig.legend(frameon=False,
loc='lower left',
ncol=1)
ax.set_rmax(24)
ax.spines["polar"].set_color(plt.rcParams["grid.color"])
ax.spines["polar"].set_linewidth(plt.rcParams["grid.linewidth"])
plt.show()