如何用seaborn绘制曲线的平均值?

2024-03-28 20:03:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我想画一些点的平均值和它们的置信区间。我用的是seaborn。我试着使用regplot,lmplot,但是它们都不起作用。这是我的程序:

import pandas as pd
from matplotlib import pyplot as plt
import seaborn as sns
sns.set_style("darkgrid")
sns.set(color_codes=True)

df = pd.read_csv("data.csv")
print(df["a"])
sns.lineplot(y=df.a, x=df.index , data=df)
plt.ylabel("R")
plt.xlabel("T")
plt.show()

img

我的目标是得到图中的红线。 这是保存在csv Fila中的一个简单的数据帧

index     a
0      -0.120
1      -0.530
2      -0.250
3      -0.330
4      -0.560
5      -0.260
6       0.018
7       0.040
8      -0.460
9      -0.690
10     -0.130
11     -0.270
12     -0.080
13     -0.430
14     -0.170
15     -0.500
16     -0.690
17     -0.060
18     -0.200
19     -0.610
20     -0.370
21      0.090
22      0.190
23     -0.010
24      0.110
25     -0.250
26     -0.210
27     -0.160
28     -0.320
29      0.130
        ...  
2501    0.760
2502    0.690
2503    0.680
2504    0.750
2505    0.560
2506    0.570
2507    0.670
2508    0.800
2509    0.630
2510    0.570
2511    0.780
2512    0.800
2513    0.800

Tags: csvimportdfdataindexaspltseaborn