1

I am using Seaborn to draw Pairplots. Problem is that, for some variables, size of x-axis is small and data points are very close to each other, as can be seen below (first row of plots):

enter image description here

As you can see, plots in the second row are fine.

This is the code I am using:

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')

Is there any way that I can set size or scale of x-axis?

Mohammad
  • 775
  • 1
  • 14
  • 37
  • I suggest providing an [MCVE](https://stackoverflow.com/help/minimal-reproducible-example) so that we can try to address the root problem instead of tampering with axes objects. – Mr. T May 29 '21 at 06:45
  • I added the code I am using but I cannot share the dataset. Is it enough? – Mohammad May 29 '21 at 13:55
  • Even though I cannot run this code due to the missing input, it is unlikely this code created the graph. For 10 categories, it would create one subplot, and the seaborn pairplot does not receive the axis object into which it is supposed to plot. Try to create a dummy input for the MCVE that recreates your problem. – Mr. T May 29 '21 at 15:25

0 Answers0