Changing xlabel/ylabel position

Hello all,

I am trying to change the position of the xlabel/ylabel with respect to the
xaxis/yaxis. Particularly, I was trying to get the "xlabel" closer to the
"xaxis" and the "ylabel" closer to the "yaxis", for which I was using the
lines indicated with '#<-------' in the following sample code:

···

#----
from pylab import *
from numpy import *
x = linspace(0,1,10)
y = x**2
plot(x, y)
xlabel('xname', position=(0.5,0.1)) #<------
ylabel('yname', position=(0.1,0.5)) #<------
#----
My understanding was that "position=(xpos,ypos)" would place the label
anywhere I wanted, though there is problem. Let me take "xlabel" as an
example. I can successfully move the "xlabel" parallel to the "xaxis" by
setting the quantity "xpos" anywhere from 0 to 1 (0.5 being the center of
the "xaxis"). However, for moving the "xlabel" closer to or further from the
"xaxis" I change the value of "ypos" but it does NOT do anything, i.e. the
"xlabel" stays at the same distance from the "xaxis". The equivalent problem
occurs with the "ylabel", i.e. I can move "ylabel" parallel to the "yaxis"
but I cannot get it any closer.
I am aware that I can "create a label" and place it anywhere by using the
text() command. Yet, it would be better if I can get the label placement
done with the xlabel/ylabel command so that I can eventually control the
label placement via rcParams.update().

Many thanks in advance.

carlo
--
View this message in context: http://old.nabble.com/Changing-xlabel-ylabel-position-tp31195337p31195337.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

If you want full control of label coordinates, you need to use
"Axis.set_label_coords" method. For example,

ax = gca()
ax.xaxis.set_label_coords(0.5, -0.1)

And alternative way is to adjust the padding between the axis and the label.

ax.xaxis.labelpad = 0

Regards,

-JJ

···

On Mon, Mar 21, 2011 at 3:27 AM, andes <czunigaz@...9...> wrote:

x = linspace(0,1,10)
y = x**2
plot(x, y)
xlabel('xname', position=(0.5,0.1)) #<------
ylabel('yname', position=(0.1,0.5)) #<------

Thanks so much JJ! It works great.

carlo

Jae-Joon Lee wrote:

···

If you want full control of label coordinates, you need to use
"Axis.set_label_coords" method. For example,

ax = gca()
ax.xaxis.set_label_coords(0.5, -0.1)

And alternative way is to adjust the padding between the axis and the
label.

ax.xaxis.labelpad = 0

Regards,

-JJ

On Mon, Mar 21, 2011 at 3:27 AM, andes <czunigaz@...9...> wrote:

x = linspace(0,1,10)
y = x**2
plot(x, y)
xlabel('xname', position=(0.5,0.1)) #<------
ylabel('yname', position=(0.1,0.5)) #<------

------------------------------------------------------------------------------
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software
be a part of the solution? Download the Intel(R) Manageability Checker
today! http://p.sf.net/sfu/intel-dev2devmar
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

--
View this message in context: http://old.nabble.com/Re%3A-Changing-xlabel-ylabel-position-tp31225992p31300118.html
Sent from the matplotlib - users mailing list archive at Nabble.com.