I have a series of subplots, and I want them to share x and y axis in all but 2 subplots (on a per-row basis).
I know that it is possible to create all subplots sepa
You can access the group of shared axes using either ax.get_shared_x_axes() or by the property ax._shared_y_axes. You can then reset the visibility of the labels using xaxis.set_tick_params(which='both', labelleft=True) or using setp(ax, get_xticklabels(), visible=True) however both of these methods suffer from the same innate problem: the tick formatter is still shared between the axes. As far as I know there is no way around this. Here is an example to demonstrate:
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(1)
fig, axs = plt.subplots(2, 2, sharex='row', sharey='row', squeeze=False)
axs[0][0]._shared_x_axes.remove(axs[0][0])
axs[0][0]._shared_y_axes.remove(axs[0][0])
for ii in range(2):
for jj in range(2):
axs[ii][jj].plot(np.random.randn(100), np.linspace(0,ii+jj+1, 100))
axs[0][1].yaxis.set_tick_params(which='both', labelleft=True)
axs[0][1].set_yticks(np.linspace(0,2,7))
plt.show()