在Seabor中实现折线图有两种。一种是在relplot()函数中的kind参数设置line就可以,另一种是lineplot()函数来可以直接实现折线图。通过relplot来实现
import matplotlib.pyplot as plt
import seaborn as sns
# 数据集
data = sns.load_dataset("fmri")
print(data.head())
# 绘画折线图
sns.relplot(x="timepoint", y="signal", kind="line", data=data, ci=None)
# 显示
plt.show()
运行结果:
subject timepoint event region signal
0 s13 18 stim parietal -0.017552
1 s5 14 stim parietal -0.080883
2 s12 18 stim parietal -0.081033
3 s11 18 stim parietal -0.046134
4 s10 18 stim parietal -0.037970
显示效果:
通过lineplot()函数来实现
import matplotlib.pyplot as plt
import seaborn as sns
# 数据集
data = sns.load_dataset("fmri")
print(data.head())
# 绘画折线图:
sns.lineplot(x="timepoint", y="signal", data=data, ci=95)
# 显示
plt.show()
运行结果是上面一样,如下是显示效果:
多坐标效果
import matplotlib.pyplot as plt
import seaborn as sns
# 数据集
data = sns.load_dataset("fmri")
print(data.head())
# 绘画折线图
f, axes = plt.subplots(nrows=1, ncols=3, figsize=(14, 6))
sns.lineplot(x="timepoint", y="signal", data=data, ci=95, ax=axes[0])
sns.lineplot(x="timepoint", y="signal", hue="region", style="event", data=data, ci=None, ax=axes[1])
sns.relplot(x="timepoint", y="signal", data=data, ci=None, kind="line", ax=axes[2])
plt.show()
显示效果:
通过relplot来实现