![](/img/trans.png)
[英]Switch the values from x-axis to y-axis while using the correct labels(Python Matplotlib.pyplot OR Seaborn)
[英]How to create a grouped bar chart (by month and year) on the x-axis and values on the y-axis using matplotlib.pyplot?
与DataFrame.pivot
和DataFrame.plot.bar
一起使用:
df.pivot('Year','Month','Views').plot.bar()
如果需要月份名称,请在旋转后添加rename
:
month_dict = {1 : "January", 2 : "February", 3 : "March", 4 : "April",
5 : "May" , 6 : "June", 7 : "July", 8 : "August",
9 : "September", 10 : "October" ,11 : "November",12 : "December"}
df.pivot('Year','Month','Views').rename(columns=month_dict).plot.bar()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.