plotly / plotly/plotly.py

`fig.update_traces(xaxis=..)` will destroy `hline` or `vline` objects on subplots

Đang mở
#4,904 3 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ả

Summary

When the figure is created by make_subplots, updating traces' xaxis or yaxis will destroy hline or vlines from user's view.

Details

The following picture represents my figure created with subplots of 3 rows and 1 column. It has horizontal line added by figure.add_hline(y=0.0, ...).

plot1_no_update_traces

def get_historical_charts(
    tournaments: list[TournamentSummary],
    max_data_points: int = 2000,
    window_sizes: tuple[int, ...] = DEFAULT_WINDOW_SIZES,
):
    # .... some dirty codes..

    figure.add_hline(    # <-------------------------------- ADDED hline
        y=0.0,
        line_color="red",
        line_dash="dash",
        row=1,
        col=1,
        label={
            "text": "Break-even",
            "textposition": "end",
            "font": {"color": "red"},
            "yanchor": "top",
        },
    )
    figure.update_layout(
        title="Historical Performance",
        hovermode="x unified",
        yaxis1={"tickformat": "$"},
        yaxis2={"tickformat": "%"},
        yaxis3={"tickformat": "$"},
    )
    figure.update_yaxes(row=3, col=1, patch={"type": "log"})
    # figure.update_traces(xaxis="x3")  # <------------------------------------- WILL CHANGE HERE
    return figure

However, I wanted to display vertical dash line on all subplots regardless of which graph you are focusing. I googled and found figure.update_traces(xaxis="x3") will make this work, but it destroyed hline. Notice that red dash line is disappeared on the second picture.

plot2_update_traces

def get_historical_charts(
    tournaments: list[TournamentSummary],
    max_data_points: int = 2000,
    window_sizes: tuple[int, ...] = DEFAULT_WINDOW_SIZES,
):
    # .... some dirty codes..

    figure.add_hline(    # <-------------------------------- ADDED hline
        y=0.0,
        line_color="red",
        line_dash="dash",
        row=1,
        col=1,
        label={
            "text": "Break-even",
            "textposition": "end",
            "font": {"color": "red"},
            "yanchor": "top",
        },
    )
    figure.update_layout(
        title="Historical Performance",
        hovermode="x unified",
        yaxis1={"tickformat": "$"},
        yaxis2={"tickformat": "%"},
        yaxis3={"tickformat": "$"},
    )
    figure.update_yaxes(row=3, col=1, patch={"type": "log"})
    figure.update_traces(xaxis="x3")  # <------------- UPDATED XAXIS AND hline IS DESTROYED
    return figure

Note that there is only 1 line of difference from above two codes.

For full codes, you can refer my repository's code.

For bandaid, I can do figure.update_traces(xaxis="x1") instead, but it will destroy custom objects on second/third subplot. So this is not a fundamental resolution.

Personally I think showing horizontal or vertical dash line to indicate which x or y are you hovering is important. However, with current status you can potentially destroy custom plot objects like hline if you do that.

Thanks for reading this.

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 tái hiện vấn đề với make_subplots, add_hline và figure.update_traces(xaxis="x3"); visualize.py được liên kết cung cấp ví dụ đầy đủ. Theo dõi cách update_traces thay đổi các phép gán trục và cách các đối tượng hline của subplot được biểu diễn. Công việc được hoàn tất khi việc cập nhật các trục của trace giữ lại mọi hline và vline trên tất cả các subplot, đồng thời ví dụ được báo cáo vẫn hiển thị chú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ệ
plotly, 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
55/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.