【发布时间】:2018-04-16 07:00:50
【问题描述】:
是否可以在 plotly 的 Dash 框架中显示一个简单的 matplotlib 图(通常由 plt.show() 生成的那种)?或者只是带有 plotly 的 Scatters 和 Data traces 的类似 plotly 的图表?
具体来说,我想我需要一个不同于Graph 的组件(见下文),以及一种在update_figure 函数中返回简单绘图的方法。
例子:
import dash
import dash_core_components as dcc
import dash_html_components as html
import numpy as np
import matplotlib.pyplot as plt
app = dash.Dash()
app.layout = html.Div(children=[
html.H1(children='Hello Dash'),
dcc.Slider(
id='n_points',
min=10,
max=100,
step=1,
value=50,
),
dcc.Graph(id='example') # or something other than Graph?...
])
@app.callback(
dash.dependencies.Output('example', 'figure'),
[dash.dependencies.Input('n_points', 'value')]
)
def update_figure(n_points):
#create some matplotlib graph
x = np.random.rand(n_points)
y = np.random.rand(n_points)
plt.scatter(x, y)
# plt.show()
return None # return what, I don't know exactly, `plt`?
if __name__ == '__main__':
app.run_server(debug=True)
【问题讨论】:
-
想法:将matplotlib图作为普通图像处理,并将其设置为plotly图的背景图像
标签: python matplotlib plotly plotly-dash