plotly / plotly/plotly.py

Cannot increase distance between shape and its label outside of the object

Đang mở
#4,971 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

feature P3
Ngôn ngữ chính
Python
Star
18.8k
Fork
2.8k
Merge trung bình
16 giờ 26 phút
Pull request đã merge (30 ngày)
21

Mô tả

Challenge

I would like to draw a shape using the label argument to position the label outside of the shape. Unfortunately, the label always touches the shape and padding only works in one direction: towards the center of the shape.

Here is an example:

import plotly.graph_objects as go

fig = go.Figure()

for i in range(0, 4):
    fig.add_shape(
        go.layout.Shape(
            type="rect",
            x0=10,
            y0=10*i + 3,
            x1=15,
            y1=10*i + 10,
            label={
                "text": f"Padding: {i*10}px",
                "textposition": "middle right",
                "xanchor": "left",
                "yanchor": "middle",
                "padding": i*10,
            },
        )
    )

fig.update_layout(xaxis_range=[0, 20], yaxis_range=[0, 60])

fig.show()

Despite seting xanchor="left" and textposition="middle right", the label barely touches the shape (for padding=0) and with increasing padding the label always moves towards the center.

Image

Setting padding to a negative value seems not to be allowed:

ValueError: 
    Invalid value of type 'builtins.int' received for the 'padding' property of layout.shape.label
        Received value: -10

    The 'padding' property is a number and may be specified as:
      - An int or float in the interval [0, inf]

Expected Behavior

Either infer from anchor and textposition, if a label should be outside of the shape, or allow negative values for padding so that I can increase the distance between the rectangle and the label.

I could not find any other info regarding this observation and I would like to avoid using an annotation as a workaround.

Am I overlooking something or is this a bug?

System Info

python: v3.10.11
plotly: v5.24.1

Working in a VSCode (v1.96.2) notebook and tested multiple different renderers with identical outcome: "vscode", "notebook", "browser".
Same result with write_image and pdf and png.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách chạy ví dụ go.Figure/add_shape được cung cấp với các giá trị padding và renderer khác nhau. Theo dõi cách các nhãn của shape xử lý textposition, xanchor và padding; issue được hoàn thành khi các nhãn có thể được đặt cách ra phía ngoài shape mà không cần workaround bằng annotation, với kiểm thử hồi quy cho trường hợp đã minh họa.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
data-visualization
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Sôi nổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
48/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.