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

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

Plotly:在一張圖中出現(xiàn)單獨(dú)的圖

Plotly:在一張圖中出現(xiàn)單獨(dú)的圖

森林海 2022-10-06 18:54:40
我想分開(kāi)出現(xiàn)在最終圖表上的圖。我有醫(yī)院的數(shù)據(jù),這就是為什么我想分開(kāi)以便我有單獨(dú)的醫(yī)院圖表。每個(gè)醫(yī)院都有自己獨(dú)立的圖表。這是我的工作代碼# importsimport plotly.graph_objects as gofrom plotly.offline import iplotimport pandas as pdimport numpy as np# intialise data of lists. data = {'Name':['Nick hospital', 'Nick hospital','Nick hospital', 'Krish hospital', 'Krish hospital','Krish hospital'],         'NAR_forms_used':[2, 1,2, 2, 2,3]       } # Create DataFrame df = pd.DataFrame(data)# get counts per NAR typedf_nar=pd.DataFrame(df.groupby('Name')['NAR_forms_used'].value_counts())df_nar=df_nar.rename({'NAR_forms_used': 'NAR count'}, axis='columns')df_nar=df_nar.reset_index()# Manage NAR types (who knows, there may be more types with time?)nars = df_nar['NAR_forms_used'].unique()nars = nars.tolist()nars.sort(reverse=False)# set up plotly figurefig = go.Figure()# add one trace per NAR type and show counts per hospitalfor nar in nars:    # subset dataframe by NAR type    df_ply=df_nar[df_nar['NAR_forms_used']==nar]    # add trace    fig.add_trace(go.Bar(x=df_ply['Name'], y=df_ply['NAR count'], name='NAR Type='+str(nar)))# make the figure a bit more presentablefig.update_layout(title='NAR per hospital',                  yaxis=dict(title='<i>count of NAR types</i>'),                  xaxis=dict(title='<i>Hospital</i>',                            )                 )fig.show()如果您注意到最終圖表將所有醫(yī)院都放在一個(gè)圖表中,但我想將它們分開(kāi)并將每個(gè)醫(yī)院圖表分開(kāi),以便我可以使用醫(yī)院的下拉選擇添加到儀表板上。請(qǐng)幫助我在尼克醫(yī)院中分離這個(gè)圖表輸出以擁有自己的圖表,這與Krish 醫(yī)院相同
查看完整描述

1 回答

?
慕哥9229398

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

import plotly.graph_objects as go

import pandas as pd


df = pd.DataFrame({'Name': ['Nick hospital', 'Nick hospital', 'Nick hospital', 'Nick hospital', 'Nick hospital', 'Nick hospital',

                   'Krish hospital', 'Krish hospital', 'Krish hospital','Krish hospital', 'Krish hospital', 'Krish hospital'],

                   'NAR_forms_used': [2, 1, 3, 1, 1, 2, 1, 2, 3, 3, 3, 1]})


df_nar = pd.DataFrame(df.groupby('Name')['NAR_forms_used'].value_counts())

df_nar = df_nar.rename({'NAR_forms_used': 'NAR count'}, axis='columns')

df_nar = df_nar.reset_index()


nars = df_nar['NAR_forms_used'].unique()

nars = nars.tolist()

nars.sort(reverse=False)


# Nick hospital

fig1 = go.Figure()


for nar in nars:


    df_ply = df_nar[(df_nar['NAR_forms_used'] == nar) & (df_nar['Name'] == 'Nick hospital')]


    fig1.add_trace(go.Bar(y=df_ply['NAR count'], x=['NAR Type=' + str(nar)]))


fig1.update_layout(title='Nick hospital', showlegend=False, yaxis=dict(title='<i>count of NAR types</i>'))


fig1.show()


# Krish hospital

fig2 = go.Figure()


for nar in nars:


    df_ply = df_nar[(df_nar['NAR_forms_used'] == nar) & (df_nar['Name'] == 'Krish hospital')]


    fig2.add_trace(go.Bar(y=df_ply['NAR count'], x=['NAR Type=' + str(nar)]))


fig2.update_layout(title='Krish hospital', showlegend=False, yaxis=dict(title='<i>count of NAR types</i>'))


fig2.show()


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

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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