我有一个直接返回图形的函数,我希望将该图形放置在布局的Div中。事实上,据我所知,不可能在回调中返回这种类型的对象
我不知道如何解决此问题以退回该数字。接下来,我也必须修改该数字。
返回数字的函数:
fig=plt.figure() #set up the figures
fig.set_size_inches(7, 5)
ax=fig.add_subplot(1,1,1)
draw_pitch(ax) # Here I draw some lines over the figure
ax.plot()
return fig
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
from utils import p_number, plot_pitch
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
app.layout = html.Div([
dcc.Input(id='my-id', value=p_number(7), type='text'),
html.Div(id='my-div')
])
@app.callback(
Output(component_id='my-div', component_property='children'),
[Input(component_id='my-id', component_property='value')],
[State('local', 'data')]
)
def update_output_div(input_value):
return plot_pitch()
if __name__ == '__main__':
app.run_server(debug=False)
Dash支持用plotly
生成的图形,但不支持matplotlib
生成的图形,这似乎是在此处完成的...这是相关文档:https://dash.plot.ly/interactive-graphing