如何从修补程序中删除未添加的datetime p

2024-03-29 11:30:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用bokeh补丁绘制我的能量数据。它成功地运行了默认的时间序列。但如果我选择不同的两个日期,那么它会合并两个日期范围

示例: 日期范围:29/07/2018 - 31/07/2018 with hours

Successfull working example of result is here

日期:30/07/2018 and 06/08/2018 with hours

Wrongly working example of result is here

所以我尝试了thispost,但没有任何改变

和代码块:

df = generateRtpDataFrame(data_list,frekans)
df=df.round(2)
def stacked(df):
    df=df[df.columns[::-1]]
    df_top = df.cumsum(axis=1)     
    df_bottom = df_top.shift(axis=1).fillna({'total': 0})[::-1]        
    df_stack = pd.concat([df_bottom, df_top], ignore_index=False)
    df_stack=df_stack.drop("total", axis=1)
    return df_stack
areas = stacked(df)
colors = d3['Category20b'][areas.shape[1]]

x2 = np.hstack((df.index[::-1], df.index))   
msg = "Example Plot"     
caption = Title(text=msg, align='left', text_font_size='10pt')
tooltips=[
    ("index", "$index"),          
]
p = figure(sizing_mode = 'scale_width',tooltips=tooltips,x_axis_type='datetime')           
p.add_layout(caption, 'above')    
p.grid.minor_grid_line_color = '#eeeeee'
p.xaxis.formatter=DatetimeTickFormatter(
    minutes=["%M"],
    hours=["%H:%M"],
    days=["%d/%m/%Y"],
    months=["%m/%Y"],
    years=["%Y"],
)

p.xaxis.major_label_overrides = {
    i: date.strftime('%Y-%m-%d %H:%M') for i, date in enumerate(pd.to_datetime(df.index))
}        
p.patches(xs=[x2]*areas.shape[1],ys= [areas[c].values for c in areas], color=colors, alpha=0.8,line_color=None)

Tags: ofdfindexisstackexampletopwith