3

The DataFrame data, where date is an index look like:

date        count   
2017-03-20  119
2017-03-29  100
2017-04-03  118
2017-04-10  113

date(index) has a format datetime64[ns].

When i try to plot it with

p = data.plot(kind="bar"),

it adds hours:minuts:seconds to the axis values(to dates). So, when i save it with

fig = p.get_figure()
fig.savefig('figure.jpeg'),

The frame cuts off days,month,yeear and leaves only zeros from minuts,seconds...

cs95
  • 379,657
  • 97
  • 704
  • 746
Ladenkov Vladislav
  • 1,247
  • 2
  • 21
  • 45

1 Answers1

3

You can use strftime + tight_layout:

import matplotlib.ticker as ticker
import matplotlib.pyplot as plt

ticklabels = data.index.strftime('%Y-%m-%d')
ax = data.plot(kind="bar")
plt.tight_layout()
ax.xaxis.set_major_formatter(ticker.FixedFormatter(ticklabels))
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252