How share title axis of multiples plot?

I´m looking to share the x-axis and y-axis in multiples plots. For this, I´m using a for loop to set the name of each axis:

for ax in axs.flat:
    ax.set(xlabel='Amino Acid Position', ylabel='Selection Score')

This line result in set the titles in each plot:

In the example plot, the title of each plot is in each y and x axis; however, I´m looking to share the title between all the y-axis and x-axis, I mean one “Selection Score” for all three y-axis and one “Amino Acid Position” for the three x-axis.
If you need, here is my complete script:

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import (AutoMinorLocator, MultipleLocator)

# This line create multiple plots, subp...(column, rows); with sharex you can fix
# each subplot x- or y-axis will be independent
# Figsize allow set the dimensions of the plots (shape)
fig, axs = plt.subplots(3, 1, sharex=True, sharey=True, figsize=(15, 9))
# Set the values in x-axis, only for the first plot
axs[0].set_xlim(0, 1200)
axs[0].set_ylim(-800, 200)
# Set the range of values in x-axis
# Set the labels for each axis
for ax in axs.flat:
    ax.set(xlabel='Amino Acid Position', ylabel='Selection Score')

# Set the values in the second y-axis
#axs[1].set_ylim(0, 9)
#axs[2].set_ylim(0, 9)

#def set_ylims(indices: list, vals: tuple):
 #   for i in indices: # For each passed index
  #      axs[i].set_ylim(0, 9)  # Unpack vals and call set_ylim()

# Set the line style in the plot
axs[0].grid(which='major', color='#CCCCCC', linestyle='--')
axs[1].grid(which='major', color='#CCCCCC', linestyle='--')
axs[2].grid(which='major', color='#CCCCCC', linestyle='--')
# This line fix the distribution of the plot (not overlap)

Please, omit the tags (#).
Is there a way to modify the .script to do that?

hi, will subxlabel or subylabel do the trick?

1 Like

Hi, thank you for your answer. I going to check the link that you share, I hope that works!