Fix Python – Common xlabel/ylabel for matplotlib subplots


Asked By – jolindbe

I have the following plot:

fig,ax = plt.subplots(5,2,sharex=True,sharey=True,figsize=fig_size)

and now I would like to give this plot common x-axis labels and y-axis labels. With “common”, I mean that there should be one big x-axis label below the whole grid of subplots, and one big y-axis label to the right. I can’t find anything about this in the documentation for plt.subplots, and my googlings suggest that I need to make a big plt.subplot(111) to start with – but how do I then put my 5*2 subplots into that using plt.subplots?

Now we will see solution for issue: Common xlabel/ylabel for matplotlib subplots


This looks like what you actually want. It applies the same approach of this answer to your specific case:

import matplotlib.pyplot as plt

fig, ax = plt.subplots(nrows=3, ncols=3, sharex=True, sharey=True, figsize=(6, 6))

fig.text(0.5, 0.04, 'common X', ha='center')
fig.text(0.04, 0.5, 'common Y', va='center', rotation='vertical')

Multiple plots with common axes label

This question is answered By – divenex

This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0