Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The most elegant way to modify messy and overlapping date labels below x axis? (Seaborn, barplot)

df (Pandas DataFrame) has two columns: Date (as datetime64) and Amount (as float).

I plot the values from Amount column against time, using barplot:

sns.barplot(x="Date", y="Amount", data=df)
plt.show()

However, the date labels are a terrible mess (see picture). What would be an elegant way of dealing with this in Pandas? I'm considering removing month and year from the label, or rotating the labels 90 degrees. How would these be done, or is there a better option? Thank you.

Overlapping date labels on x axis

like image 977
KMFR Avatar asked Nov 28 '18 21:11

KMFR


1 Answers

This automatically adjusts SNS plot's date x axis so you don't have to manually do this in most cases: sns_plot.get_figure().autofmt_xdate()

like image 58
Tagar Avatar answered Sep 28 '22 09:09

Tagar