使用此代碼,我創建了一個 seaborn 圖來可視化長格式資料集中的多個變數。
import pandas as pd
import seaborn as sns
data = {'Patient ID': [11111, 11111, 11111, 11111, 22222, 22222, 22222, 22222, 33333, 33333, 33333, 33333, 44444, 44444, 44444, 44444, 55555, 55555, 55555, 55555],
'Lab Attribute': ['% Saturation- Iron', 'ALK PHOS', 'ALT(SGPT)', 'AST (SGOT)', '% Saturation- Iron', 'ALK PHOS', 'ALT(SGPT)', 'AST (SGOT)', '% Saturation- Iron', 'ALK PHOS', 'ALT(SGPT)', 'AST (SGOT)', '% Saturation- Iron', 'ALK PHOS', 'ALT(SGPT)', 'AST (SGOT)', '% Saturation- Iron', 'ALK PHOS', 'ALT(SGPT)', 'AST (SGOT)'],
'Baseline': [46.0, 94.0, 21.0, 18.0, 56.0, 104.0, 31.0, 12.0, 50.0, 100.0, 33.0, 18.0, 46.0, 94.0, 21.0, 18.0, 46.0, 94.0, 21.0, 18.0],
'3 Month': [33.0, 92.0, 19.0, 25.0, 33.0, 92.0, 21.0, 11.0, 33.0, 102.0, 18.0, 17.0, 23.0, 82.0, 13.0, 17.0, 23.0, 82.0, 13.0, 17.0],
'6 Month': [34.0, 65.0, 10.0, 14.0, 34.0, 65.0, 10.0, 14.0, 34.0, 65.0, 10.0, 14.0, 34.0, 65.0, 10.0, 14.0, 34.0, 65.0, 10.0, 14.0]}
df = pd.DataFrame(data)
# reshape the dataframe
dfm = df_labs.melt(id_vars=['Patient_ID', 'Lab_Attribute'], var_name='Months')
# change the Months values to numeric
dfm.Months = dfm.Months.map({'Baseline': 0, '3 Month': 3, '6 Month': 6})
# plot a figure level line plot with seaborn
p = sns.relplot(data=dfm, col='Lab_Attribute', x='Months', y='value', hue='Patient_ID', kind='line', col_wrap=5, marker='o', palette='husl',facet_kws={'sharey': False, 'sharex': True},err_style="bars", ci=95,)
plt.savefig('gmb_nw_labs.jpg')
繪圖效果很好,但由于某種原因,即使在添加后,誤差條也沒有顯示:
err_style="bars", ci=95,
到 sns.replot()
p = sns.relplot(data=dfm, col='Lab_Attribute', x='Months', y='value', hue='Patient_ID', kind='line', col_wrap=5, marker='o', palette='husl',facet_kws={'sharey': False, 'sharex': True},err_style="bars", ci=95,)
誰能告訴我這是為什么,我的資料集中的資料點可能太少了嗎?
uj5u.com熱心網友回復:
- 每個資料點由 分隔
hue,因此沒有錯誤條,因為沒有組合資料。洗掉hue='Patient ID'以僅顯示平均線和誤差線。 - 或者,
- 原始實作沒有
hue='Patient ID'
p = sns.relplot(data=dfm, col='Lab Attribute', x='Months', y='value', kind='line', col_wrap=3, marker='o', palette='husl', facet_kws={'sharey': False, 'sharex': True}, err_style="bars", ci=95)
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/362629.html標籤:Python 熊猫 matplotlib 海生 错误栏
- 原始實作沒有
