Iām creating plotly figures using plotly.express
, created a custom theme and setting it as a default theme pio.templates.default = "my_theme
.
my_theme
pio.templates["my_theme"] = go.layout.Template(
layout={},
data= dict(
bar=[dict(texttemplate="%{value:,}", hovertemplate="%{label}<br>(%{value:,})<extra></extra>", width=0.6,...)],
pie=[dict(texttemplate="%{percent:.2%}", hovertemplate="%{label}<br><b>(%{value:,})</b>"...)]
),
)
Everything in the traces is applying without a problem, but the hovertemplate
is being ignored.
When figures are created with plotly.express:
figure = px.bar(source, x="x"....)
the default hovertemplate : "x_label=%{x}<br>y_label=%{y}"
instead of the one defined in the custom theme. But all other traces are applied from the theme.
The only way to get it to work is to disable hovertemplate in update_traces:
figure.update_traces(hovertemplate=None)
Then it works as expected.
If, however, I create the figures as graph_objects
, everything in the custom theme is applying, including the specified hovertemplate
.
Is this a bug or am I overlooking something?
Iām using plotly v5.24.0