3

I need to format dates on a x-axis ggplot for python bar chart.

How can I do it?

Wilduck
  • 13,822
  • 10
  • 58
  • 90
Hugo
  • 1,558
  • 12
  • 35
  • 68

1 Answers1

1

Use scale_x_date() to format dates on the x-axis.

p = ggplot(aes(x='date'), data) + geom_bar() + scale_x_date(labels='%m-%Y')

This gives number of month and the year, for example, 01-1990 You can try other formats.

  • Does anyone know a good resource URL to look up the different formats available? I am trying to work with dates that represent daily data and I think I want x to plot the points for each day. This URL has a few examples but not what I am looking for: http://blog.yhat.com/posts/ggplot-for-python.html – TMWP Apr 05 '17 at 22:38