【发布时间】:2020-05-04 22:40:13
【问题描述】:
你好 Overstack 社区,
我是 Python 的初学者,我无法让我的情节的颜色与情节的颜色保持一致。
请在下面找到我编写的代码:-
merged_genres_mmd_plot.pivot_table(index='release_year', columns='genres', aggfunc='count').plot(figsize=(16,8))
plt.title('Popularity of Genre over the Years', fontsize=18)
plt.legend(['Action','Comedy','Drama','Horror','Western'])
plt.xlabel('Release Year',labelpad = 25)
plt.show()
This is the plot I am getting.
谁能帮我想出一种方法可以将图例的颜色与情节的颜色对齐?
提前感谢您!
【问题讨论】:
-
如果你忽略了
plt.legend()电话,它不就行了吗? -
嗨,我需要自定义设置图例,因为我使用的是数据透视表,而另一列的“名称”会扭曲图例。我得到类似 ---revenue,Action
标签: python matplotlib legend mismatch