✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🧬 Learn how to build RNA-Seq data apps with Python & Dash. Register for the May 20 Webinar!

How to remove mode bar buttons

I would like to know how can I remove some mode bar buttons of a plot using Python. I know that I can do this by the “config” argument in the “show” method, but this doesn’t change the plotly object, so when I get a json of this object, for example, it still has the buttons I tried to remove. Could anybody help me, please?

1 Like

Hi Camila! Welcome to the forum!

I use modeBarButtonsToRemove when I want to remove certain options from the modebar. you can use the config parameter when defining a plot like this:

plot(data, config={"modeBarButtonsToRemove": ['pan2d']})

All the names for the buttons are:
“zoom2d”, “pan2d”, “select2d”, “lasso2d”, “zoomIn2d”, “zoomOut2d”, “autoScale2d”, “resetScale2d”, “hoverClosestCartesian”, “hoverCompareCartesian”, “zoom3d”, “pan3d”, “resetCameraDefault3d”, “resetCameraLastSave3d”, “hoverClosest3d”, “orbitRotation”, “tableRotation”, “zoomInGeo”, “zoomOutGeo”, “resetGeo”, “hoverClosestGeo”, “toImage”, “sendDataToCloud”, “hoverClosestGl2d”, “hoverClosestPie”, “toggleHover”, “resetViews”, “toggleSpikelines”, “resetViewMapbox”

2 Likes

Hi Krichardson, thank you very much for your answer!

I am making a donut chart like this:

plt = go.Figure(data=[go.Pie(values=[0.25, 0.75],
                             hole=0.7, direction='clockwise', sort=False,
                             showlegend=False, textinfo='none', hoverinfo='none'
                            )
                     ])

This doesn’t accept the config parameter. Is there any other way I can use it?

Well. I have more experience with Dash than I do with just working with Plotly.py. Normally in Dash I would implement it like this:

import dash_core_components as dcc

dcc.Graph(figure = [Whatever figure you want],
          layout = [Layout stuff]
          config = {modeBarButtonsToRemove: ['pan2d']}
)

But it seems from what I’ve been able to find the only way modify the config with just plotly.py is through the config parameter in the show() function. Which I know you were wanting to avoid but its the only solid answer I can find.

Sorry about that Camila, Maybe someone who knows more about plotly.py than me will be able to point out a better way!

1 Like

Yeah, I’m afraid this is really the only way to do it. I’m gonna keep looking for a better way, though.

Thanks a lot!

Hi @camila.cardoso ,

The mode bar in Pie chart have only two buttons and you can remove them as bellow:

import plotly.graph_objects as go

fig = go.Figure(go.Pie(values=[0.25, 0.75],
                       hole=0.7, direction='clockwise', sort=False,
                       showlegend=False, textinfo='none', hoverinfo='none'))

fig.show(config={'modeBarButtonsToRemove':['toImage', 'hoverClosestPie']})

Thanks @Krichardson for the quick accurate reply.

Hi, mahdis!

Thanks for your answer! But, I am trying to avoid the show function because this doesn’t change the plt object, so when I try to get its json like this:

json.dumps(plt, cls=plotly.utils.PlotlyJSONEncoder)

the buttons are still there.

The modebar buttons are not controlled by the JSON of the figure, but rather by the config, which is a separate object, so I don’t think there’s a way to do what you’re trying to do unfortunately.

I see… Thanks, Nicolas!

So forgetting the json object for a moment, let’s suppose I changed the modebar buttons using the show function like mahdis exemplified. After I make another change in the pie chart, like adding annotations for example, if I wanna display the chart using the show method, will I have to change the config again?

yes you need to include the config in every show() call.

1 Like