日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Visualization Document Feb 12 16:42

發布時間:2025/3/19 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Visualization Document Feb 12 16:42 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Visualization Document Feb 12 16:42

文章目錄

  • Visualization Document Feb 12 16:42
    • Page nav, PIE, and Line chart
    • PIE, and Line chart on differnet page
    • Table
    • Updated Table
    • Change the timeseries x axis to hours
    • Notes from Python Dash

Page nav, PIE, and Line chart

from dash import Dash, dcc, html,callback, Input, Output import pandas as pd import plotly.express as px app = Dash(__name__) # df = pd.read_csv ('robot.txt', sep =' ') # df2 = df.set_axis(['Time', 'Power', 'Robot'], axis=1, inplace=False)#df3 = px.data.tips()# fig = px.pie(df2, values='Power', names='Robot') # fig.show() #print(df3)app.layout = html.Div([ html.H1(children='Hello Dash'),html.Div(children='''Dash: A web application framework for your data.'''),dcc.Location(id='url', refresh=False),dcc.Link('Navigate to "/"', href='/'),html.Br(),dcc.Link('Navigate to "/page-2"', href='/page-2'),# content will be rendered in this elementhtml.Div(id='page-content'),dcc.Graph(figure = px.pie(df2, values='Power', names='Robot')),dcc.Graph(figure=dict(data=[dict(x=df2['Time'],y=df2['Power'].loc[df2['Robot']=='robot1'],#df.loc[df['column_name'] == some_value]name='Robot 1',marker=dict(color='rgb(55, 83, 109)')),dict(x=df2['Time'],y=df2['Power'].loc[df2['Robot']=='robot2'],#df.loc[df['column_name'] == some_value]name='Robot 2',marker=dict(color='rgb(26, 118, 255)'))],layout=dict(title='Robot Power',showlegend=True,legend=dict(x=0,y=1.0),margin=dict(l=40, r=0, t=40, b=30))),style={'height': 300},id='my-graph')])@callback(Output('page-content', 'children'),[Input('url', 'pathname')]) def display_page(pathname):return html.Div([html.H3(f'You are on page {pathname}')])if __name__ == '__main__':app.run_server(debug=True)

PIE, and Line chart on differnet page

from dash import Dash, dcc, html, Input, Output, callback import plotly.express as px app = Dash(__name__, suppress_callback_exceptions=True) import pandas as pddf = pd.read_csv ('robot.txt', sep =' ') # df2 = df.set_axis(['Time', 'Power', 'Robot'], axis=1, inplace=False)app.layout = html.Div([dcc.Location(id='url', refresh=False),html.Div(id='page-content') ])index_page = html.Div([dcc.Link('Pie chart', href='/page-1'),html.Br(),dcc.Link('Line chart', href='/page-2'), ])page_1_layout = html.Div([html.H1('Page 1'),dcc.Graph(figure=px.pie(df2, values='Power', names='Robot')),html.Div(id='page-1-content'),html.Br(),dcc.Link('Go to Line chart', href='/page-2'),html.Br(),dcc.Link('Go back to home', href='/'), ])@callback(Output('page-1-content', 'children'),[Input('page-1-dropdown', 'value')]) def page_1_dropdown(value):return f'You have selected {value}'page_2_layout = html.Div([html.H1('Page 2'),dcc.Graph(figure=dict(data=[dict(x=df2['Time'],y=df2['Power'].loc[df2['Robot'] == 'robot1'], # df.loc[df['column_name'] == some_value]name='Robot 1',marker=dict(color='rgb(55, 83, 109)')),dict(x=df2['Time'],y=df2['Power'].loc[df2['Robot'] == 'robot2'], # df.loc[df['column_name'] == some_value]name='Robot 2',marker=dict(color='rgb(26, 118, 255)'))],layout=dict(title='Robot Power',showlegend=True,legend=dict(x=0,y=1.0),margin=dict(l=40, r=0, t=40, b=30))),style={'height': 300},id='my-graph'),html.Div(id='page-2-content'),html.Br(),dcc.Link('Go to Pie Chart', href='/page-1'),html.Br(),dcc.Link('Go back to home', href='/') ])@callback(Output('page-2-content', 'children'),[Input('page-2-radios', 'value')]) def page_2_radios(value):return f'You have selected {value}'# Update the index @callback(Output('page-content', 'children'),[Input('url', 'pathname')]) def display_page(pathname):if pathname == '/page-1':return page_1_layoutelif pathname == '/page-2':return page_2_layoutelse:return index_page# You could also return a 404 "URL not found" page hereif __name__ == '__main__':app.run_server(debug=True)

