Rotating axis text for each subplot

Just iterate through the axes tied to the figure, set the active axes to the iterated object, and modify:

for ax in fig.axes:
    matplotlib.pyplot.sca(ax)
    plt.xticks(rotation=90)

plt only acts on the current active axes. You should bring it inside your last loop where you set some of the labels visibility to True:

# Turn on the proper x or y axes ticks.
for i, j in zip(range(numvars), itertools.cycle((-1, 0))):
    axes[j,i].xaxis.set_visible(True)
    axes[i,j].yaxis.set_visible(True)

    for tick in axes[i,j].get_xticklabels():
        tick.set_rotation(45)
    for tick in axes[j,i].get_xticklabels():
        tick.set_rotation(45)

Tags:

Matplotlib