Moving Graph Titles in the Y axis of Subplots

Viewed 34

This question is adapted from this answer, however the solution provided does not work and following is my result. I am interested in adding individual title on the right side for individual subgraphs.

(p.s no matter how much offset for y-axis i provide the title seems to stay at the same y-value)

from matplotlib import pyplot as plt
import numpy as np

fig, axes = plt.subplots(nrows=2)
ax0label = axes[0].set_ylabel('Axes 0')
ax1label = axes[1].set_ylabel('Axes 1')

title = axes[0].set_title('Title')

offset = np.array([-0.15, 0.0])
title.set_position(ax0label.get_position() + offset)
title.set_rotation(90)

fig.tight_layout()
plt.show()

enter image description here

1 Answers

Something like this? This is the only other way i can think of.

from matplotlib import pyplot as plt
import numpy as np

fig, axes = plt.subplots(nrows=2)
ax0label = axes[0].set_ylabel('Axes 0')
ax1label = axes[1].set_ylabel('Axes 1')
ax01 = axes[0].twinx()
ax02 = axes[1].twinx()
ax01.set_ylabel('title')
ax02.set_ylabel('title')


fig.tight_layout()
plt.show()

right labels

Related