AXES properties

set_position does not work with axes_grid toolkits.

Try something like


However, note that this (and set_rotation) may not work with
mpl_toolkits in future release of matplotlib as there has been some
significant changes.



ps. please use "reply to all", so that messages stay inside the list.


On Mon, Feb 1, 2010 at 7:52 PM, Kim Cheung <ecs1749@...287...> wrote:

Mr. Lee,

Thanks for the reply.

The position call works with the first example but not the second:

# Example 1
import pylab


pylab.plot(data1, label='Score 2005')
pylab.plot(data2, label='Num 2006')
pylab.setp(pylab.gca(), xticklabels=[])
pylab.ylabel('Score 2')
pylab.title('Historical Statistics')
pylab.legend(loc='upper left')

pylab.plot(data1, label='Score 06')
pylab.plot(data2, label='Num 06')
xlabels = pylab.gca().get_xticklabels()
ylabels = pylab.gca().get_yticklabels()
pylab.setp(xlabels, 'rotation', 90)
pylab.setp(xlab, position=(0.2,0.1)) # <=== This line works
pylab.ylabel('Score 1')
pylab.legend(loc='upper left')

But doesn't work in this example:

# Example 2
from mpl_toolkits.axes_grid.parasite_axes import SubplotHost
import matplotlib.pyplot as plt

from matplotlib.ticker import MultipleLocator, FormatStrFormatter

if 1:
figprops = dict(figsize=(8., 8. / 1.618), dpi=128)
# Figure properties
adjustprops = dict(left=0.08, bottom=0.12, right=0.79, top=0.96,
wspace=0.2, hspace=0.2) # Subplot properties

fig = plt.figure(**figprops)
# Tunes the subplot layout

host = SubplotHost(fig, 111)

p0, = host.plot([0, 1, 2], [0, 1, 2], label="Density")
plt.setp(ax.label, visible=True, text="Density", size=12,
plt.setp(ax.major_ticklabels, rotation="vertical")

plt.setp(ax.label, position=(0.2,0.1)) # This line has no effect.


host.set_xlim(0, 2)
host.set_ylim(0, 2)


Jae-Joon Lee wrote:

Are you using the axes_grid toolkit?
Standard matplotlib axis instance does not have "major_ticklabels"
attribute, while axes_grid axis does.

Please post a simple, but complete example that can be run and tested.


On Sun, Jan 31, 2010 at 11:06 AM, <kc106_2005-matplotlib@...9...> >> wrote:

BTW: I tried to use set_position to change the position of the axes label
as suggested by previous posting. No effect.

----- Original Message ----


I am creating a plot with multiple y-axis (up to 6) and twinx

works pretty well. The problem is that there are too much wasted spaces
used up
by the axes. Since I have multiple axes, it cuts into the amount of
available for the plot area. I need to know how I can squeeze some
spaces out of
the standard axes. First thing I discovered was that I can rotate the
labels to vertical by:

plt.setp(ax.major_ticklabels, rotation="vertical")

where ax is my y-axis. But then:

(1) How to reduce the space between the tick and the axes label?

First I tried to place the label on top but couldn't get that to work.
Then I

tried to change the position property of the axis label object and that
have no
effect. So, can somebody please tell me how I can do these 2 things?

(2) How to avoid overlapping tick labels?

With the way the standard x and y axis are drawn, after I do a vertical

of the y tick labels, the first y tick label overlaps with the last x
tick label
since they are both center aligned. Is there any way to change the
alignment of
only the first and last tick labels of an axes (while keeping the rest


John Henry

The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call
Matplotlib-users mailing list

Kim Cheung