我试着用fill_between和熊猫系列的值,但它不起作用。'DAY'字段是字符串日期格式,类似于'%Y-%m-%d'。
df_tmp喜欢:
MEDIA_B2W MEDIA_CONC UPPER_BOUND LOWER_BOUND DAY
2017.48 2512.55 2811.0 1924.0 2017-01-01
1999.38 2512.55 2811.0 1924.0 2017-01-02
1930.89 2512.55 2811.0 1924.0 2017-01-03
df_tmp[['UPPER_BOUND','LOWER_BOUND','MEDIA_CONC','MEDIA_B2W','DAY']].plot(
x='DAY',ax=ax[0],grid=True,style=['r-','b-','y--','g-o'])
ax[0].fill_between(df_tmp.index,df_tmp['UPPER_BOUND'], df_tmp['LOWER_BOUND'],
facecolor='green', alpha=0.2, interpolate=True)我想在上下限之间着色。这是电流图
只有线条出现在情节里。
发布于 2017-04-28 20:46:54
这个解决方案使用df索引来表示x刻度,然后用掉期来表示时间序列。
df = df[['UPPER_BOUND','LOWER_BOUND','MEDIA_CONC','MEDIA_B2W','DAY']]
ax = df.plot(x=df.index, grid=True, style=['r-','b-','y--','g-o'])
ax.fill_between(df.index, df.LOWER_BOUND, df.UPPER_BOUND,
facecolor='green', alpha=0.2, interpolate=True)
# replace index values with dates
ax.set_xticks(df.index)
ax.set_xticklabels(df.DAY)
# cosmetic adjustments
pad = 700
ax.set_ylim([df.LOWER_BOUND.min()-pad, df.UPPER_BOUND.max()+pad])

或者,您可以将DAY设置为df.index
df.DAY = pd.to_datetime(df.DAY)
df = df.set_index('DAY')
ax = df.plot(grid=True, style=['r-','b-','y--','g-o'])
ax.fill_between(df.index, df.LOWER_BOUND, df.UPPER_BOUND,
facecolor='green', alpha=0.2, interpolate=True)
# cosmetic adjustments
pad = 700
_=ax.set_ylim([df.LOWER_BOUND.min()-pad, df.UPPER_BOUND.max()+pad])

https://stackoverflow.com/questions/43686022
复制相似问题