python - 将配置模式添加到 Plotly.Py 离线 - 模式栏

标签 python plotly

Plotly.js 包含配置 ModeBar 所需的所有参数,它允许从显示栏中删除选项(例如在线编辑图形的链接)。但是,这似乎没有在 Plotly.py API 中实现。在js版本中:
Plotly.newPlot('myDiv', data, layout, {displayModeBar: false});完全删除模式栏。
Plotly.newPlot('myDiv', data, layout, {displaylogo: false}, {modeBarButtonsToRemove: ['sendDataToCloud','hoverCompareCartesian']})允许一个人指定每个按钮来删除我想要实现的。

我已经编辑了这个,因为我找到了一种解决方法......请参阅我在下面发布的答案。对于那些想要使用其他参数的人来说可以派上用场。

最佳答案

打开 HTML 文件,搜索 modeBarButtonsToRemove:[]然后替换为您要删除的按钮,出于我的目的modeBarButtonsToRemove:['sendDataToCloud']
要删除 Plotly Logo 和链接,请搜索 displaylogo:!0并替换为 displaylogo:!1
这是一个使用 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)

关于python - 将配置模式添加到 Plotly.Py 离线 - 模式栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36554705/

相关文章:

python - Seaborn tsplot 在 x 轴上更改标签

python - 图像处理 : Problem with Fish measuring

python - 什么算法解决方案可以匹配包含倍数的两个垃圾箱之间的项目?

python - Plotly 图未在 ipywidgets 交互函数中渲染(Google Colab)

python - 如何在 Zeppelin 中使用 Plotly

python - 在 Python 中,如何缩放存储为 NumPy 数组的图像的大小?

python -/usr/local/lib/python2.6和/usr/lib/python2.6有什么区别?

python - 在 plotly 中添加一个 slider 来绘制带有子图的图形

javascript - 根据值更改标记颜色 - Plotly

python - 无法使用 Kaleido 将绘图图像导出为 png