[英]Scatter plot with subplot in seaborn
我是 Python 可視化的新手。 我正在嘗試使用以下代碼並排繪制兩個散點圖,但不能。
另外,有人可以為我提供一些關於 seaborn/matplotlib 的好教程。 我深入研究了他們的文檔及其令人生畏的
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);
我得到兩個地塊,一個在另一個之上。 第一個圖的大小很好,但下面的第二個圖沒有第一個圖的大小,並且 x 軸長度非常小
您沒有正確指定ax
參數。 試試這個:
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)
您似乎遺漏了第二個ax
參數。 嘗試:
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.