首页 > 解决方案 > 如何在 seaborn Pairplot 中设置 x 轴大小

问题描述

我正在使用 Seaborn 来绘制 Pairplots。问题是,对于某些变量,x 轴的大小很小,数据点彼此非常接近,如下所示(第一行图):

在此处输入图像描述

如您所见,第二行中的图很好。

这是我正在使用的代码:

import math
import matplotlib.pyplot as plt
import seaborn as sns

y_name = 'y'
features = data.iloc[:, :-1]
features_names = features.columns   
  
plot_size=7
num_plots_x=10   # No. of plots in every row
num_plots_y = math.ceil(len(features_names)/num_plots_x)   # No. of plots in y direction

fig = plt.figure(figsize=(plot_size*num_plots_y, plot_size*num_plots_x), facecolor='white')
axes = [fig.add_subplot(num_plots_y,1,i+1) for i in range(num_plots_y)]   

for i, ax in enumerate(axes):   
    start_index = i * num_plots_x
    end_index = (i+1) * num_plots_x
    if end_index > len(features_names): end_index = len(features_names)
    sns.pairplot(x_vars=features_names[start_index:end_index], y_vars=y_name, data = data)

plt.savefig('figure.png')

有什么方法可以设置 x 轴的大小或比例?

标签: pythonplotseabornscalingx-axis

解决方案


推荐阅读