Adding config modes to Plotly.Py offline - modebar

爷,独闯天下 提交于 2019-11-28 10:34:18

Open the HTML file, search for modeBarButtonsToRemove:[] then replace with the buttons you want removed, for my purpose modeBarButtonsToRemove:['sendDataToCloud']

To remove the Plotly Logo and link, search for displaylogo:!0 and replace with displaylogo:!1

Here is a demo using Python:

from plotly.offline import plot
import plotly.graph_objs as go
import webbrowser
import numpy as np
import pandas as pd

# generate your Plotly graph here

N = 500
y = np.linspace(0, 1, N)
x = np.random.randn(N)
df = pd.DataFrame({'x': x, 'y': y})
data = [go.Histogram(x=df['x'])]

# plot it for offline editing
HTMLlink = plot(data, show_link=False, auto_open=False)[7:] #remove the junk characters
# now need to open the HTML file
with open(HTMLlink, 'r') as file :
  tempHTML = file.read()
# Replace the target strings
tempHTML = tempHTML.replace('displaylogo:!0', 'displaylogo:!1')
tempHTML = tempHTML.replace('modeBarButtonsToRemove:[]', 'modeBarButtonsToRemove:["sendDataToCloud"]')
with open(HTMLlink, 'w') as file:
  file.write(tempHTML)
del tempHTML

webbrowser.open(HTMLlink)

This is the compact code. No need in the workaround.

plot(figure, filename='my_chart.html', show_link=False,
     config=dict(displaylogo=False,
                 modeBarButtonsToRemove=['sendDataToCloud']))

cool workaround. There's a PR for this here: https://github.com/plotly/plotly.py/pull/410. However there was some debate as to the implementation and thus it hasn't been merged.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!