adjusting space between axes label and axes

hi all,

how can the space between the label (e.g. thing created by
plt.xlabel('mylabel')) and the axes be adjusted? i am not talking
about the space between the ticklabels of the axes and the axes
themselves (which is set by 'xtick.major.pad' or 'ytick.major.pad')
but between the overall axes label and the axes.

how can this be done? thanks.

hi all,

how can the space between the label (e.g. thing created by

plt.xlabel(‘mylabel’)) and the axes be adjusted? i am not talking

about the space between the ticklabels of the axes and the axes

themselves (which is set by ‘xtick.major.pad’ or ‘ytick.major.pad’)

but between the overall axes label and the axes.

how can this be done? thanks.

Using the set_position method, e.g. :

xlab = plt.xlabel(“my x-axes label”)
xlab.set_position((0.2, 0.1))

···

On Fri, Nov 13, 2009 at 12:36 PM, per freem <perfreem@…878…287…> wrote:


Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day

trial. Simplify your report design, integration and deployment - and focus on

what you do best, core application coding. Discover what’s new with

Crystal Reports now. http://p.sf.net/sfu/bobj-july


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Gökhan

thanks for the suggestion, though this does not work for me in the
following example:

import matplotlib
matplotlib.use('PDF')
import matplotlib.pyplot as plt
from matplotlib import rc
rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']})
plt.rcParams['ps.useafm'] = True
rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']})
plt.rcParams['pdf.fonttype'] = 42
plt.rcParams['font.size'] = 10

from mpl_toolkits.axes_grid.axislines import SubplotZero

def setup_axes(fig, labelpad=1, invisible=["bottom", "top", "right"]):
    plt.rcParams['ytick.major.pad'] = 2
    plt.rcParams['ytick.minor.pad'] = 2
    # Y ticks work, but X tick do not...
    plt.rcParams['xtick.major.pad'] = 0.01
    plt.rcParams['xtick.minor.pad'] = 0.01
    ax = SubplotZero(fig, 1, 1, 1)
    fig.add_subplot(ax)
    # make xzero axis (horizontal axis line through y=0) visible.
    ax.axis["xzero"].set_visible(True)
    # make other axis (bottom, top, right) invisible.
    for n in invisible:
        ax.axis[n].set_visible(False)
    return ax

fig = plt.figure(figsize=(5, 5), dpi=300)
setup_axes(fig, labelpad=2)
x = range(1, 11)
y = [5000, 900, 600, 500, 200, 110, 50, 20, 10, 5]
plt.plot(x, y, linewidth=1.5, c='k')
plt.ylabel('hello', labelpad=10)
xlab = plt.xlabel('hello x axis')
xlab.set_position((0.2, 0.1))
plt.savefig('test_logscale.pdf')

the xaxis doesn't seem to be moved. any idea what might be wrong here? thanks.

···

On Fri, Nov 13, 2009 at 1:43 PM, Gökhan Sever <gokhansever@...287...> wrote:

On Fri, Nov 13, 2009 at 12:36 PM, per freem <perfreem@...287...> wrote:

hi all,

how can the space between the label (e.g. thing created by
plt.xlabel('mylabel')) and the axes be adjusted? i am not talking
about the space between the ticklabels of the axes and the axes
themselves (which is set by 'xtick.major.pad' or 'ytick.major.pad')
but between the overall axes label and the axes.

how can this be done? thanks.

Using the set_position method, e.g. :

xlab = plt.xlabel("my x-axes label")
xlab.set_position((0.2, 0.1))

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008
30-Day
trial. Simplify your report design, integration and deployment - and focus
on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--
Gökhan

thanks for the suggestion, though this does not work for me in the

following example:

import matplotlib

matplotlib.use(‘PDF’)

import matplotlib.pyplot as plt

from matplotlib import rc

rc(‘font’,**{‘family’:‘sans-serif’,‘sans-serif’:[‘Helvetica’]})

