Remove axis titles from Seaborn PairGrid

2019-08-03 19:19发布

问题:

I've tried using the answer to Hide Axis Titles in Seaborn, which applies to heatmap, but end up with two plots instead: the first being an empty grid without axis titles, the second being the PairGrid but still with axis titles. How can I hide the axis titles on the PairGrid?

import matplotlib.pyplot as plt
import seaborn as sns

iris = sns.load_dataset('iris')

fig, ax = plt.subplots(1, 1, figsize = (10, 10), dpi=300)
sns.PairGrid(iris).map_diag(sns.distplot)
ax.set_ylabel('')    
ax.set_xlabel('')

回答1:

Just loop through the subplots and clear the titles for each of them.

import matplotlib.pyplot as plt
import seaborn as sns

iris = sns.load_dataset('iris')

g = sns.PairGrid(iris).map_diag(sns.distplot)
for ax in g.axes.flatten():
    ax.set_ylabel('')
    ax.set_xlabel('')