4

I can turn off the modebar in plotly by passing displayModeBar: False as the value of config in fig.show(), like this-

import plotly.express as px

df = px.data.stocks()
fig = px.line(df, x='date', y='GOOG')

fig.show(config={'displayModeBar':False})

But is there a way I could do it just once for the entire session rather than having to pass it with each figure call?

callmeanythingyouwant
  • 1,789
  • 4
  • 15
  • 40

2 Answers2

3
import plotly.io as pio

pio.renderers['jupyterlab'].config['displayModeBar'] = False
Stas S
  • 1,022
  • 1
  • 8
  • 18
0

As of writing this there isn't an official way to set a default config value for the show function of every figure.

What I would recommend as a workaround is to create a function that sets default values and passes them on to the show function of a figure:

import plotly.express as px

df = px.data.stocks()


def show(fig, *args, **kwargs):
    kwargs.get("config", {}).setdefault("displayModeBar", False)
    fig.show(*args, **kwargs)


df = px.data.stocks()
fig = px.line(df, x="date", y="GOOG")
show(fig)

The above sets the default value of config to {"displayModeBar": False}. The default value can simply be overwritten by passing arguments to the custom show function.

5eb
  • 14,798
  • 5
  • 21
  • 65