Inconsistent theme updates using `template`
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 5/5
- 預估耗時
- 一週以上
- 新手友好度
- 25/100
- Issue 類型
- 缺陷
- 描述清晰度
- 需要釐清
- 活躍度
- 停滯
- 技術堆疊
- python
研究方向
首先使用 template 和 update_layout 重現 Plotly Express 和 graph-object 範例,包括明確指定 colorscale 的情況。比較 Figure 2/3 和 Figure 5/7 如何解析範本設定,然後釐清提出的兩種行為中哪一種是預期行為。當接受的範本更新語意在兩個介面之間保持一致,且文件中的範例不再存在差異時,即視為完成。
由索引模型根據 Issue 內容生成。
描述
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
- I would expect
fig.update_layout(template="seaborn")to have the same effect, regardless of whetherpxorgointerface is used. From this perspective, to result for Figure 2 is a bug (the colour scale should have changed forseaborntemplate). - 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
colorscalesetting Figure 6 has with that of a template provided inupdate_layout.
- 主要語言
- Python
- 星號
- 18.8k
- 分支
- 2.9k
- 平均合併
- 14 小時 12 分鐘
- 30 天內合併 PR
- 19
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
plotly/plotly.py 的其他 Issue
-
[BUG]: Unnecessary `UserWarning` when using `fig.write_image()` with `kaleido.start_sync_server()`可能已有人在做 @jayzhou2309 於 3 天前認領。 未關閉bug
難度 2/5 1-3 小時 新手友好度 74/100
維護者通常 1 天內回覆
-
P3 size: 1 task
難度 2/5 1-3 小時 新手友好度 65/100
plotly/plotly.py#5769 · 1 個 reaction ·
維護者通常 1 天內回覆
-
Remove `@types/plotly.js` dependency可能已有人在做 @Belagum 於 19 天前認領。 未關閉P3 size: 1 task
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆
-
bug P1
難度 1/5 1 小時以內 新手友好度 68/100
維護者通常 1 天內回覆
-
feature P3
難度 2/5 1-3 小時 新手友好度 62/100
維護者通常 1 天內回覆
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 82/100
維護者通常 1 天內回覆
-
難度 2/5 半天 新手友好度 70/100
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 72/100
Qiskit/qiskit-ibm-runtime#3431 · 1 則留言 ·
維護者通常 1 天內回覆
-
[Lesson] A compatibility-gate rejection is a verdict, not something to overwrite with --accept-risk未關閉lesson-submission needs-ac pending-review
難度 2/5 1-3 小時 新手友好度 65/100
Ikalus1988/MisakaNet#2870 ·
維護者通常 1 天內回覆
-
feature:LinkChecker
難度 2/5 1-3 小時 新手友好度 66/100
digitalfabrik/integreat-cms#4594 ·
維護者通常 5 天內回覆