简体   繁体   English

seaborn 中带有子图的散点图

[英]Scatter plot with subplot in seaborn

I am new to python visualizations.我是 Python 可视化的新手。 I am trying to use draw two scatter plots side by side using the follow code, but couldn't.我正在尝试使用以下代码并排绘制两个散点图,但不能。

Also, can someone please provide me some good tutorials for seaborn/matplotlib.另外,有人可以为我提供一些关于 seaborn/matplotlib 的好教程。 I peaked into their documentation and its daunting我深入研究了他们的文档及其令人生畏的

plt.figure(figsize = (16, 12))
ax = plt.subplot(1,2,1)
sns.relplot(x="total_bill", y="tip", data=tips, ax= ax);
ax = plt.subplot(1,2,2)
sns.scatterplot(x="total_bill", y="tip", data=tips);

I get two plots, one above the another.我得到两个地块,一个在另一个之上。 The first plot is of good size, but the second plot below is not of the size as first and has very small x axis length第一个图的大小很好,但下面的第二个图没有第一个图的大小,并且 x 轴长度非常小

You didn't specify the ax parameter properly.您没有正确指定ax参数。 Give this a try:试试这个:

fig, (ax1,ax2) = plt.subplots(1,2, figsize=(16,6))

ax1.set_title('Latitute')
sns.scatterplot(x='price', y='lat', data=df, ax=ax1)

ax2.set_title('Longitude')
sns.scatterplot(x='price', y='long', data=df, ax=ax2)

You seemed to have left out your second ax parameter.您似乎遗漏了第二个ax参数。 Try:尝试:

plt.figure(figsize = (16, 12))
ax = plt.subplot(1,2,1)
sns.relplot(x="total_bill", y="tip", data=tips, ax= ax);
ax = plt.subplot(1,2,2)
sns.scatterplot(x="total_bill", y="tip", data=tips, ax= ax);
#Somthing like this should work
import numpy as np
import matplotlib.pyplot as plt

x1 = [1, 2, 3, 4, 5]
x2 = [1, 2, 3, 4, 5]
y1 = [1, 8, 27, 36, 125]
y2 = [1, 4, 9, 16, 25]

fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(5, 3))
axes[0].plot(x1, y1)
axes[1].plot(x2, y2)
fig.tight_layout()
plt.show()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM