一页上的多个 plotly plots 没有子图
Multiple plotly plots on 1 page without subplot
我想在不使用 tools.make_subplots 方法的情况下在 1 html 页上绘制多个 plotly 图。 (我不想使用它,因为我发现它不容易阅读,而且我希望在每个子图面板中都有一个独特的图例和布局)。
我想定义2个具有自己独特布局的图形,并在页面上任意排列它们。我想我知道如何使用 html.Div 对象使用 dash 来做到这一点,但我想知道是否有一种简单的方法可以仅使用 plotly 来做到这一点?
所以,总而言之,我还没有找到一种纯粹用 plotly 来做到这一点的方法。下面是我使用 Dash 执行此操作的代码,它运行良好:
第 1 步:制作一些情节图
import plotly.offline as pyo
import plotly.graph_objs as go
import plotly as py
fig1 = go.Scatter(y=[1,2,3])
fig2 = go.Scatter(y=[3,2,1])
plots = [fig1, fig2]
第 2 步:制作破折号 Div 个对象:
app = dash.Dash()
layout = html.Div(
[html.Div(plots[i]) for i in range(len(plots))],
style = {'margin-right': '0px'}
)
第 3 步:运行 破折号
app.layout = layout
app.run_server(port=8052)
我遇到了同样的问题,并按照此处发布的解决方案进行操作:
来自 Esostack
然而,当我将多个图形的 html 转储到一个文本文件中时,我发现文件大小增加了 5MB 每添加一个图形。其中 99.9% 是由 plotly 添加的 java 脚本内容引起的,以使情节具有交互性。幸运的是,他们还实现了一个参数来指定是否要包含 js。因此,您只需要为第一个图形包含它,其余的则跳过它,就像在以下函数中完成的那样。希望有所帮助:
def figures_to_html(figs, filename):
'''Saves a list of plotly figures in an html file.
Parameters
----------
figs : list[plotly.graph_objects.Figure]
List of plotly figures to be saved.
filename : str
File name to save in.
'''
import plotly.offline as pyo
dashboard = open(filename, 'w')
dashboard.write("<html><head></head><body>" + "\n")
add_js = True
for fig in figs:
inner_html = pyo.plot(
fig, include_plotlyjs=add_js, output_type='div'
)
dashboard.write(inner_html)
add_js = False
dashboard.write("</body></html>" + "\n")
我想在不使用 tools.make_subplots 方法的情况下在 1 html 页上绘制多个 plotly 图。 (我不想使用它,因为我发现它不容易阅读,而且我希望在每个子图面板中都有一个独特的图例和布局)。
我想定义2个具有自己独特布局的图形,并在页面上任意排列它们。我想我知道如何使用 html.Div 对象使用 dash 来做到这一点,但我想知道是否有一种简单的方法可以仅使用 plotly 来做到这一点?
所以,总而言之,我还没有找到一种纯粹用 plotly 来做到这一点的方法。下面是我使用 Dash 执行此操作的代码,它运行良好:
第 1 步:制作一些情节图
import plotly.offline as pyo
import plotly.graph_objs as go
import plotly as py
fig1 = go.Scatter(y=[1,2,3])
fig2 = go.Scatter(y=[3,2,1])
plots = [fig1, fig2]
第 2 步:制作破折号 Div 个对象:
app = dash.Dash()
layout = html.Div(
[html.Div(plots[i]) for i in range(len(plots))],
style = {'margin-right': '0px'}
)
第 3 步:运行 破折号
app.layout = layout
app.run_server(port=8052)
我遇到了同样的问题,并按照此处发布的解决方案进行操作:
然而,当我将多个图形的 html 转储到一个文本文件中时,我发现文件大小增加了 5MB 每添加一个图形。其中 99.9% 是由 plotly 添加的 java 脚本内容引起的,以使情节具有交互性。幸运的是,他们还实现了一个参数来指定是否要包含 js。因此,您只需要为第一个图形包含它,其余的则跳过它,就像在以下函数中完成的那样。希望有所帮助:
def figures_to_html(figs, filename):
'''Saves a list of plotly figures in an html file.
Parameters
----------
figs : list[plotly.graph_objects.Figure]
List of plotly figures to be saved.
filename : str
File name to save in.
'''
import plotly.offline as pyo
dashboard = open(filename, 'w')
dashboard.write("<html><head></head><body>" + "\n")
add_js = True
for fig in figs:
inner_html = pyo.plot(
fig, include_plotlyjs=add_js, output_type='div'
)
dashboard.write(inner_html)
add_js = False
dashboard.write("</body></html>" + "\n")