Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Inconsistent theme updates using `template`

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

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

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
25/100
Loại issue
Lỗi
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
data-visualization

Hướng nghiên cứu

Bắt đầu bằng cách tái tạo các ví dụ Plotly Express và graph-object bằng template và update_layout, bao gồm cả trường hợp colorscale được chỉ định rõ ràng. So sánh cách Figure 2/3 và Figure 5/7 phân giải các thiết lập của template, sau đó làm rõ hành vi nào trong hai hành vi được đề xuất là hành vi dự kiến. Công việc được xem là hoàn tất khi ngữ nghĩa cập nhật template được chấp nhận nhất quán trên cả hai giao diện và các ví dụ được ghi lại không còn khác nhau.

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

Mô tả

documentation feature P3

According to Theming and templates in Python, a figure can be created using a predefined template or updated to match it. However, the way updates happen is confusing if not inconsistent. Consider the examples below for plotly[express] == 6.2.0.

Plotly Express

import plotly.express as px

df = px.data.iris()

# uses the default `plotly` template
fig = px.scatter(df, x="sepal_width", y="sepal_length", color="petal_length", title="Figure 1")
fig.show()

# update to use another template, note that the colour scale is unchanged
fig.update_layout(template="seaborn", title="Figure 2")
fig.show()

# this is not equivalent to Figure 2
fig = px.scatter(df, x="sepal_width", y="sepal_length", color="petal_length", template="seaborn", title="Figure 3")
fig.show()

So Figure 3 is not the same as Figure 2, at least because the colour scales don't match. For custom themes, I can imagine that there may be other components of the figure object that would differ. As far as I know, there is no way to update traces using a template, e.g., fig.update_traces(template="seaborn"), to adjust non-layout settings.

Plotly Graph Object

To make things more confusing, there is a Specifying themes in graph object figures example in the documentation that does the same, but it actually works as expected. Adjusting the example we get:

import plotly.express as px
import plotly.graph_objects as go

df = px.data.iris()

# uses the default `plotly` template
fig = go.Figure(
    data=go.Scatter(
        x=df["sepal_width"],
        y=df["sepal_length"],
        mode="markers",
        marker={
            "color": df["petal_length"],
            "showscale": True,
        },
    )
)
fig.update_layout(title="Figure 4")
fig.show()

# update to use another template, note that the colour scale has changed as expected
fig.update_layout(template="seaborn", title="Figure 5")
fig.show()

However, specifying an explicit colorscale will prevent a template update from setting its own colour scheme:

# same as Figure 4 but with an explicit `colorscale`
fig = go.Figure(
    data=go.Scatter(
        x=df["sepal_width"],
        y=df["sepal_length"],
        mode="markers",
        marker={
            "color": df["petal_length"],
            "colorscale": "Viridis",  # or any other colour scale
            "showscale": True,
        },
    )
)
fig.update_layout(title="Figure 6")
fig.show()

# no longer matches Figure 5
fig.update_layout(template="seaborn", title="Figure 7")
fig.show()

Suggestions

  1. I would expect fig.update_layout(template="seaborn") to have the same effect, regardless of whether px or go interface is used. From this perspective, to result for Figure 2 is a bug (the colour scale should have changed for seaborn template).
  2. When an existing figure is updated, the settings from a template should take precedence over any existing settings. So Figure 5 and Figure 7 should produce the same result. This would entail that an update in Figure 7 overwrites whatever the colorscale setting Figure 6 has with that of a template provided in update_layout.
Ngôn ngữ chính
Python
Star
18.8k
Fork
2.8k
Merge trung bình
13 giờ 41 phút
Pull request đã merge (30 ngày)
21

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.

Issue khác của plotly/plotly.py

Tất cả issue của plotly/plotly.py

Issue tương tự

Thêm issue về Python

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.