Plotnine rotating labels
Asked Answered
O

1

17

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.

Ophir answered 8/12, 2017 at 12:34 Comment(0)
N
27

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))
)
Nudism answered 23/12, 2017 at 21:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.