Table

Energy consumedCurrent energyCurrent powerCurrent cost
RobotEnd of the columnDummy
page_3_layout = html.Div([html.H1('Page 3'),dash_table.DataTable(df2.to_dict('records'), [{"name": i, "id": i} for i in df2.columns]),html.Div(id='page-3-content'),html.Br(),dcc.Link('Go to Line chart', href='/page-3'),html.Br(),dcc.Link('Go back to home', href='/'), ])@callback(Output('page-3-content', 'children'),[Input('page-3-dropdown', 'value')]) def page_3_dropdown(value):return f'You have selected {value}'

Updated Table

d = {'Energy consumed': [1], 'Current energy': [3],'Current power': [3],'Current cost': [3]} df3=pd.DataFrame(data=d)page_3_layout = html.Div([html.H1('Page 3'),dash_table.DataTable(df3.to_dict('records'), [{"name": i, "id": i} for i in df3.columns]),html.Div(id='page-3-content'),html.Br(),dcc.Link('Go to Line chart', href='/page-3'),html.Br(),dcc.Link('Go back to home', href='/'), ])@callback(Output('page-3-content', 'children'),[Input('page-3-dropdown', 'value')]) def page_3_dropdown(value):return f'You have selected {value}'

Change the timeseries x axis to hours

official website

import plotly.express as px df = px.data.stocks() fig = px.line(df, x="date", y=df.columns,hover_data={"date": "|%B %d, %Y"},title='custom tick labels') fig.update_xaxes(dtick="M1",tickformat="%b\n%Y") fig.show()

from dash import Dash, dcc, html, Input, Output, callback, dash_table import plotly.express as px app = Dash(__name__, suppress_callback_exceptions=True) import pandas as pd from example import *df2 = read_example_csv()# dataframe for total energy frame df3 d = {'Energy consumed': [1], 'Current energy': [3],'Current power': [3],'Current cost': [3]} df3=pd.DataFrame(data=d)# test for period df_test = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')fig = px.line(df2, x=df2.index, y='Power', title='Time Series with Range Slider and Selectors')fig.update_xaxes(rangeslider_visible=True,rangeselector=dict(buttons=list([dict(count=1, label="1m", step="month", stepmode="backward"),dict(count=6, label="6m", step="month", stepmode="backward"),dict(count=1, label="YTD", step="year", stepmode="todate"),dict(count=1, label="1y", step="year", stepmode="backward"),dict(step="all")])) )app.layout = html.Div([dcc.Location(id='url', refresh=False),html.Div(id='page-content') ])index_page = html.Div([dcc.Link('Pie chart', href='/page-1'),html.Br(),dcc.Link('Line chart', href='/page-2'),html.Br(),dcc.Link('Table', href='/page-3'), ])page_1_layout = html.Div([html.H1('Page 1'),dcc.Graph(figure=px.pie(df2, values='Power', names='Machine')),html.Div(id='page-1-content'),html.Br(),dcc.Link('Go to Line chart', href='/page-2'),html.Br(),dcc.Link('Go back to home', href='/'), ])@callback(Output('page-1-content', 'children'),[Input('page-1-dropdown', 'value')]) def page_1_dropdown(value):return f'You have selected {value}'page_2_layout = html.Div([html.H1('Page 2'),# dcc.Graph(# figure = px.line(df2, x=df2.index, y='Power', title='Time Series with Range Slider and Selectors')# ),dcc.Graph(figure=dict(data=[dict(x=df2.index,y=df2['Power'].loc[df2['Machine'] == 'robot1'], # df.loc[df['column_name'] == some_value]name='Robot 1',marker=dict(color='rgb(55, 83, 109)')),dict(x=df2.index,y=df2['Power'].loc[df2['Machine'] == 'robot2'], # df.loc[df['column_name'] == some_value]name='Robot 2',marker=dict(color='rgb(26, 118, 255)'))],layout=dict(title='Robot Power',showlegend=True,legend=dict(x=0,y=1.0),margin=dict(l=40, r=0, t=40, b=30))),style={'height': 300},id='my-graph'),html.Div(id='page-2-content'),html.Br(),dcc.Link('Go to Pie Chart', href='/page-1'),html.Br(),dcc.Link('Go back to home', href='/') ])@callback(Output('page-2-content', 'children'),[Input('page-2-radios', 'value')]) def page_2_radios(value):return f'You have selected {value}'page_3_layout = html.Div([html.H1('Page 3'),dash_table.DataTable(df3.to_dict('records'), [{"name": i, "id": i} for i in df3.columns]),html.Div(id='page-3-content'),html.Br(),dcc.Link('Go to Line chart', href='/page-3'),html.Br(),dcc.Link('Go back to home', href='/'), ])@callback(Output('page-3-content', 'children'),[Input('page-3-dropdown', 'value')]) def page_3_dropdown(value):return f'You have selected {value}'# Update the index @callback(Output('page-content', 'children'),[Input('url', 'pathname')]) def display_page(pathname):if pathname == '/page-1':return page_1_layoutelif pathname == '/page-2':return page_2_layoutelif pathname == '/page-3':return page_3_layoutelse:return index_page# You could also return a 404 "URL not found" page hereif __name__ == '__main__':app.run_server(debug=True) # Here add all required functions. example.py import pandas as pddef cost_function(df, dt=1, start='08:30:00', end='22:30:00', low_price=0.08, high_price=0.121):low1 = df.between_time('00:00:00', start)high = df.between_time(start, end)low2 = df.between_time(end, '23:59:59')# Calculate energy consumption(kWh) during different periodsenergy_low = (low1.Power.sum() + low2.Power.sum()) / (36 * 10 ** 5)energy_high = (high.Power.sum()) / (36 * 10 ** 5)cost_low = energy_low * low_pricecost_high = energy_high * high_pricecost = cost_low + cost_highreturn costdef read_example_csv():df = pd.read_csv('example_data.csv', sep=',', index_col=0, parse_dates=True)return dfdef state(current_power, threshold_dictionary={"off": [0, 200], "idle": [201, 500], "on": [501]}):off_upper_limit = threshold_dictionary.get("off")[1]idle_lower_limit = off_upper_limit + 1idle_upper_limit = threshold_dictionary.get("idle")[1]on_lower_limit = idle_upper_limit + 1if (current_power >= on_lower_limit):return "On"elif (current_power >= 201):return "Idle"else:return "Off"def current_power(df):latest_time_df = df.index.max().strftime('%Y-%m-%d %X')total_current_power = latest_time_df.Power.sum()return total_current_powerdef predict_cost(df):"""need to upate"""return cost_function(df)def summary(dataframe):total_energy = dataframe.Power.sumtotal_cost = cost_function(dataframe)instantaneous_power = current_power(dataframe)expected_cost = predict_cost(dataframe)data_dict = {"Total_Energy": total_energy, "Total_cost": total_cost, "Current_Power": instantaneous_power,"Expected_Cost": expected_cost}return data_dict

