plotly / plotly/plotly.py

Multiple legends are not independent in their placement and placement is not consistent

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

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

bug 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ả

I am currently experimenting with the new-ish multi-legend feature. Unfortunately I seem to have stumbled across a case in which the legends are not behaving independently even though it is not clear why.

The following code demonstrates this:

from copy import deepcopy
import plotly.graph_objects as go

error_fig = {
    'data': [
        {
            'legend': 'legend2',
            'showlegend': True,
            'type': 'scatter',
            'x': [0, 1],
            'xaxis': 'x2',
            'y': [0, -1],
            'yaxis': 'y2'
        },
        {
            'legend': 'legend3',
            'showlegend': True,
            'type': 'scatter',
            'x': [0, 1],
            'xaxis': 'x3',
            'y': [0, 1],
            'yaxis': 'y3'
        },
        {
            'legend': 'legend3',
            'showlegend': True,
            'type': 'scatter',
            'x': [0, 1],
            'xaxis': 'x3',
            'y': [0, -1],
            'yaxis': 'y3'
        },
        {
            'legend': 'legend3',
            'showlegend': True,
            'type': 'scatter',
            'x': [0, 1],
            'xaxis': 'x3',
            'y': [0, 1],
            'yaxis': 'y3'
        },
        {
            'legend': 'legend3',
            'showlegend': True,
            'type': 'scatter',
            'x': [0, 1],
            'xaxis': 'x3',
            'y': [0, 1],
            'yaxis': 'y3'
        }
    ],
    'layout': {
        'legend2': {
            'orientation': 'v',
            'visible': True,
            'x': 0.515,
            'xanchor': 'left',
            'xref': 'paper',
            'y': 0.3,
            'yanchor': 'top',
            'yref': 'paper'
        },
        'legend3': {
            'entrywidth': 0.2,
            'entrywidthmode': 'fraction',
            'orientation': 'h',
            'visible': True,
            'x': 0.95,
            'xanchor': 'left',
            'xref': 'paper',
            'y': 1.0,
            'yanchor': 'top',
            'yref': 'paper'
        },
        'xaxis2': {'anchor': 'y2', 'domain': [0, 0.5]},
        'xaxis3': {'anchor': 'y3', 'domain': [0.45, 0.95]},
        'yaxis2': {'anchor': 'x2', 'domain': [0, 0.3]},
        'yaxis3': {'anchor': 'x3', 'domain': [0.7, 1.0]}
    }
}


correct_fig = deepcopy(error_fig)
correct_fig["layout"]["legend3"]["x"] = 1

fig_correct = go.Figure(correct_fig)
fig_correct.show()

fig_error = go.Figure(error_fig)
fig_error.show()

Where fig_correct produces this output upon png-download (The issue also exists in interactive mode with varying severity based on screen size):
correct

fig_error produces this:
error

Which for me makes no sense as the only change that occurred was the placement of legend3 along x. I would therefore not expect legend2 to move. Additionally, for me it does not make any sense, why any large movement should occur at all, as I only changed the x-coordinate of legend3 by 0.05 .

For me the Issue only occurs when using "orientation": "h".


I am on Python 3.11.1
My pip dump:

Package    Version
---------- -------
packaging  23.1
pip        22.3.1
plotly     5.17.0
setuptools 65.5.0
tenacity   8.2.3

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 bản tái hiện Python được cung cấp với Plotly 5.17.0 và so sánh các bố cục nhiều chú giải theo chiều ngang ở chế độ tương tác và đầu ra PNG. Không có tệp nguồn hoặc bài kiểm thử nào được nêu, vì vậy hãy lần theo các điểm đầu vào của việc định vị chú giải và kết xuất bố cục từ bản tái hiện; được xem là hoàn tất khi việc di chuyển legend3 không còn vô tình di chuyển legend2 hoặc gây ra chuyển động không cân xứng.

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
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
38/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.