My dataset consists of four variables (x, a, b, c), of which the latter three depend on the first. I want to show these in a single plot: three panels next to each other with plots of x against a, x against b, x against d, respectively.
Now, since x is the same for every plot, I want the ticklabels to show up only on the leftmost panel, so I used ax.set_yticklabels([])
to remove them from the second and third panel.
Here is the problem though: I want the three panels to have exactly the same width. However, the width of the plot is changed when adding or removing the tick labels.
Also, I would like to the three panels to be exactly centred. So far I have been calculating the exact positions of each axes to satisfy this, but I don't know the width of the ticklabels + ylabel and I was wondering if there is a more elegant way of solving this issue.
Many thanks!
T
Example:
fig = plt.figure(figsize=(10,5))
ax1 = fig.add_axes(0, 0, 0.3, 1])
ax1.plot(a, x)
ax1.xaxis.set_tick_params(which='major', size=5, width=1, direction='in', top='on')
ax1.yaxis.set_tick_params(which='major', size=5, width=1, direction='in', top='on')
ax1.invert_yaxis()
ax1.grid(ls=':')
ax2 = fig.add_axes([1/3+1/30, 0, 0.3, 1])
ax2.plot(b, x)
ax2.set_yticklabels([])
ax2.xaxis.set_tick_params(which='major', size=5, width=1, direction='in', top='on')
ax2.yaxis.set_tick_params(which='major', size=5, width=1, direction='in', top='on')
ax2.invert_yaxis()
ax2.grid(ls=':')
ax3 = fig.add_axes([2/3+1/30, 0, 0.3, 1])
ax3.plot(c, x)
ax3.set_yticklabels([])
ax3.xaxis.set_tick_params(which='major', size=5, width=1, direction='in', top='on')
ax3.yaxis.set_tick_params(which='major', size=5, width=1, direction='in', top='on')
ax3.invert_yaxis()
ax3.grid(ls=':')
plt.show()