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
  • 330,695
  • 80
  • 606
  • 657
Ladenkov Vladislav
  • 1,156
  • 1
  • 18
  • 40

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
  • 729,927
  • 78
  • 1,141
  • 1,090