Categories
matplotlib pandas python

How to add a shared x-label and y-label to a plot created with pandas’ plot?

One can create subplots easily from a dataframe using pandas:

import pandas as pd
import matplotlib.pyplot as plt
df = pd.DataFrame({'A': [0.3, 0.2, 0.5, 0.2], 'B': [0.1, 0.0, 0.3, 0.1], 'C': [0.2, 0.5, 0.0, 0.7], 'D': [0.6, 0.3, 0.4, 0.6]}, index=list('abcd'))
ax = df.plot(kind="bar", subplots=True, layout=(2, 2), sharey=True, sharex=True, rot=0, fontsize=20)

How would one now add the x- and y-labels to the resulting plot? Here it is explained for a single plot. So if I wanted to add labels to a particular subplot I could do:

ax[1][0].set_xlabel('my_general_xlabel')
ax[0][0].set_ylabel('my_general_ylabel')
plt.show()

That gives:

enter image description here

How would one add the labels so that they are centred and do not just refer to a one row/column?