我创建了一个函数来生成蜘蛛/雷达图,但遇到了一个错误。你知道吗
这句话给我添麻烦了:
ax.set_thetagrids(angles * 180/np.pi, labels = labels, color='blue', frac=1.5)
根据文献记载,“frac是极轴半径的一部分 放置标签(1是边缘)。e、 g.轴外为1.05 轴内为0.95。”
但是,即使我设置frac=1.5,标签仍然与绘图本身重叠。 This is an example of a plot
=======================================================================================
以下是整个函数定义:
import matplotlib.pyplot as plt
import numpy as np
def make_radar_chart(name, stats, labels, plot_markers = markers, plot_str_markers = str_markers):
markers = [1,2, 3, 4, 5, 6, 7, 8, 9, 10]
str_markers = ["",'', "", '', "", '', "", "", "", '']
labels = np.array(labels)
angles = np.linspace(0, 2*np.pi, len(labels), endpoint=False)
stats = np.concatenate((stats,[stats[0]]))
angles = np.concatenate((angles,[angles[0]]))
fig= plt.figure()
ax = fig.add_subplot(111, polar=True)
ax.plot(angles, stats, 'green', linewidth=1)
ax.fill(angles, stats, 'green', alpha=0.25)
ax.set_thetagrids(angles * 180/np.pi, labels = labels, color='blue', frac=1.5)
plt.yticks(markers)
plt.yticks([1,2,3,4,5,6,7,8,9], ["",'','3','',"5","",'7','',''], color="grey", size=7)
ax.set_title(name)
ax.grid(True)
return plt.show()
看看What's new in matplotlib 2.1上面写着:
相关问题 更多 >
编程相关推荐