plt.rcParams[‘ps.useafm’] = True

rc(‘font’,**{‘family’:‘sans-serif’,‘sans-serif’:[‘Helvetica’]})

plt.rcParams[‘pdf.fonttype’] = 42

plt.rcParams[‘font.size’] = 10

from mpl_toolkits.axes_grid.axislines import SubplotZero

def setup_axes(fig, labelpad=1, invisible=[“bottom”, “top”, “right”]):

plt.rcParams['ytick.major.pad'] = 2

plt.rcParams['ytick.minor.pad'] = 2

# Y ticks work, but X tick do not...

plt.rcParams['xtick.major.pad'] = 0.01

plt.rcParams['xtick.minor.pad'] = 0.01

ax = SubplotZero(fig, 1, 1, 1)

fig.add_subplot(ax)

# make xzero axis (horizontal axis line through y=0) visible.

ax.axis["xzero"].set_visible(True)

# make other axis (bottom, top, right) invisible.

for n in invisible:

    ax.axis[n].set_visible(False)

return ax

You are hiding the bottom x-axis. Therefore no label is appearing on the resulting figure. You may try not hiding it instead just the ticks. Using

ax.xaxis.set_major_locator(pylab.NullLocator())

But this causes the vertical grid lines to disappear. Alternatively you can manually add the xlabel if you are not in batch-producing mode --using your favorite pdf editor.

I am sure Jae-Jeon has a better explanation for this.

···

On Fri, Nov 13, 2009 at 1:02 PM, per freem <perfreem@…83…287…> wrote:

fig = plt.figure(figsize=(5, 5), dpi=300)

setup_axes(fig, labelpad=2)

x = range(1, 11)

y = [5000, 900, 600, 500, 200, 110, 50, 20, 10, 5]

plt.plot(x, y, linewidth=1.5, c=‘k’)

plt.ylabel(‘hello’, labelpad=10)

xlab = plt.xlabel(‘hello x axis’)
xlab.set_position((0.2, 0.1))

plt.savefig(‘test_logscale.pdf’)

the xaxis doesn’t seem to be moved. any idea what might be wrong here? thanks.

On Fri, Nov 13, 2009 at 1:43 PM, Gökhan Sever <gokhansever@…287…> wrote:

On Fri, Nov 13, 2009 at 12:36 PM, per freem <perfreem@…287…> wrote:

hi all,

how can the space between the label (e.g. thing created by

plt.xlabel(‘mylabel’)) and the axes be adjusted? i am not talking

about the space between the ticklabels of the axes and the axes

themselves (which is set by ‘xtick.major.pad’ or ‘ytick.major.pad’)

but between the overall axes label and the axes.

how can this be done? thanks.

Using the set_position method, e.g. :

xlab = plt.xlabel(“my x-axes label”)

xlab.set_position((0.2, 0.1))


Let Crystal Reports handle the reporting - Free Crystal Reports 2008

30-Day

trial. Simplify your report design, integration and deployment - and focus

on

what you do best, core application coding. Discover what’s new with

Crystal Reports now. http://p.sf.net/sfu/bobj-july


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Gökhan


Gökhan

I think I have said this a few times, but if you're using axes_grid
toolkit, it is likely that most of the ticks, ticklabels and
axis-related command of the original matplotlib may NOT work. And that
is why I recommend you to use the spines instead.

Anyhow, adjusting the pad between axis and the axis label in the
axes_grid toolkit way is

ax.axis["xzero"].LABELPAD=10

Things like "labelpad" parameters in xlabel (or ylabel) command are
currently ignored.

I don't think set_position command will work also. I f you need to
place your labels at some specific point, simply use "text" or
"annotate" command instead.

-JJ

···

On Fri, Nov 13, 2009 at 2:02 PM, per freem <perfreem@...287...> wrote:

thanks for the suggestion, though this does not work for me in the
following example:

