S
Solara12mo ago
artursp.

Remove controls from plotly figure

I'm using plotly to create clickable images that are tightly arranged. For this I need to remove the plotly controls. This can be done by passing config={'displayModeBar': False} to plotly.show, but as this is not a figure property I'm not sure how to accomplish this when doing solara.FigurePlotly(fig).
7 Replies
Ítalo Epifânio
Ítalo Epifânio12mo ago
@artursp. I don't think there's a way to do that using solara FigurePlotly component. The displayModeBar is not part of the figure, it's changed in the render phase of Plotly. There's a hack in the end of this issue that may help you hacking solara rendering as well: https://github.com/plotly/plotly.py/issues/1074#issuecomment-663543409
GitHub
pass config options to FigureWidget · Issue #1074 · plotly/plotly.py
Previously I was able to do plotly.offline.plot(..., config={'showLink':False, 'displayModeBar':False}) Is it possible using the new FigureWidget ?
MaartenBreddels
MaartenBreddels12mo ago
Good question. I see that the widget exposes a https://github.com/plotly/plotly.py/blob/95cc3d0dc6b3379d181e28ba90a0b708fad3bc40/packages/python/plotly/plotly/basewidget.py#L41 _config object, maybe this needs to be an argument to our plotly component?
Monty Python
Monty Python12mo ago
packages/python/plotly/plotly/basewidget.py line 41
_config = Dict().tag(sync=True, **custom_serializers)
_config = Dict().tag(sync=True, **custom_serializers)
artursp.
artursp.OP12mo ago
Thanks, unfortunately a naive application does not work (bar still shows): import plotly.graph_objects as go fig = go.FigureWidget() fig._config = fig._config | {'displayModeBar': False} solara.FigurePlotly(fig) Would there be another straight forward method for getting clickable (matplotlib) images?
Gordon
Gordon12mo ago
One option is to hide it with CSS plotly .modebar { display: none; }
MaartenBreddels
MaartenBreddels12mo ago
Nice workaround @Gordon ! To configure the underlying widget, you can use the following pattern:
fig = px.scatter(df, x="sepal_width", y="sepal_length", color="species")
def configure():
fig_widget = solara.get_widget(fig_element)
fig_widget._config = fig_widget._config | {'displayModeBar': False}
solara.use_effect(configure)
fig_element = solara.FigurePlotly(
fig, on_selection=set_selection_data, on_click=set_click_data, on_hover=set_hover_data, on_unhover=set_unhover_data, on_deselect=set_deselect_data
)
fig = px.scatter(df, x="sepal_width", y="sepal_length", color="species")
def configure():
fig_widget = solara.get_widget(fig_element)
fig_widget._config = fig_widget._config | {'displayModeBar': False}
solara.use_effect(configure)
fig_element = solara.FigurePlotly(
fig, on_selection=set_selection_data, on_click=set_click_data, on_hover=set_hover_data, on_unhover=set_unhover_data, on_deselect=set_deselect_data
)
artursp.
artursp.OP12mo ago
awesome, thanks!
Want results from more Discord servers?
Add your server