Plotnine rotating labels

Question:

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.

Asked By: sdgaw erzswer

||

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))
)
Answered By: Keeler
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.