3 回答

TA贡献1798条经验 获得超7个赞
您可以使用plotPandas 数据框的内置方法和subplots=True按列绘图的选项
from io import StringIO
import pandas as pd
import matplotlib.pyplot as plt
plt.style.use('seaborn')
# Here I read your example data in
df = pd.read_fwf(StringIO("""
X Y Z
0 1.000000 1.000000 1.014925
1 1.000000 1.000000 1.000000
"""), header=1, index_col=0)
# Plotting as desired
df.plot.hist(subplots=True, legend=False)
df.plot
需要很多其他参数来让你轻松地改变你的情节,例如
df.plot.hist(subplots=True, legend=True, layout=(1, 3))

TA贡献1824条经验 获得超8个赞
使用seaborn.FacetGrid可能需要您重构数据。
让我们看一个例子:
np.random.seed(0)
df = pd.DataFrame(np.random.randn(1000, 3), columns=['X', 'Y', 'Z'])
print(df.head(10))
X Y Z
0 1.764052 0.400157 0.978738
1 2.240893 1.867558 -0.977278
2 0.950088 -0.151357 -0.103219
3 0.410599 0.144044 1.454274
4 0.761038 0.121675 0.443863
5 0.333674 1.494079 -0.205158
6 0.313068 -0.854096 -2.552990
7 0.653619 0.864436 -0.742165
8 2.269755 -1.454366 0.045759
9 -0.187184 1.532779 1.469359
df_melted = df.melt(var_name='column')
print(df_melted.head(10))
column value
0 X 1.764052
1 X 2.240893
2 X 0.950088
3 X 0.410599
4 X 0.761038
5 X 0.333674
6 X 0.313068
7 X 0.653619
8 X 2.269755
9 X -0.187184
g = sns.FacetGrid(df_melted, row='column')
g.map(plt.hist, 'value')
[出去]

TA贡献1966条经验 获得超4个赞
sns.pairplot(your_df)会这样做,但是它也会向您显示每列的成对散点图,所以是的,它会做得比您需要的多一点?在进行探索性数据分析时很好。您还可以通过添加corner=True到呼叫来使其更清晰。
或者类似的东西:
# Update as needed
n_rows=1
n_cols=3
# Create the subplots
fig, axes = plt.subplots(nrows=n_rows, ncols=n_cols, figsize=(10, 10))
for i, column in enumerate(df):
sns.histplot(df, ax=axes[i // n_cols, i % n_cols]).set_title(column)
https://seaborn.pydata.org/generated/seaborn.pairplot.htma
添加回答
举报