我正在嘗試在我的散點圖中添加一條線性回歸線,但是我的資料存盤和/或結構化的方式使這項任務對我來說非常棘手。我設法使用“sns.scatterplot”用我的資料創建了一個散點圖,但無法使用“sns.regplot”復制它。
通過使用以下代碼,我能夠生成如下圖:
sns.set_theme(color_codes=True)
sns.scatterplot(x=100, y=dict_all_mv['dict_100'])
sns.scatterplot(x=90, y=dict_all_mv['dict_90'])
sns.scatterplot(x=80, y=dict_all_mv['dict_80'])
sns.scatterplot(x=60, y=dict_all_mv['dict_60'])
sns.scatterplot(x=40, y=dict_all_mv['dict_40'])
sns.scatterplot(x=20, y=dict_all_mv['dict_20'])
plt.show()

y 軸上顯示的資料存盤在嵌套字典中。其中一本詞典的型別和字樣如下所示:
print(type(dict_all_mv['dict_100']))
print(dict_all_mv['dict_100'])
<class 'dict'>
{'P1S1': 0.2825781935483871, 'P2S1': 0.1566529827586207, 'P3S1': 0.16534197660818717, 'P4S1': 0.2463573039215686, 'P5S1': 0.21233809917355378, 'P6S1': 0.2780758316831682, 'P7S1': 0.261270830357143, 'P8S1': 0.25920007258064504, 'P9S1': 0.17294190131578946, 'P10S1': 0.18588214503816788, 'P1S2': 0.1870260291970803, 'P2S2': 0.2059823125, 'P3S2': 0.17782266216216217, 'P4S2': 0.1835217697841726, 'P5S2': 0.21022608870967743, 'P6S2': 0.2695895306122449, 'P7S2': 0.2393472735042735, 'P8S2': 0.18402302247191013, 'P9S2': 0.17260260273972605, 'P10S2': 0.20730387826086952}
I want to plot all the values stored in each dictionaries on the y axis, while the x axis values are equals to 100 for each values of 'dict_100', 90 for each values of 'dict_90', 80 for 'dict_80', etc. I have tried some options to plot a linear regression line with sns.regplot and lmplot, but without any success. Here is one of my failed attempts :
sns.regplot(x=100,y=dict_all_mv['dict_100'])
sns.regplot(x=90,y=dict_all_mv['dict_90'])
sns.regplot(x=80,y=dict_all_mv['dict_80'])
plt.show()
I got this error message :
AttributeError: 'int' object has no attribute 'shape'
My goal is to obtain a graph like this one:

轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/451524.html
標籤:python matplotlib seaborn linear-regression scatter-plot
下一篇:在python中影片移動方塊
