Skip to content

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

Closed

Description

@TerryGamon

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

Activity

  1. has2k1 commented on Jul 16, 2024

    @has2k1
    Owner

    Use axis_ticks_pad.

    The margin will work in some future version.

  2. added a commit that references this issue on Nov 13, 2024
    f27cbd3
  3. added a commit that references this issue on Jan 2, 2025
    e143853
  4. added a commit that references this issue on Mar 21, 2025
    4add1cb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions