from plotnine import *
from plotnine.data import economics
= ggplot(economics, aes("date", "psavert")) + geom_line() p
Scale x and y
- continuous
- discrete
- date, datetime, timedelta
- log10, sqrt, symlog
- reverse
Common formatting:
- percentages
- dates
Full example
from mizani.labels import percent_format
("date", "psavert"))
ggplot(economics, aes(+ geom_line()
+ labs(title="")
+ scale_y_continuous(
="Personal savings rate",
name=[0, None],
limits=percent_format(scale=1),
labels
)+ scale_x_date(
="Date",
name="10 years",
date_breaks="5 year",
date_minor_breaks
) )
Expanding limits to include zero
+ scale_y_continuous(limits=[0, None]) p
Labelling percentages
("date", "psavert"))
ggplot(economics, aes(+ geom_line()
+ scale_y_continuous(labels=lambda arr: [f"{x}%" for x in arr])
)
from mizani.labels import percent_format
("date", "psavert"))
ggplot(economics, aes(+ geom_line()
+ scale_y_continuous(labels=percent_format(scale=1))
)
Specifying date breaks
("date", "psavert"))
ggplot(economics, aes(+ geom_line()
+ scale_x_date(date_breaks="10 years", date_minor_breaks="5 year")
)
Applying log scale
= ggplot(economics, aes("date", "pce")) + geom_line()
p
p+ scale_y_log10() p