Setting the position of the `ylabel`

You can move the ylabel using ax.yaxis.set_label_coords, which does accept negative numbers. For your example, I removed the line with set_label_position, and added:

axPres.yaxis.set_label_coords(-0.1,1.02)

enter image description here

From the documentation:

Axis.set_label_coords(x, y, transform=None)

Set the coordinates of the label.

By default, the x coordinate of the y label and the y coordinate of
the x label are determined by the tick label bounding boxes, but this
can lead to poor alignment of multiple labels if there are multiple
axes.

You can also specify the coordinate system of the label with the
transform. If None, the default coordinate system will be the axes
coordinate system: (0, 0) is bottom left, (0.5, 0.5) is center, etc.

For further examples of using this method, see the second example on the matplotlib Align y-labels example page.

Leave a Comment