Unexpected behavior when rotating x-axis text
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- Medio día
- Aptitud para principiantes
- 55/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- matplotlib, python
- Área
- data-visualization
Línea de trabajo
Start by reading the axis text positioning and rotation code in plotnine, then check how element_text passes alignment and rotation_mode to Matplotlib. Reproduce the reported combinations from the issue with the supplied example and compare label anchors against tick positions. Done means the rotated labels can be aligned as described without shifting too far left or down.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
First off, I'm really grateful for plotnine because for a long time, my biggest complaint with python was not having a good implementation of the grammar of graphics like R's ggplot2. In my opinion, plotnine has filled that space beautifully. That being said, I'm currently struggling with positioning tick labels on a plot I'm working on. Here's a small example to illustrate the issue I'm having:
With default parameters, everything looks as expected:
import plotnine as pn
import polars as pl
data = pl.DataFrame(
{
"x": ["aaaaa", "bbbbb", "ccccc"],
"y": [1, 1, 1]
}
)
plot = (
pn.ggplot(data, pn.aes("x", "y"))
+ pn.geom_point()
)
Output:
I can then rotate the x-axis labels just fine:
plot = (
pn.ggplot(data, pn.aes("x", "y"))
+ pn.geom_point()
+ pn.theme(
axis_text_x=pn.element_text(rotation=45)
)
)
Output:
What I'd like to achieve is shift the rotated x-axis labels to the left such that the end of the label falls directly below the corresponding tick mark. I first tried setting ha="right" but this moved the labels too far (i.e., if you trace along the center axis of the letters in each label, you get to the end of the label before you reach the x-position of the tick):
plot = (
pn.ggplot(data, pn.aes("x", "y"))
+ pn.geom_point()
+ pn.theme(
axis_text_x=pn.element_text(rotation=45, ha="right")
)
)
Output:
I figure that what I'm going for is anchoring the center-right point of the label to a point just below the tick, and then rotating around that anchor. If I set ha="right" and va="center" without rotating, it appears that the anchor point is in the correct location (i.e., directly below the tick):
plot = (
pn.ggplot(data, pn.aes("x", "y"))
+ pn.geom_point()
+ pn.theme(
axis_text_x=pn.element_text(ha="right", va="center")
)
)
Output:
But then when I rotate, it does not appear to be rotating around that anchor point. Instead the labels shift way down and also still end up positioned too far to the left:
plot = (
pn.ggplot(data, pn.aes("x", "y"))
+ pn.geom_point()
+ pn.theme(
axis_text_x=pn.element_text(rotation=45, ha="right", va="center", rotation_mode="anchor")
)
)
Output:
I've also tried lots of other combinations of values for ha, va, and rotation_mode, but can't seem to get the labels in the right position. Any help would be appreciated.
- Plotnine version: 0.15.8
- Matplotlib version: 3.11.1
- Python version: 3.11.14
- Lenguaje dominante
- Python
- Estrellas
- 4.8k
- Forks
- 260
- Merge medio
- 2 d 12 h
- PR fusionados (30 d)
- 4
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de has2k1/plotnine
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
Los mantenedores suelen responder en 1 día
-
Enhancement
Dificultad 4/5 3-5 días Aptitud para principiantes 52/100
has2k1/plotnine#1081 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
-
Discussion
Dificultad 5/5 Más de una semana Aptitud para principiantes 30/100
has2k1/plotnine#1047 · 15 comentarios · 3 reacciones ·
Los mantenedores suelen responder en 1 día
-
Documentation Plot Composition Question
Dificultad 3/5 1-2 días Aptitud para principiantes 45/100
has2k1/plotnine#1036 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
plotnine 0.16.0 alpha releasesAbiertoInstallation Plot Composition
Dificultad 1/5 Menos de una hora Aptitud para principiantes 20/100
has2k1/plotnine#1031 · 11 reacciones ·
Los mantenedores suelen responder en 1 día
Todos los issues de has2k1/plotnine
Issues similares
-
bug triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
mealie-recipes/mealie#9117 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
freelawproject/courtlistener#8406 ·
Los mantenedores suelen responder en 2 días
-
good first issue help wanted level 1 wocs
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
GianlucaBave/murmury#49 ·
Los mantenedores suelen responder en 1 día
-
regression skipped skipped_bmg
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
intel/torch-xpu-ops#6142 · 1 comentario ·
Los mantenedores suelen responder en 2 días
-
good first issue help wanted python up-for-grabs
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
andrewsiah/agentswarm-data-tasks#122 ·
Los mantenedores suelen responder en 1 día