subplots : boolean, default False
Make separate subplots for each column
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# 創建一個 DataFrame
df = pd.DataFrame(np.random.randn(1000, 3),
columns=['A', 'B', 'C'])
ax=df.plot( subplots=False )
通常是畫這種疊圖:

df:

ax=df.plot( subplots=True )

三張子圖畫在同一張圖中
以下也是三張子圖畫在同一張圖中:

plt.show()之前加一行:
plt.subplots_adjust ( hspace=1 )
可以調整子圖間的間距
hspace参数被用来调整垂直间距。
如果要调整水平间距,可以使用wspace参数
h代表的是 height(高度,不是horizontal 水平),
而 w 则代表 width(宽度)

需要三個fig物件,才能畫三張分開的圖
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# 創建一個 DataFrame
df = pd.DataFrame(np.random.randn(1000, 3),
columns=['A', 'B', 'C'])
# 繪製第一個圖
fig1, ax1 = plt.subplots()
df['A'].plot(kind='line', ax=ax1)
ax1.set_title('Line plot')
ax1.set_xlabel('X label')
ax1.set_ylabel('Y label')
# 繪製第二個圖
fig2, ax2 = plt.subplots()
df['B'].plot(kind='hist', ax=ax2)
ax2.set_title('Histogram')
ax2.set_xlabel('X label')
ax2.set_ylabel('Y label')
# 繪製第三個圖
fig3, ax3 = plt.subplots()
df.plot(kind='scatter', x='A', y='B', ax=ax3)
ax3.set_title('Scatter plot')
ax3.set_xlabel('X label')
ax3.set_ylabel('Y label')
# 顯示圖形
plt.show()

輸出結果:

推薦hahow線上學習python: https://igrape.net/30afN


![Python: pandas.DataFrame()處理雙維度資料,dict跟2D list轉為DataFrame有何差別?如何用index及columns屬性客製化index跟欄位名稱?df.index = [“一”,”二”,”三”,”四”] ; df.columns = 使用.head(n) ; .tail(m) ;取首n列,尾m列; .at[index,欄位名稱] 取單一資料 ; .iat[index,欄位順序] 取單一資料 ; .loc[index,欄位名稱] 取資料 ; .iloc[index,欄位順序];df.iloc[ [0,1],[0,2]])取資料 ; df.iloc[ 0:3,0:2]切片 Python: pandas.DataFrame()處理雙維度資料,dict跟2D list轉為DataFrame有何差別?如何用index及columns屬性客製化index跟欄位名稱?df.index = [“一”,”二”,”三”,”四”] ; df.columns = 使用.head(n) ; .tail(m) ;取首n列,尾m列; .at[index,欄位名稱] 取單一資料 ; .iat[index,欄位順序] 取單一資料 ; .loc[index,欄位名稱] 取資料 ; .iloc[index,欄位順序];df.iloc[ [0,1],[0,2]])取資料 ; df.iloc[ 0:3,0:2]切片](https://i2.wp.com/savingking.com.tw/wp-content/uploads/2022/11/20221111093547_79.png?quality=90&zoom=2&ssl=1&resize=350%2C233)


![Python如何讀取*.jsonl (JSON Lines)? 讀取為List[dict] Python如何讀取*.jsonl (JSON Lines)? 讀取為List[dict]](https://i0.wp.com/savingking.com.tw/wp-content/uploads/2023/10/20231024225613_30.png?quality=90&zoom=2&ssl=1&resize=350%2C233)






近期留言