Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotnine rotating labels

I was wondering how one rotates the x-labels, something in the lines of:

theme(axis.text.x = element_text(angle = 90, hjust = 1))

in ggplot?

Thank you.

like image 394
sdgaw erzswer Avatar asked Dec 08 '17 12:12

sdgaw erzswer


1 Answers

Plotnine is basically a clone of ggplot, you can call (almost) exactly that.

Here's an example :

import pandas as pd
from datetime import datetime, timedelta
from plotnine import ggplot, geom_point, aes, theme, element_text
now = datetime.now()
ago_28days = now - timedelta(days=28)
delta = now - ago_28days

timestamps = [ago_28days + timedelta(days=i) for i in range(delta.days)]
df = pd.DataFrame(data={'timestamp': timestamps, 'value':list(range(28))})

(ggplot(df) +
 geom_point(aes('timestamp', 'value')) +
 theme(axis_text_x=element_text(rotation=90, hjust=1))
)
like image 50
Keeler Avatar answered Nov 18 '22 07:11

Keeler