将配置模式添加到Plotly.Py脱机-模式栏 [英] Adding config modes to Plotly.Py offline - modebar

查看:85
本文介绍了将配置模式添加到Plotly.Py脱机-模式栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Plotly.js包含配置ModeBar所需的所有参数,该参数允许从显示栏中删除选项(例如,用于在线编辑图形的链接).但是,这在Plotly.py API中似乎没有实现.在js版本中:

Plotly.js includes all the parameters needed to configure the ModeBar, which allows one to take away options from the display bar (such as the link to edit the graph online). However, this does not appear implemented in the Plotly.py API. In the js version:

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

Plotly.newPlot('myDiv', data, layout, {displayModeBar: false}); Removes the modebar entirely.
Plotly.newPlot('myDiv', data, layout, {displaylogo: false}, {modeBarButtonsToRemove: ['sendDataToCloud','hoverCompareCartesian']}) allows one to specify each button to remove which I'd like to implement.

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

I've edited this as I've found a workaround... see the answer I posted below. Can come in handy for those that have other parameters that they would like to use.

推荐答案

打开HTML文件,搜索modeBarButtonsToRemove:[],然后用您要删除的按钮替换,这是出于我的目的modeBarButtonsToRemove:['sendDataToCloud']

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

要删除Plotly徽标和链接,请搜索displaylogo:!0并替换为displaylogo:!1

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

这是一个使用Python的演示:

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)

这篇关于将配置模式添加到Plotly.Py脱机-模式栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