[英]How to plot these histograms next to each other
具有 3 列的樣本數據:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
d = {'col1': [1, 2, 3, 4, 5, 6, 3, 5],
'col2': [1, 2, 2, 2, 5, 6, 3, 5],
'col3': [1, 2, 2, 2, 2, 2, 2, 6], }
df = pd.DataFrame(data=d)
df
您可以使用 matplotlib 中的子圖來查看單獨直方圖上的每一列:
fig, axs = plt.subplots(len(df.columns), figsize=(8,12))
i=0
for x in df.columns.to_list():
axs[i].hist(df[x], bins=10)
i=i+1
為什么不只是df.hist(bins=120)
? 無需 go 通過循環。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.