加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

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

发布时间:2020-12-20 12:33:08 所属栏目:Python 来源:网络整理
导读:Plotly.js包含配置ModeBar所需的所有参数,允许用户从显示栏中取走选项(例如在线编辑图形的链接).但是,这似乎没有在Plotly.py API中实现.在js版本中: Plotly.newPlot(‘myDiv’,data,layout,{displayModeBar:false}); 完全删除模式栏. ?Plotly.newPlot(‘my
Plotly.js包含配置ModeBar所需的所有参数,允许用户从显示栏中取走选项(例如在线编辑图形的链接).但是,这似乎没有在Plotly.py API中实现.在js版本中:

Plotly.newPlot(‘myDiv’,data,layout,{displayModeBar:false});
完全删除模式栏.
?Plotly.newPlot(‘myDiv’,{displaylogo:false},{modeBarButtonsToRemove:[‘sendDataToCloud’,’hoverCompareCartesian’]})允许指定每个按钮以删除我想要实现的按钮.

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

解决方法

打开 HTML文件,搜索modeBarButtonsToRemove:[]然后替换你想要删除的按钮,为我的目的modeBarButtonsToRemove:[‘sendDataToCloud’]

要删除Plotly徽标和链接,请搜索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)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读