Hello 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.
有人可以帮助我找出一种使图例的颜色与图的颜色对齐的方法吗?
预先感谢您!
答案 0 :(得分:0)
您的问题有几个答案,我认为最好的答案是:
使用您拥有的数据,您可以选择x和y轴是什么,使用pl.plot()您可以绘制所有具有的曲线并定义其标签,例如:
plt.plot(x, y, label = 'Action')
plt.plot(x, y, label = 'Comedy')
.
.
.
plt.legend()
plt.show()