我已经绘制了数据,但图例颜色与图形不同。
for row in Survey2.values.tolist():
values = row[1:] + [row[1]]
plt.polar(angles, values, 'o-', linewidth=0.5, label=row[0])
plt.fill(angles, values, alpha=0.25)
# Representation of the spider graph
plt.legend(Survey2["createdAt"],
loc=4,
fontsize=7)
plt.title('PHQ-9,GAD-7 and Likert Scale over the study period', size=12, y=1.07)
plt.thetagrids(angles * 180 / np.pi, labels)
plt.figure(figsize=(10, 10))
plt.show()
1条答案
按热度按时间k97glaaz1#
每行绘制两个元素:
plt.polar(...
点plt.fill(...
阴影因此,添加图例时,每行数据将获得两项:一个是点,一个是填充。图例是和你的图一样的颜色。图例只有3个条目,但是有6条曲线
您可以通过将
label='_nolegend_'
添加到plt.fill(
来避免这种情况,如以下类似问题所示:Show only certain items in legend Python Matplotlib另外,如果在创建曲线时添加了标签(使用
label=row[0]
),为什么在创建图例时添加新标签Survey2["createdAt"]
?这将覆盖之前给出的标签