Plotly:关闭会话的模式栏
Plotly: Turn off modebar for the session
我可以通过将 displayModeBar: False
作为 fig.show()
中 config
的值传递来关闭模式栏,就像这样-
import plotly.express as px
df = px.data.stocks()
fig = px.line(df, x='date', y='GOOG')
fig.show(config={'displayModeBar':False})
但是有没有一种方法可以让我在整个会话中只执行一次,而不必在每次图形调用时都传递它?
在撰写本文时,还没有官方方法可以为每个图形的 show
函数设置默认 config
值。
我建议的解决方法是创建一个函数来设置默认值并将它们传递给图形的 show
函数:
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)
上面将config
的默认值设置为{"displayModeBar": False}
。可以通过将参数传递给自定义 show
函数来简单地覆盖默认值。
import plotly.io as pio
pio.renderers['jupyterlab'].config['displayModeBar'] = False
我可以通过将 displayModeBar: False
作为 fig.show()
中 config
的值传递来关闭模式栏,就像这样-
import plotly.express as px
df = px.data.stocks()
fig = px.line(df, x='date', y='GOOG')
fig.show(config={'displayModeBar':False})
但是有没有一种方法可以让我在整个会话中只执行一次,而不必在每次图形调用时都传递它?
在撰写本文时,还没有官方方法可以为每个图形的 show
函数设置默认 config
值。
我建议的解决方法是创建一个函数来设置默认值并将它们传递给图形的 show
函数:
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)
上面将config
的默认值设置为{"displayModeBar": False}
。可以通过将参数传递给自定义 show
函数来简单地覆盖默认值。
import plotly.io as pio
pio.renderers['jupyterlab'].config['displayModeBar'] = False