On Tue, Sep 28, 2010 at 2:10 PM, Ruggero <giurrero@gmail.com> wrote:
2010/9/28 John Hunter <jdh2358@gmail.com>:
> On Tue, Sep 28, 2010 at 10:04 AM, Ruggero <giurrero@gmail.com> wrote:
>> As in the title: usually axis label on the x axis is plottet in the
>> middle of the axis. How to move it on the right? (and on the top for y
>> axis)
>
> You cannot coerce the xlabel to the top because it's y position is
> determined at drawtime to avoid overlapping the tick labels.  But you
> can place an arbitrary piece of text up there
>
>  text(1.0, 1.02, 'testing', horizontalalignment='right',
> verticalalignment='bottom', fontsize=14)
>
> See also
>
>  http://matplotlib.sourceforge.net/users/index_text.html
>
> and
>
>  http://matplotlib.sourceforge.net/examples/pylab_examples/alignment_test.html
>
> JDH
>

really there is no way to place the xlabel on the right as here:
http://www.cernlove.org/blog/wp-content/uploads/2009/10/root_plot1d.png  ?

I don't want to edit the y position of x label, I want to modify the x
position of x label and the y position of y label


Yes, there is...

When calling .set_xlabel(), you can specify the x coordinate of the label (in units of percentage of the axis width) without naming the y coordinate (that will be set automatically).   You might have to fiddle with the 'ha' (horizontalalignment) keyword (choices are 'center', 'left', 'right') in order to align your text relative to the coordinate you choose.

ex:
ax.set_xlabel('Time (s)', x=0.95, ha='right')

You can do the same thing with the 'y' keyword in .set_ylabel().  Instead of 'ha', you use 'va' (verticalalignment) in that case (choices: 'top', 'bottom', 'center', 'baseline').

Maybe we should add an example into the documentation for set_xlabel() and set_ylabel()?  I can see this as a reasonable enough feature for some to want to seek out.

Ben Root

P.S. - I just noticed that the axis label 'remembers' the keyword properties that were used in previous calls to set_?label() on that axis.  In other words, if at one point I specify that the ylabel should be at y=0.25 and then in a subsequent call to set_ylabel(), I don't specify anything at all, the previous value is used rather than the default.

Don't know if that is a feature or a bug, but this kind of thing would be more obvious as matplotlib becomes more interactive.  At the least, it probably should be documented in some way.