Unexpected behavior when rotating x-axis text
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- Nửa ngày
- Mức phù hợp với người mới
- 55/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- matplotlib, python
- Lĩnh vực
- data-visualization
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- Python
- Star
- 4.8k
- Fork
- 260
- Merge trung bình
- 2 ngày 12 giờ
- Pull request đã merge (30 ngày)
- 4
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của has2k1/plotnine
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Enhancement
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 52/100
has2k1/plotnine#1081 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Discussion
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 30/100
has2k1/plotnine#1047 · 15 bình luận · 3 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Documentation Plot Composition Question
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
has2k1/plotnine#1036 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
plotnine 0.16.0 alpha releasesĐang mởInstallation Plot Composition
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 20/100
has2k1/plotnine#1031 · 11 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của has2k1/plotnine
Issue tương tự
-
enhancement good first issue help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
-
Community
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
kedro-org/kedro-plugins#1575 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
hive size:simple
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
Significant-Gravitas/AutoGPT#16733 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
changelog investigate
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 74/100
ramnes/notion-sdk-py#444 ·