%matplotlib inline import numpy as np import matplotlib.pyplot as plt def funky_formatting(ax): ax.set_xticks([0.1, 0.2, 0.5, 0.7, 0.9]) ax.set_xticklabels(list('ABCDE'), rotation=60) ax.set_xticks([0.3, 0.4, 0.6, 0.8], minor=True) ax.set_xticklabels(list('abce'), rotation=30, minor=True) ax.set_yticks([0.2, 0.5, 0.7, 0.8]) ax.set_yticklabels(list('WXYZ'), rotation=35) ax.set_yticks([0.3, 0.4, 0.6], minor=True) ax.set_yticklabels(list('xyz'), rotation=80, minor=True) ax.tick_params(axis='both', labelsize=18, labelcolor='r', direction='out') ax.tick_params(axis='both', labelsize=12, labelcolor='g', direction='out', which='minor') ax.set_ylabel('r$y_{\mathrm{ii}}$ test', color='b', fontweight='extra bold', fontsize=20) ax.set_xlabel('r$y_{\mathrm{ii}}$ test', color='r', fontweight='light', fontsize=16) def offset_spines(ax): for spine in ax.spines.values(): spine.set_position(('outward', 10)) # create two axes fig, axes = plt.subplots(nrows=2, figsize=(8, 5)) # format both axes the same way: for ax in axes: ax.plot([0.2, 0.4, 0.6], [0.3, 0.7, 0.5], 'ko') funky_formatting(ax) # offset the spines of only the top subplot offset_spines(axes[0]) fig.tight_layout() def try_update(artist, p): for k, v in p.items(): try: artist.update({k: v}) except: pass def offset_spines_2(ax): for spine in ax.spines.values(): paxis = spine.axis.properties() ptick = [label.properties() for label in spine.axis.get_ticklabels()] spine.set_position(('outward', 10)) try_update(spine.axis, paxis) for label, p in zip(spine.axis.get_ticklabels(), ptick): p.pop("transform") try_update(label, p) # create two axes fig, axes = plt.subplots(nrows=2, figsize=(8, 5)) # format both axes the same way: for ax in axes: funky_formatting(ax) # offset the spines of only the top subplot offset_spines_2(axes[0]) fig.tight_layout()