第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

Plotly Dash:為什么我的數(shù)字無法通過多個(gè)下拉選項(xiàng)顯示?

Plotly Dash:為什么我的數(shù)字無法通過多個(gè)下拉選項(xiàng)顯示?

四季花海 2022-12-06 15:40:20
我正在使用 dash 和 plotly 構(gòu)建一個(gè)簡(jiǎn)單的 python 儀表板。我也是 python 的新手(可能很明顯?。?,我很高興任何/所有更正。我想從預(yù)先確定的 CSV 文件中繪制時(shí)間序列數(shù)據(jù)。我添加了一個(gè)下拉選擇框,我想用它來繪制多個(gè)不同的列。樣本數(shù)據(jù):"TOA5","HE605_RV50_GAF","CR6","7225","CR6.Std.07","CPU:BiSP5_GAF_v2d.CR6","51755","SensorStats""TIMESTAMP","RECORD","BattV_Min","BattV_Avg","PTemp_C_Avg","SensorRel_Min(1)","SensorRel_Min(2)","SensorRel_Min(3)","SensorRel_Min(4)","SensorRel_Min(5)","SensorRel_Max(1)","SensorRel_Max(2)","SensorRel_Max(3)","SensorRel_Max(4)","SensorRel_Max(5)""TS","RN","Volts","Volts","Deg C","","","","","","","","","","""","","Min","Avg","Avg","Min","Min","Min","Min","Min","Max","Max","Max","Max","Max""2019-09-30 11:15:00",0,12.68219,12.74209,"NAN","NAN","NAN","NAN","NAN","NAN","NAN","NAN","NAN","NAN","NAN""2019-09-30 11:30:00",1,12.68466,12.73777,31.26331,-2.498894,-2.38887,-8.497528,-2.963989,-20.42339,41.51585,28.41309,88.98283,27.27819,17.98986"2019-09-30 11:45:00",2,12.69364,12.74584,31.43891,-3.490456,-2.856804,-8.770081,-3.879868,-22.69171,42.27676,30.53723,89.47752,34.25191,23.92586"2019-09-30 12:00:00",3,12.69078,12.74522,31.38461,-3.290047,-2.973389,-8.69928,-3.295074,-21.88254,42.72508,29.91062,83.36012,27.9931,22.6571"2019-09-30 12:15:00",4,12.6914,12.74376,31.2449,-2.899231,-2.392128,-10.01413,-2.996033,-23.22171,42.97162,29.20943,106.1204,35.93995,41.74426我的 python(3.7) 代碼是:import dashimport dash_core_components as dccimport dash_html_components as htmlfrom dash.dependencies import Input, Outputimport pandas as pdimport plotly.graph_objects as go# Load external stylesheetsexternal_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']app = dash.Dash(__name__, external_stylesheets=external_stylesheets)    )  ])該圖的初始渲染看起來不錯(cuò),因?yàn)檫@是運(yùn)行后出現(xiàn)的python3 app.py:
查看完整描述

2 回答

?
翻過高山走不出你

TA貢獻(xiàn)1875條經(jīng)驗(yàn) 獲得超3個(gè)贊

問題是下拉列表返回多個(gè)變量的列表(如您設(shè)置的那樣multi=True),而您的回調(diào)旨在僅繪制一個(gè)變量。


為了繪制多個(gè)變量,您需要遍歷選定的變量列表(即通過selectedVariable2您的代碼)并將相應(yīng)的軌跡添加到圖中。


您還應(yīng)該確保下拉列表是用列表而不是字符串初始化的(即您應(yīng)該value="RECORD"用value=["RECORD"].


我在下面包括了一個(gè)例子。


import pandas as pd

import dash

import dash_core_components as dcc

import dash_html_components as html

from dash.dependencies import Input, Output

import plotly.graph_objects as go


# Load external stylesheets

external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']

app = dash.Dash(__name__, external_stylesheets=external_stylesheets)


# Create a sample http://img1.sycdn.imooc.com//638ef21c00015c7118101121.jpgataset

df = pd.DataFrame({"TIMESTAMP": ["2019-09-30 11:15:00", "2019-09-30 11:30:00", "2019-09-30 11:45:00", "2019-09-30 12:00:00", "2019-09-30 12:15:00"],

                   "RECORD": [0, 1, 2, 3, 4],

                   "SensorRel_Min(2)": [12.68219, 12.68466, 12.69364, 12.69078, 12.6914],

                   "SensorRel_Min(3)": [14.74209, 13.73777, 10.74584, 9.74522, 16.74376]})


# Define dropdown options

opts = [{'label': k, 'value': k} for k in list(df.columns.values)[1:]]


# Create a Dash layout

app.layout = html.Div(children=[


    html.H1(children='Testing dashboard v01'),


    html.Div(children='''

        Select variable to plot below.

    '''),


    html.Div(children='''

        Select variables to add to plot below.

    '''),


    dcc.Dropdown(

        id='multiVariableDropdown',

        options=opts,

        value=['RECORD'],

        multi=True

    ),


    dcc.Graph(

        id='plot2'

    )


])


# Add callback functions

## For plot 2

@app.callback(Output('plot2', 'figure'),

             [Input('multiVariableDropdown', 'value')])

def update_graph(selectedVariable2):


    traces = []


    for var in selectedVariable2:


        traces.append(go.Scatter(x=df['TIMESTAMP'],

                                 y=df[var],

                                 name=var))


    fig2 = go.Figure(data=traces)


    return fig2


if __name__ == '__main__':

    app.run_server(debug=True)


查看完整回答
反對(duì) 回復(fù) 2022-12-06
?
楊__羊羊

TA貢獻(xiàn)1943條經(jīng)驗(yàn) 獲得超7個(gè)贊

嘗試使用print()對(duì)其進(jìn)行調(diào)試。如下所示,這樣您就可以在每次從下拉列表中添加/刪除內(nèi)容時(shí)看到發(fā)送到輸出組件的內(nèi)容。希望能幫助到你!


def update_graph(selectedVariable2):

    trace_finalPlot2 = go.Scatter(

                            x=df['TIMESTAMP'],

                            y=df[selectedVariable2],

                            name=str(selectedVariable2))

    fig2 = go.Figure(data=trace_finalPlot2)

    print(df[selectedVariable2])

    return fig2


查看完整回答
反對(duì) 回復(fù) 2022-12-06
  • 2 回答
  • 0 關(guān)注
  • 172 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)