Notes from Python Dash

[外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-m3aXUuD6-1644684167119)(…/…/Library/Application%20Support/typora-user-images/image-20220212163814079.png)]

[外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-oQ6Y7J95-1644684167119)(…/…/Library/Application%20Support/typora-user-images/image-20220212163835117.png)]

[外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-cQpw81KP-1644684167119)(…/…/Library/Application%20Support/typora-user-images/image-20220212163913676.png)]

pd.read_csv('file_name.csv', usecols= ['column_name1','column_name2']) pd.read_csv(path_to_import,usecols=columns, sep=';').to_csv('selected.csv', index=False) df.rename({'a': 'X', 'b': 'Y'}, axis=1, inplace=True) dfX Y c d e 0 x x x x x 1 x x x x x 2 x x x x x

Functions.py

max(list) import plotly.express as px # This dataframe has 244 lines, but 4 distinct values for `day` df = px.data.tips() fig = px.pie(df, values='tip', names='day') fig.show() Date-Time,Power,Machine 12/02/2022 00:00:00,1321.08,robot1 12/02/2022 00:00:01,28354.84,robot1 12/02/2022 00:00:02,6677.94,robot1 12/02/2022 00:00:03,1598.42,robot1 12/02/2022 00:00:04,438.78,robot1 12/02/2022 00:00:05,296.18,robot1 12/02/2022 00:00:06,269.7,robot1 12/02/2022 00:00:07,160.68,robot1 12/02/2022 00:00:08,270.38,robot1 12/02/2022 00:00:09,274.82,robot1 12/02/2022 00:00:10,271.99,robot1 12/02/2022 00:00:11,273.28,robot1 12/02/2022 00:00:12,121.88,robot1 12/02/2022 00:00:13,261.44,robot1 12/02/2022 00:00:14,252.33,robot1

from dash import Dash, dcc, html, Input, Output
import plotly.express as px

import pandas as pd

