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.Series如何只保留str,去除重複值?#isinstance(x:Any, str) -> bool #.drop_duplicates() #Series.apply( function )逐元素應用function運算 #DataFrame.apply( function )逐Series應用function運算 .drop_duplicates() 跟.unique()有何差別? df.drop_duplicates() 等效於 df[~df.duplicated()] Python: pandas.Series如何只保留str,去除重複值?#isinstance(x:Any, str) -> bool #.drop_duplicates() #Series.apply( function )逐元素應用function運算 #DataFrame.apply( function )逐Series應用function運算 .drop_duplicates() 跟.unique()有何差別? df.drop_duplicates() 等效於 df[~df.duplicated()]](https://i0.wp.com/savingking.com.tw/wp-content/uploads/2024/11/20241123194900_0_5218de.png?quality=90&zoom=2&ssl=1&resize=350%2C233)
![Python struct.pack() 將整數轉換為bytes ; while list: str1=list[0] ; 中間內容; list=[1:] #切片 ,遍歷list中的每一個元素,跟for i in list 類似 ; timeit() #計時 Python struct.pack() 將整數轉換為bytes ; while list: str1=list[0] ; 中間內容; list=[1:] #切片 ,遍歷list中的每一個元素,跟for i in list 類似 ; timeit() #計時](https://i2.wp.com/savingking.com.tw/wp-content/uploads/2022/10/20221012095050_42.png?quality=90&zoom=2&ssl=1&resize=350%2C233)








近期留言