亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在散景中繪制多列數據幀

在散景中繪制多列數據幀

SMILET 2021-11-09 19:30:05
我已經構建了一個簡單的燒瓶應用程序。前端(視圖)提供了兩個復選框 A 和 B,它們是數據框列。當我選擇任一列時,將繪制列值。這是代碼。from flask import Flask, render_template, redirect, requestfrom bokeh.plotting import figure, show, output_file,saveimport webbrowserfrom threading import Timerimport pandas as pdimport numpy as npimport osapp = Flask(__name__)@app.route('/')def index():    return render_template('sop1.html')@app.route('/FlaskTutorial',  methods=['POST'])def user_rec():    dates = pd.date_range('20130101', periods=100)    df1 = pd.DataFrame(np.random.randn(100, 2), index=dates,      columns=list('AB'))    result = request.form     signal = request.form.getlist('check')    print(signal)    df=pd.DataFrame(df1[signal])    path=os.getcwd()    plot=figure(title="Time series data for "+str(df.columns[0])+" pair",width=1000,height=600,x_axis_type='datetime',tools='hover')       plot.line( source=df,x='index',y=str(df.columns[0]), line_color="blue",legend="spot rate")output_file(str(path)+'/templates/myplot11.html')save([plot])return render_template('myplot11.html', result=result)def open_browser():      webbrowser.open_new('http://127.0.0.1:3190/') if __name__ == '__main__':    Timer(1, open_browser).start();    app.run(port=3190,debug=True)我想要的是,當我選擇兩列時要繪制的兩列(水平或垂直)。這是 sop1.html<!DOCTYPE html><html><head>   <body>      <form method="post" action="/FlaskTutorial">      <div class="custom1">         <p>Dataframe columns</p>         <input type = "checkbox" name = "check" value = "A"> A <br> </br>        <input type = "checkbox" name = "check" value = "B"> B<br> </br>       </div>     <input type="submit" value="Submit" name="ok"/>          </form>   </body></html>請建議前進的方向。我的散景版本是 1.0.4
查看完整描述

1 回答

?
白板的微信

TA貢獻1883條經驗 獲得超3個贊

僥幸,我找到了解決方案。


result = request.form 

signal = request.form.getlist('check')


dd=[]

for i in range(len(signal)):

    print(i)

    dd.append(bokeh_plot(df1,i))

save([dd[0],dd[1]]) 

這是 bokeh_plot 函數


def bokeh_plot(df,i):

    path=os.getcwd()

    plot=figure(title="Time series data for "+str(df.columns[i])+" pair",width=1000,height=600,x_axis_type='datetime',tools='hover')   

    plot.line( source=df,x='index',y=str(df.columns[i]), line_color="blue",legend="spot rate")

    output_file(str(path)+'/templates/myplot11.html')

    #save([plot])

    return plot


查看完整回答
反對 回復 2021-11-09
  • 1 回答
  • 0 關注
  • 184 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號