Python以颜色绘制365天的年度数据
下面给出了我的原始数据帧的示例数据。原始数据框架有20年的数据Python以颜色绘制365天的年度数据,python,dataframe,matplotlib,Python,Dataframe,Matplotlib,下面给出了我的原始数据帧的示例数据。原始数据框架有20年的数据 input_df = Datetime Data 2000-05-31 0.000 2000-06-20 8.204 2000-06-21 7.724 2000-06-22 7.268 2000-06-23 3.687 2017-01-03 2.718 2017-01-04 3.11
input_df =
Datetime Data
2000-05-31 0.000
2000-06-20 8.204
2000-06-21 7.724
2000-06-22 7.268
2000-06-23 3.687
2017-01-03 2.718
2017-01-04 3.113
2017-01-05 3.841
2017-01-06 4.135
2017-01-07 0.819
2017-01-08 3.537
2017-01-09 3.471
我想画出上面的数据,这样我想得到下面的图,表示一年数据的一种颜色和标记
我试着用我的方法解决,但没有成功。
我的解决方案:
year_group = input_df.groupby(pd.Grouper(freq='A'),axis=1)
years = pd.DataFrame()
for name, group in year_group:
years[name.year] = group.values
years.plot(subplots=True, legend=False)
pyplot.show()
像这样的
# dummy data
dti = pd.date_range('2000-01-01', periods=20*12, freq='M')
df = pd.DataFrame(np.random.random(size=(20*12,)), index=dti, columns=['value'])
import itertools
marker = itertools.cycle(['.', ',', 'o', 'v', '^', '<', '>', '1', '2', '3', '4', '8', 's', 'p', '*', 'h', 'H', '+', 'x', 'D', 'd', '|', '_', 'P', 'X'])
for y in range(2000,2020):
temp = df.loc[df.index.year==y]
plt.plot(temp.index.dayofyear, temp.value, label=y, marker=next(marker))
plt.legend()
我实施了你的方法。出现以下错误:返回对象。\u getattribute\u self,name AttributeError:'DataFrame'对象没有属性'value'