import matplotlib
matplotlib.use('PDF')
import matplotlib.pyplot as plt
from matplotlib import rc
rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']})
plt.rcParams['ps.useafm'] = True
rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']})
plt.rcParams['pdf.fonttype'] = 42
plt.rcParams['font.size'] = 10

from mpl_toolkits.axes_grid.axislines import SubplotZero

def setup_axes(fig, labelpad=1, invisible=["bottom", "top", "right"]):
plt.rcParams['ytick.major.pad'] = 2
plt.rcParams['ytick.minor.pad'] = 2
# Y ticks work, but X tick do not...
plt.rcParams['xtick.major.pad'] = 0.01
plt.rcParams['xtick.minor.pad'] = 0.01
ax = SubplotZero(fig, 1, 1, 1)
fig.add_subplot(ax)
# make xzero axis (horizontal axis line through y=0) visible.
ax.axis["xzero"].set_visible(True)
# make other axis (bottom, top, right) invisible.
for n in invisible:
ax.axis[n].set_visible(False)
return ax

fig = plt.figure(figsize=(5, 5), dpi=300)
setup_axes(fig, labelpad=2)
x = range(1, 11)
y = [5000, 900, 600, 500, 200, 110, 50, 20, 10, 5]
plt.plot(x, y, linewidth=1.5, c='k')
plt.ylabel('hello', labelpad=10)
xlab = plt.xlabel('hello x axis')
xlab.set_position((0.2, 0.1))
plt.savefig('test_logscale.pdf')

the xaxis doesn't seem to be moved. any idea what might be wrong here? thanks.

On Fri, Nov 13, 2009 at 1:43 PM, Gökhan Sever <gokhansever@...287...> wrote:

On Fri, Nov 13, 2009 at 12:36 PM, per freem <perfreem@...287...> wrote:

hi all,

how can the space between the label (e.g. thing created by
plt.xlabel('mylabel')) and the axes be adjusted? i am not talking
about the space between the ticklabels of the axes and the axes
themselves (which is set by 'xtick.major.pad' or 'ytick.major.pad')
but between the overall axes label and the axes.

how can this be done? thanks.

Using the set_position method, e.g. :

xlab = plt.xlabel("my x-axes label")
xlab.set_position((0.2, 0.1))

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008
30-Day
trial. Simplify your report design, integration and deployment - and focus
on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--
Gökhan

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Hi Jae-Joon and others,

i switched to using splines, but i still cannot see how to adjust the
space between the axis labels and the ticks of the axes. right now the
labels are too far away.

here is my code:

fig = plt.figure()

x = np.linspace(0,2*np.pi,100)
y = 2*np.sin(x)

ax = fig.add_subplot(2,2,1)
ax.plot(x,y)
show_spines(ax,['left', 'bottom'])
plt.xlabel('xlabel')
plt.ylabel('ylabel')

ax = fig.add_subplot(2,2,2)
ax.plot(x,y)
show_spines(ax,['left', 'bottom'])
plt.xlabel('xlabel')
plt.ylabel('ylabel')

ax = fig.add_subplot(2,2,3)
ax.plot(x,y)
show_spines(ax,['left','bottom'])
plt.xlabel('xlabel')
plt.ylabel('ylabel')

ax = fig.add_subplot(2,2,4)
ax.plot(x,y)
show_spines(ax,['left', 'bottom'])
plt.xlabel('xlabel')
plt.ylabel('ylabel')
plt.savefig('test.pdf')

i don't see how i could switch to plt.text or plt.annotate here. the
xlabel and ylabel functions automatically plot the label of an axis in
the center, which is exactly what i need. computing where the
coordinates where a label should be plotted with plt.text so that the
label appears in the center seems very messy and difficult, since it
requires knowing how much space the label will take (and that depends
on the font size etc.)

is there an existing parameter that just controls the distance between
the xticks and the label? it seems like there must be.. i just want to
bring them closer together.

