0

I have a pairplot in Python. I like to add x-axis and y-axis ticks (i.e, numbers) to all boxes. So, the ticks and their labels at the bottom and left side of pairplot will repeat for each box. See the below pictures.

Thanks in advance!

What I have

enter image description here

what I want to have

enter image description here

Sad Vaseb
  • 299
  • 3
  • 10

1 Answers1

2

You can set ax.tick_params() and adjust the subplot spacing.

import matplotlib.pyplot as plt
import seaborn as sns

penguins = sns.load_dataset("penguins")

pp = sns.pairplot(
    penguins,
    x_vars=["bill_length_mm", "bill_depth_mm", "flipper_length_mm"],
    y_vars=["bill_length_mm", "bill_depth_mm"],
)
for ax in pp.axes.flat:
    ax.tick_params(axis='both', labelleft=True, labelbottom=True)
    
plt.subplots_adjust(wspace=0.3, hspace=0.3)

plt.show()

enter image description here

r-beginners
  • 31,170
  • 3
  • 14
  • 32
  • Thank you so much! It works perfectly but I have two problems. 1) how can I add labels to all boxes? 2) I use corner = True option to remove extra boxes; so I get "AttributeError: 'NoneType' object has no attribute 'tick_params'" How can I fix this? Thanks in advance! – Sad Vaseb Oct 15 '20 at 15:28
  • `pairplot()` did not work. Instead, you can use `PairGrid(despine=True)` to display a frame. You can use the following [answers](https://stackoverflow.com/questions/33377243/seaborn-pairgrid-show-axes-labels-for-each-subplot) for labels. – r-beginners Oct 16 '20 at 02:50