1

I'm calculating the daily mean with the standard deviation as a bar plot. My dataframe looks like this:

                Ozone
2014-06-10  41.958586
2014-06-11  32.747222
2014-06-12  35.781250
2014-06-13  28.623264
2014-06-14  31.160764
2014-06-15  30.494444
2014-06-16  35.666667

[7 rows x 1 columns]

As you can see, the indexing row is nicely truncated to daily dates. When I try to plot this in a bar plot however, each of the seven bars has the full date followed by '00:00:00' underneath. This is probably matplotlib trying to be smart, but I can't figure out how to format the index so that only the daily date shows instead.

It looks like this:

2014-06-13 00:00:00

Do you have any suggestions on how to change this?

veor
  • 993
  • 2
  • 8
  • 17
  • See related: http://stackoverflow.com/questions/23088241/formatting-datetime-xlabels-in-matplotlib-pandas-df-plot-method – EdChum Jun 17 '14 at 09:27
  • I can create labels with this: `formatted_ticks = df.index.map(lambda t: t.strftime('%y-%m-%d %a')) print formatted_ticks` which gives the formatting I want. However, I can't call on the plot to change the settings. The plot is created like this: `plot = mean.plot(legend = False, figsize=(20,10), kind = 'bar', yerr = std.Ozone, error_kw=dict(ecolor='black', lw=2, capsize=5, capthick=2)) fig = plot.get_figure() plt.ylabel('Mean ozone (ppb)') plt.tight_layout()` – veor Jun 17 '14 at 09:35

2 Answers2

2

One possiblity is that as Pandas/Matplotlib is taking the dates as datetime values if you convert them to strings then you can control the format by using the datetime.strftime method.

Steve Barnes
  • 27,618
  • 6
  • 63
  • 73
2

Doing this:

formatted_ticks = mean.index.map(lambda t: t.strftime('%y-%m-%d %a'))
plot.set_xticklabels(formatted_ticks)

Worked just fine. Thanks!

veor
  • 993
  • 2
  • 8
  • 17