我可以给不同的月份上色吗? [英] Can I color different months?

查看:77
本文介绍了我可以给不同的月份上色吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据具有日期时间索引.我对数据进行了重新采样,并希望对其进行可视化处理,以使不同月份的颜色都不同.这是我的数据

My data has a datetime index. I've resampled the data and want to visualize it so that the different months all have a different color. Here is my data

Time        Count
2016-08-07  88
2016-08-14  95
2016-08-21  86
2016-08-28  81
2016-09-04  92
2016-09-11  89
2016-09-18  93
2016-09-25  83
2016-10-02  78
2016-10-09  90
2016-10-16  87
2016-10-23  79
2016-10-30  91
2016-11-06  90
2016-11-13  87
2016-11-20  97
2016-11-27  83
2016-12-04  63

如何绘制这些数据,以便每个月都有不同的颜色?

How can I plot this data so that each month has a different color?

推荐答案

根据对属于一个月的每个条形具有相同颜色的要求"的要求.您可以在下面的字典中将颜色更改为任意颜色,然后将这些颜色用于列表推导中.

As per request for "each bar belonging to a seperate month to have all the same color". You can change the colours to whatever you like in the dict below and these are then used in the list comprehension.

df['month'] = df.index.to_datetime().month

colors = {8: 'r', 9: 'b', 10: 'g',11: 'y', 12: 'w',}
df['Count'].plot(kind='bar', color=[colors[i] for i in df['month']])

这篇关于我可以给不同的月份上色吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