Python Numpy Matplotlib Set Y-Label inline -
i'm wondering how might set y label in following plot inline 1 another. misaligned since y values not of equal space.
in case, it's easier not use ylabel
@ all. instead, use annotate
place text @ constant offset left side of axes.
as example of problem:
import matplotlib.pyplot plt fig, axes = plt.subplots(nrows=4, sharex=true) yranges = [(-1000, 100), (-0.001, 0.002), (0, 5), (0, 20)] labels = ['$p_{euc}[mm]$', '$p_z[mm]$', '$p_y[mm]$', '$p_x[mm]$'] ax, yrange, label in zip(axes, yranges, labels): ax.set(ylim=yrange, ylabel=label) plt.show()
to solve this, it's easiest use annotate
. trick position text @ y=0.5
in axes coordinates, , 5 points left hand edge of figure in x-direction. syntax bit verbose, relatively easy read. key in xycoords
, textcoords
kwargs control how xy
, xytext
interpreted:
import matplotlib.pyplot plt fig, axes = plt.subplots(nrows=4, sharex=true) yranges = [(-1000, 100), (-0.001, 0.002), (0, 5), (0, 20)] labels = ['$p_{euc}[mm]$', '$p_z[mm]$', '$p_y[mm]$', '$p_x[mm]$'] ax, yrange, label in zip(axes, yranges, labels): ax.set(ylim=yrange) ax.annotate(label, xy=(0, 0.5), xytext=(5, 0), rotation=90, xycoords=('figure fraction', 'axes fraction'), textcoords='offset points', va='center', ha='left') plt.show()
Comments
Post a Comment