[英]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.