thank you.

···

On 11/13/09, Jae-Joon Lee <lee.j.joon@...287...> wrote:

I think I have said this a few times, but if you're using axes_grid
toolkit, it is likely that most of the ticks, ticklabels and
axis-related command of the original matplotlib may NOT work. And that
is why I recommend you to use the spines instead.

Anyhow, adjusting the pad between axis and the axis label in the
axes_grid toolkit way is

ax.axis["xzero"].LABELPAD=10

Things like "labelpad" parameters in xlabel (or ylabel) command are
currently ignored.

I don't think set_position command will work also. I f you need to
place your labels at some specific point, simply use "text" or
"annotate" command instead.

-JJ

On Fri, Nov 13, 2009 at 2:02 PM, per freem <perfreem@...287...> wrote:

thanks for the suggestion, though this does not work for me in the
following example:

import matplotlib
matplotlib.use('PDF')
import matplotlib.pyplot as plt
from matplotlib import rc
rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']})
plt.rcParams['ps.useafm'] = True
rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']})
plt.rcParams['pdf.fonttype'] = 42
plt.rcParams['font.size'] = 10

from mpl_toolkits.axes_grid.axislines import SubplotZero

def setup_axes(fig, labelpad=1, invisible=["bottom", "top", "right"]):
plt.rcParams['ytick.major.pad'] = 2
plt.rcParams['ytick.minor.pad'] = 2
# Y ticks work, but X tick do not...
plt.rcParams['xtick.major.pad'] = 0.01
plt.rcParams['xtick.minor.pad'] = 0.01
ax = SubplotZero(fig, 1, 1, 1)
fig.add_subplot(ax)
# make xzero axis (horizontal axis line through y=0) visible.
ax.axis["xzero"].set_visible(True)
# make other axis (bottom, top, right) invisible.
for n in invisible:
ax.axis[n].set_visible(False)
return ax

fig = plt.figure(figsize=(5, 5), dpi=300)
setup_axes(fig, labelpad=2)
x = range(1, 11)
y = [5000, 900, 600, 500, 200, 110, 50, 20, 10, 5]
plt.plot(x, y, linewidth=1.5, c='k')
plt.ylabel('hello', labelpad=10)
xlab = plt.xlabel('hello x axis')
xlab.set_position((0.2, 0.1))
plt.savefig('test_logscale.pdf')

the xaxis doesn't seem to be moved. any idea what might be wrong here?
thanks.

On Fri, Nov 13, 2009 at 1:43 PM, Gökhan Sever <gokhansever@...287...> >> wrote:

On Fri, Nov 13, 2009 at 12:36 PM, per freem <perfreem@...287...> wrote:

hi all,

how can the space between the label (e.g. thing created by
plt.xlabel('mylabel')) and the axes be adjusted? i am not talking
about the space between the ticklabels of the axes and the axes
themselves (which is set by 'xtick.major.pad' or 'ytick.major.pad')
but between the overall axes label and the axes.

how can this be done? thanks.

Using the set_position method, e.g. :

xlab = plt.xlabel("my x-axes label")
xlab.set_position((0.2, 0.1))

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008
30-Day
trial. Simplify your report design, integration and deployment - and
focus
on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--
Gökhan

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008
30-Day
trial. Simplify your report design, integration and deployment - and focus
on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

As you first tried (with your example with axes_grid), labelpad
parameter does what you want.

plt.xlabel("xlabel", labelpad=0)

or

ax.xaxis.labelpad = 0

It didn't work in your previous example because you were using
axes_grid toolkit, that simply ignores this parameter.

Also, see this

http://matplotlib.sourceforge.net/faq/howto_faq.html#align-my-ylabels-across-multiple-subplots

Regards,

-JJ

···

On Sun, Nov 22, 2009 at 11:16 AM, per freem <perfreem@...287...> wrote:

is there an existing parameter that just controls the distance between
the xticks and the label?