4

With seaborn.PairGrid is there a way to show the axes tick-labels for each subplot? (an equivalent to sharex=False, sharey=False in case of seaborn.FacetGrid)

import pandas as pd
import numpy as np    
import seaborn as sns
import matplotlib.pyplot as plt

df = pd.DataFrame()
for n in ['a', 'b']:
    tmp = pd.DataFrame({'name': [n] * 100,
                        'prior': [1, 10] * 50,
                        'post': [1, 10] * 50})
    df = df.append(tmp)

g = sns.PairGrid(df, hue='name', diag_sharey=False)
g.map_offdiag(sns.regplot, fit_reg=False, x_jitter=.1)
g.map_diag(sns.distplot, kde=False)
Antoine Gautier
  • 623
  • 8
  • 25

3 Answers3

3

Answer found here: http://stackoverflow.xluat.com/questions/31094436/show-y-ticklabels-in-a-seaborn-pairplot

for ax in g.axes.flat:
    _ = plt.setp(ax.get_yticklabels(), visible=True)
    _ = plt.setp(ax.get_xticklabels(), visible=True)

Where it is precised that _ = ... is here to suppress unwanted print out in interactive environments.

Antoine Gautier
  • 623
  • 8
  • 25
  • 1
    Getting this error in PairGrid : ```AttributeError: 'NoneType' object has no attribute 'get_yticklabels'``` Any suggestions or am I 5 yrs too late :D? – rahul-ahuja Feb 28 '21 at 02:46
0

Have you tried set a style with sns.set_style("ticks") ?

More details about controlling figure aesthetics: http://stanford.edu/~mwaskom/software/seaborn/tutorial/aesthetics.html

art
  • 181
  • 1
  • 9
  • I edited my question to clarify: I meant the axes tick-labels. They are only displayed on the main plot axes. I want them on each subplot. – Antoine Gautier Jun 30 '15 at 18:39
0

I would call .set on the pairplot PairGrid

g = sns.pairplot(...)
g.set(xticklabels=[], yticklabels=[])
Filippo Vitale
  • 7,597
  • 3
  • 58
  • 64