我有这四个数据集,例如df1。我想将它们打印为散点图,例如2 * 2。
df1
Height time_of_day resolution clusters
11 3.146094 0.458333 0.594089 0
90 0.191690 0.541667 0.594089 0
99 1.300386 1.666667 0.594089 1
121 3.054903 2.083333 0.594089 0
df2
Height time_of_day resolution clusters
10 3.146094 0.458333 0.594089 0
60 3.191690 0.541667 0.594089 0
87 1.300386 1.666667 0.594089 1
121 3.054903 1.083333 0.594089 0
df3
Height time_of_day resolution clusters
13 3.146094 0.458333 0.594089 0
61 3.191690 0.541667 0.594089 0
86 1.300386 1.666667 0.594089 1
113 4.054903 1.083333 0.594089 0
df4
Height time_of_day resolution clusters
10 3.146094 0.458333 0.594089 0
20 3.191690 0.541667 0.594089 0
37 1.300386 1.666667 0.594089 1
121 3.054903 1.083333 0.594089 0
我尝试了几种方法,但所有方法都不起作用。
dics = [df1,df2,df3,df4]
rows = range(4)
fig, ax = plt.subplots(2,2,squeeze=False,figsize = (20,10))
for x in rows:
for i,dic in enumerate(dics):
sns.lmplot(x="time_of_day", y="Height",fit_reg=False,hue="clusters", data=dic[x], height=6, aspect=1.5)
plt.show()
这是散点图的单一代码
sns.lmplot(x="time_of_day", y="Height",fit_reg=False,hue="clusters", data=summer_spike_df, height=6, aspect=1.5)
我应该更改什么代码才能打印成具有不同散点图结果的2 * 2? 谢谢
答案 0 :(得分:1)
如果您不绘制回归线,那为什么不直接使用seaborn.scatterplot
。
您可以使用zip
函数和array.ravel
进行以下绘制:
fig, axes = plt.subplots(2,2,squeeze=False,figsize = (20,10))
for df, ax in zip(dics, axes.ravel()):
sns.scatterplot(x="time_of_day", y="Height",hue="clusters", data=df, ax=ax)
plt.show()