`fig.update_traces(xaxis=..)` will destroy `hline` or `vline` objects on subplots
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 18.8k
- Forks
- 2.8k
- Ø Merge
- 16 Std. 26 Min.
- Gemergte PRs (30 T.)
- 21
Beschreibung
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, ...).
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.
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit, das Problem mit make_subplots, add_hline und figure.update_traces(xaxis="x3") zu reproduzieren; die verknüpfte visualize.py enthält das vollständige Beispiel. Verfolge, wie update_traces die Achsenzuweisungen ändert und wie hline-Objekte von Subplots dargestellt werden. Erledigt ist die Aufgabe, wenn das Aktualisieren der Trace-Achsen alle hline und vline über die Subplots hinweg erhält und das gemeldete Beispiel sie weiterhin anzeigt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- plotly, python
- Bereich
- data-visualization
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Aktiv
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 55/100