在烧瓶上发送绘图

时间:2018-12-14 21:10:44

标签: html python-3.x ubuntu flask plotly

现在我有一个代码,可使用图来创建人物

def show_city_frequency(number_of_city = 10):
plot_1 = go.Histogram(
    x=dataset[dataset.city.isin(city_count[:number_of_city].index.values)]['city'],
    showlegend=False)

## Creating the grid for all the above plots
fig = tls.make_subplots(rows=1, cols=1)

fig.append_trace(plot_1,1,1)


fig['layout'].update(showlegend=True, title="Frequency of cities in the dataset ")
return plot(fig)

我想将其合并到flask函数中,并使用send_file将其作为字节io对象发送到html模板。我能够使用matplotlib做到这一点,只需使用:

img = io.BytesIO()
plt.plot(x,y, label='Fees Paid')
plt.savefig(img, format='png')
img.seek(0)
return send_file(img,   mimetype='image/png')

我已经读到除了使用以下内容外,我可以做基本相同的事情:

img =  plotly.io.to_image(fig, format='png')
img.seek(0)
return send_file(img, mimetype='image/png')

但是我似乎找不到在哪里下载plotly.io。我读过说,离线脱机不适用于Ubuntu,所以我想知道这是否也是我的问题。我也乐于接受有关如何将该图像动态发送到我的html代码的新建议。

0 个答案:

没有答案