Unexpected behavior when rotating x-axis text
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- Mezza giornata
- Idoneità per principianti
- 55/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- matplotlib, python
- Ambito
- data-visualization
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- Lingua principale
- Python
- Stelle
- 4.8k
- Fork
- 260
- Merge medio
- 2g 12h
- PR unite (30g)
- 4
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di has2k1/plotnine
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
I maintainer di solito rispondono entro 1 giorno
-
Enhancement
Difficoltà 4/5 3-5 giorni Idoneità per principianti 52/100
has2k1/plotnine#1081 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Discussion
Difficoltà 5/5 Più di una settimana Idoneità per principianti 30/100
has2k1/plotnine#1047 · 15 commenti · 3 reazioni ·
I maintainer di solito rispondono entro 1 giorno
-
Documentation Plot Composition Question
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
has2k1/plotnine#1036 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Installation Plot Composition
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 20/100
has2k1/plotnine#1031 · 11 reazioni ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di has2k1/plotnine
Issue simili
-
Edit: TVS Encarnacion [PY]Apertachannels:edit check:passed
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
[Bug] The blue-green mitigation strategy lists catalog names and views before the source tablesAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
aws-samples/sample-aws-genai-db-modernizer#2097 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
ietf-tools/datatracker#12027 ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug]: Python SDK overwrites OVPack backups with HTTP 200 JSON errorsForse già presa @stefanielizeth73-art l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
volcengine/OpenViking#7347 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
deepset-ai/haystack-core-integrations#4228 ·
I maintainer di solito rispondono entro 1 giorno