has2k1 / plotnine

A Grammar of Graphics for Python
https://plotnine.org
MIT License
4.06k stars 225 forks source link

axis_text_x=p9.element_text(margin=...) has no effect #843

Open TerryGamon opened 4 months ago

TerryGamon commented 4 months ago

I want to add space between the x-axis labels and the x-axis. But element_text(margin =) seems to be ignored?

First:

import plotnine as p9
from plotnine.data import mtcars
mtcars=mtcars.head(5)
(p9.ggplot(mtcars)
+ p9.geom_col(p9.aes(x='name',y='mpg'))
+ p9.labs(x='')
)

image

So far so good. Now add space:

(p9.ggplot(mtcars)
+ p9.geom_col(p9.aes(x='name',y='mpg'))
+ p9.labs(x='')
+ p9.theme(axis_text_x=p9.element_text(margin={'t': 40, 'units':'pt'}))  
)

nothing changes

image

just to clarify what I want to achive, here the ggplot dplyr code:

library(tidyverse)

mtcars = as_tibble(mtcars,rownames = "name")
mtcars = mtcars |> head(5)

ggplot(mtcars) +
  geom_col(aes(x=name,y=mpg))+
  labs(x='')+
  theme(axis.text.x = element_text(margin = margin(10)))

image

has2k1 commented 4 months ago

Use axis_ticks_pad.

The margin will work in some future version.