首页 > 解决方案 > How to create a unstacked bar plot with dates in X axis?

问题描述

I'm trying to create an unstacked bar plot.

I had a lot of problems to extract the dates from the data frame to be able using the with major_locator, DayLocator, etc.

Important: Date start type is datetime64[ns]

I tried many options to unstack the bars but I wasn't able to fix it.

fig, ax = plt.subplots(1,1, figsize=(15,8))
fig.suptitle('ICP: Time standing', fontsize=25, fontweight='bold')

date_listdate_list = df[df['Container'] == 1]['Date start'].tolist()


ax.bar(date_list,df[df['Container'] == 1]['Aluminum (Al)\nppb'],width = 0.1)
ax.bar(date_list,df[df['Container'] == 1]['Barium (Ba)\nppb'],width = 0.1)


myFmtx = DateFormatter("%d/%m")
ax.xaxis.set_major_locator(mdates.DayLocator(interval=1))
ax.xaxis.set_major_formatter(myFmtx)
fig.autofmt_xdate()

output Graph

Dataframe

标签: pythonpandasdataframematplotlib

解决方案


推荐阅读