0

I'm trying to make a bar plot with matplotlib

  • I want the bars to be unstacked.
  • I want my x-axis to be a date axis. in order to treat him with DayLocator, DateFormatter, etc.

When I'm trying to change the X-axis to dated and customize him - it disappears

index=pd.Series(df[df['Container'] == 1]['Date start']).count()
index = int(index)
height =  np.arange(index)

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

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

#dates = pd.date_range(start='29/6/2019', end='01/08/2019')

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

Output Graph

enter image description here

Ravi B
  • 1,574
  • 2
  • 14
  • 31
  • `height` is the index. So `plt.bar(height, ...)` will plot the index. You can plot something else by using `plt.bar(something, ...)` – ImportanceOfBeingErnest Aug 09 '19 at 14:02
  • @ImportanceOfBeingErnest my goal is to wright the bars, side by side at the x-axis. (the x-axis is dates). I'm adding a link with my code. I'm not able to plot the bars side by side, so that's the reason that I plotted index at the serial the x-axis (and after that, I tried to change it to dates). the link: https://stackoverflow.com/questions/57428330/how-to-create-a-unstacked-bar-plot-with-dates-in-x-axis do you have a solution? – Offir Inbar Aug 10 '19 at 19:39

0 Answers0