Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I format the x-axis on Python Ggplot?

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

How can I do it?

like image 884
Hugo Avatar asked Feb 03 '26 05:02

Hugo


1 Answers

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.