An ad hoc solution, that introduces the magic value 25
that I don't understand very much, to say the least, is
plt.xlabel('pollo', horizontalalignment='right', position=(1,25))
A more sensible approach is to use whichever y
position the axes.xaxis
has choosen... With this idea in mind a sane procedure is usually like
- get the object using a
.get_object(...)
method of the parent container - modify the object
- update the parent using its
.set_object(...)
method
In our case, we make the plot, then we get the current axis ax
that contains the xaxis
that contains the label
whose position and alignment we want to modify.
...plt.xlabel('...')...ax = plt.gca()label = ax.xaxis.get_label()x_lab_pos, y_lab_pos = label.get_position()label.set_position([1.0, y_lab_pos])label.set_horizontalalignment('right')ax.xaxis.set_label(label)...plt.show()
With respect of acting directly on matplotlib
's defaults, I've browsed the plt.rcParams
data structure but I haven't spotted anything useful. Of course that doesn't mean that it is impossible, just that I cannot see a viable solution.