Show y_ticklabels in nautical pair with common axes

I am using a pair-sided pair to plot multiple independent variables relative to the dependent variable.

import seaborn as sns
iris = sns.load_dataset("iris")
x_vars = ['sepal_length', 'sepal_width', 'petal_length']
y_vars = ['petal_width']
pp = sns.pairplot(data=iris, x_vars=x_vars, y_vars=y_vars)

      

enter image description here

Now I want to add y-axes and y-labels to the second and third subplots.

Adding Y-axis labels is easy:

pp.set(ylabel='petal_width')

      

enter image description here

But I can't for the life of me figure out how to show y_ticklabels.

Things like:

pp.set(yticklabels=np.arange(-0.5, 3.01, 0.5))

      

or

for i in range(3):
    ax = pp.axes[0,i]
    ax.set_yticks(np.arange(-0.5, 3.01, 0.5))
    ax.set_yticklabels(np.arange(-0.5, 3.01, 0.5))
    ax.set_visible(True)

      

irrelevant.

+3


source to share


2 answers


Just turn yticklabels

back to visible and you're good to go at the desired subheading:

import seaborn as sns
iris = sns.load_dataset("iris")
x_vars = ['sepal_length', 'sepal_width', 'petal_length']
y_vars = ['petal_width']
pp = sns.pairplot(data=iris, x_vars=x_vars, y_vars=y_vars)
_ = plt.setp(pp.axes[0,1].get_yticklabels(), visible=True) #changing the 2nd plot

      



_ = ...

here is to suppress unwanted printing in interactive environments. enter image description here

+3


source


3.0.3 is my version of matplotlib and CT Zhu's answer didn't work for me and I don't know why.

I found the answer here .

You can use the method tick_params

on your desired subplot to show yticklabels

by passing a parameter labelleft=True

. (there are 2 ways)


"""enabling yticklabels for all subplots"""

import seaborn as sns
iris = sns.load_dataset("iris")
x_vars = ['sepal_length', 'sepal_width', 'petal_length']
y_vars = ['petal_width']
pp = sns.pairplot(data=iris, x_vars=x_vars, y_vars=y_vars)

# iterating over all subplots
for ax in pp.axes.flat:
    # labelleft refers to yticklabels on the left side of each subplot
    ax.tick_params(axis='y', labelleft=True) # method 1
    # ax.yaxis.set_tick_params(labelleft=True) # method 2
plt.show()

      




enabling yticklabels for shared axes

From the docs tick_params

.

Change the appearance of ticks, tick marks and grid lines.

0


source







All Articles