df = pd.read_csv(‘https://raw.githubusercontent.com/plotly/datasets/master/gapminderDataFiveYear.csv’)

app = Dash(name)

app.layout = html.Div([
dcc.Graph(id=‘graph-with-slider’),
dcc.Slider(
df[‘year’].min(),
df[‘year’].max(),
step=None,
value=df[‘year’].min(),
marks={str(year): str(year) for year in df[‘year’].unique()},
id=‘year-slider’
)
])

@app.callback(
Output(‘graph-with-slider’, ‘figure’),
Input(‘year-slider’, ‘value’))
def update_figure(selected_year):
filtered_df = df[df.year == selected_year]

fig = px.scatter(filtered_df, x="gdpPercap", y="lifeExp",size="pop", color="continent", hover_name="country",log_x=True, size_max=55)fig.update_layout(transition_duration=500)return fig

if name == ‘main’:
app.run_server(debug=True)

from dash import Dash, dash_table
import pandas as pd

df = pd.read_csv(‘https://raw.githubusercontent.com/plotly/datasets/master/solar.csv’)

app = Dash(name)

app.layout = dash_table.DataTable(df.to_dict(‘records’), [{“name”: i, “id”: i} for i in df.columns])

if name == ‘main’:
app.run_server(debug=True)

d = {'col1': [1, 2], 'col2': [3, 4]} df = pd.DataFrame(data=d) dfcol1 col2 0 1 3 1 2 4

總結

以上是生活随笔為你收集整理的Visualization Document Feb 12 16:42的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 粉嫩欧美一区二区三区 | 久久视频精品 | 欧美第一页 | 精品无码一区二区三区蜜臀 | 黄频网站在线观看 | 午夜两性视频 | 国产福利小视频在线 | 伊人影院综合 | 人妻无码一区二区三区 | 国产成人高清视频 | 日本在线中文 | 影音先锋成人 | 又黄又色又爽 | 亚洲AV午夜成人片 | 三级在线看中文字幕完整版 | 综合伊人 | 国产美女网 | 久久精品九九 | 亚洲综合一区在线观看 | 色www亚洲国产张柏芝 | 欧美大肚乱孕交hd孕妇 | 91av在线播放 | 蜜臀av无码精品人妻色欲 | 中文字幕精品久久久久人妻红杏ⅰ | 色噜噜一区二区三区 | 成人小视频在线播放 | 青青草原在线免费观看视频 | 成人性生活免费视频 | 五月网站 | 国产18在线观看 | 嫩草影院一区二区三区 | 亚洲国内在线 | 中文字幕人成乱码熟女香港 | 伦理黄色片 | 哪里可以免费看毛片 | 亚洲a人| 久久精品国产亚洲av高清色欲 | 色婷婷电影网 | 无码任你躁久久久久久老妇 | 午夜精品久久久久久久久久久 | 麻豆网站免费观看 | 都市激情校园春色亚洲 | 熟妇女人妻丰满少妇中文字幕 | 国产精品ww | 边吃奶边添下面好爽 | 一区二区片| 国产超碰 | 色噜噜综合网 | 色人天堂 | 日韩大片免费 | 国产人妖在线播放 | 国产精品xxxx喷水欧美 | 少妇的被肉日常np | 奶水旺盛的少妇在线播放 | 韩国三色电费2024免费吗怎么看 | 免费看黄色一级视频 | 久久久久国产 | 99精品久久毛片a片 成人网一区 | 中文字字幕一区二区三区四区五区 | 欧美乱论视频 | 欧日韩视频| 成人h在线观看 | 成人免费网站www网站高清 | 绿帽av| 免费观看视频一区 | 在线激情小视频 | 国产精品日韩电影 | 国产在线观看无码免费视频 | 久久久情 | 土耳其xxxx性hd极品 | 蜜臀久久99静品久久久久久 | 午夜精品久久久久久久99 | 在线观看av国产一区二区 | 亚洲视频一区二区三区 | 水蜜桃色314在线观看 | av一区二区三 | 久久久久亚洲精品中文字幕 | 夜夜嗨aⅴ一区二区三区 | 在线视频 一区二区 | 成人在线免费 | 性欧美另类| 少妇高潮21p| 色大师av一区二区三区 | 国产视频导航 | 国产xxxx做受性欧美88 | 色综合av在线 | 久久久99精品国产一区二区三区 | 久久免费播放 | 毛片高清免费 | 久久高清 | 中国女人毛茸茸 | 精品少妇人妻av一区二区 | 水密桃av| 成年人在线网站 | 国产成人精品视频一区二区 | 伦伦影院午夜理论片 | 日本一区二区三区视频在线观看 | 91麻豆精品国产91 | 蜜臀av免费一区二区三区水牛 |