forgetful xlim?

Hi all,

I am again a little defeated so I hope somebody can point me in the right direction. I am trying to plot a graph but require some customation of the axes afterwards. As the axes are sacred in matplotlib I am trying to hide the existing axes and plot some new axes afterwards. The problem I have encountered is whilst plotting the new axes, the xlim functions apparently are no longer recognised.

The new axes appears fine but on the non-limited axes. All of this appears to work until the "make_xaxis" command where the original non-limited x axis appears again. I have tried various methods, tricks and suggestions but cannot appear to get the script to work. Probably something simple I know, but I can't seem to get around this one :-s

test script >

from pylab import *
import matplotlib.pyplot as plt
import matplotlib.lines as lines

#define new axis subroutines
def make_xaxis(aa, yloc, offset, **props):
     xmin, xmax = aa.get_xlim()
     locs = [loc for loc in aa.xaxis.get_majorticklocs()
             if loc>=xmin and loc<=xmax]
     tickline, = aa.plot(locs, [yloc]*len(locs),linestyle='',
             marker=lines.TICKDOWN, **props)
     aaline, = aa.plot([xmin, xmax], [yloc, yloc], **props)
     tickline.set_clip_on(False)
     aaline.set_clip_on(False)
# xaxis text
     for loc in locs:
         aa.text(loc, yloc-offset, '%1.0f'%loc,
                 horizontalalignment='center',
                 verticalalignment='top')

def make_yaxis(aa, xloc, offset, **props):
     ymin, ymax = aa.get_ylim()
     locs = [loc for loc in aa.yaxis.get_majorticklocs()
             if loc>=ymin and loc<=ymax]
     tickline, = aa.plot([xloc]*len(locs), locs, linestyle='',
             marker=lines.TICKLEFT, **props)
     aaline, = aa.plot([xloc, xloc], [ymin, ymax], **props)
     tickline.set_clip_on(False)
     aaline.set_clip_on(False)
# yaxis text
     for loc in locs:
         aa.text(xloc-offset, loc, '%1.2f'%loc,
                 verticalalignment='center',
                 horizontalalignment='right')

#read data
a=load('NC_figure4_alteredT.dat', skiprows=(1))
ax=a[:,0]
ay1=a[:,1]
ay2=a[:,2]

props = dict(color='black', linewidth=2, markeredgewidth=2)
                                                 #new axis props
fig = plt.figure(facecolor='white')
aa = fig.add_subplot(111, frame_on=False)
aa.scatter(ax, ay2, s=15, c='b', marker='^')
aa.set_xlim(-2.5,58.5)
aa.set_ylim(-0.01,0.25)

#plot new axes
make_xaxis(aa, -0.02, offset=0.01, **props)
                                                 #offset text values from axes
                                                 #select y axis intercept
#make_yaxis(aa, -4, offset=3, **props) #offset text values from axes

show()

time (h) n:c (a) n:c (b)
-2 0.12 0.21
-2 0.12 0.15
-2 0.1 0.14
0 0.12 0.14
0 0.11 0.13
0 0.11 0.21
2 0.11 0.15
2 0.11 0.13
2 0.11 0.14
4 0.11 0.14
4 0.1 0.14
4 0.09 0.12
6 0.09 0.14
6 0.1 0.12
6 0.1 0.1
8 0.11 0.13
8 0.08 0.13
8 0.1 0.11
10 0.1 0.12
10 0.08 0.11
10 0.11 0.1
12 0.07 0.1
12 0.09 0.1
12 0.08 0.1
14 0.1 0.1
14 0.16 0.1
14 0.1 0.1
16 0.1 0.1
16 0.17 0.1
16 0.07 0.1
18 0.1 0.09
18 0.09 0.11
20 0.09 0.12
20 0.09 0.1
20 0.07 0.11
22 0.12 0.11
22 0.09 0.12
22 0.09 0.13
24 0.09 0.13
24 0.11 0.13
26 0.09 0.12
26 0.09 0.13
26 0.11 0.14
28 0.09 0.13
28 0.1 0.14
28 0.09 0.13
30 0.09 0.12
30 0.1 0.13
30 0.1 0.12
32 0.09 0.12
32 0.08 0.12
32 0.09 0.12
34 0.08 0.12
34 0.11 0.11
36 0.09 0.11
36 0.07 0.11
36 0.09 0.1
38 0.1 0.11
38 0.08 0.11
38 0.09 0.1
40 0.09 0.11
42 0.09 0.11
42 0.11 0.12
42 0.08 0.11
44 0.12 0.12
44 0.12 0.16
44 0.11 0.12
46 0.11 0.12
46 0.12 0.11
46 0.1 0.12
48 0.1 0.12
48 0.14 0.13
48 0.1 0.14
56 0.1 0.12
56 0.11 0.12
58 0.12 0.11
58 0.12 0.1

Try

aa.set_autoscale_on(False)

before your "make_xaxis" call (but after xlim and ylim changed).
When you plot something, the xlim and ylim is automatically adjusted
(unless you set autoscale=False).

-JJ

···

On Wed, Mar 11, 2009 at 2:31 PM, Nicholas Stephens <Nicholas.Stephens@...2159...> wrote:

Hi all,

I am again a little defeated so I hope somebody can point me in the
right direction. I am trying to plot a graph but require some
customation of the axes afterwards. As the axes are sacred in
matplotlib I am trying to hide the existing axes and plot some new
axes afterwards. The problem I have encountered is whilst plotting the
new axes, the xlim functions apparently are no longer recognised.

The new axes appears fine but on the non-limited axes. All of this
appears to work until the "make_xaxis" command where the original
non-limited x axis appears again. I have tried various methods, tricks
and suggestions but cannot appear to get the script to work. Probably
something simple I know, but I can't seem to get around this one :-s

test script >

from pylab import *
import matplotlib.pyplot as plt
import matplotlib.lines as lines

#define new axis subroutines
def make_xaxis(aa, yloc, offset, **props):
xmin, xmax = aa.get_xlim()
locs = [loc for loc in aa.xaxis.get_majorticklocs()
if loc>=xmin and loc<=xmax]
tickline, = aa.plot(locs, [yloc]*len(locs),linestyle='',
marker=lines.TICKDOWN, **props)
aaline, = aa.plot([xmin, xmax], [yloc, yloc], **props)
tickline.set_clip_on(False)
aaline.set_clip_on(False)
# xaxis text
for loc in locs:
aa.text(loc, yloc-offset, '%1.0f'%loc,
horizontalalignment='center',
verticalalignment='top')

def make_yaxis(aa, xloc, offset, **props):
ymin, ymax = aa.get_ylim()
locs = [loc for loc in aa.yaxis.get_majorticklocs()
if loc>=ymin and loc<=ymax]
tickline, = aa.plot([xloc]*len(locs), locs, linestyle='',
marker=lines.TICKLEFT, **props)
aaline, = aa.plot([xloc, xloc], [ymin, ymax], **props)
tickline.set_clip_on(False)
aaline.set_clip_on(False)
# yaxis text
for loc in locs:
aa.text(xloc-offset, loc, '%1.2f'%loc,
verticalalignment='center',
horizontalalignment='right')

#read data
a=load('NC_figure4_alteredT.dat', skiprows=(1))
ax=a[:,0]
ay1=a[:,1]
ay2=a[:,2]

props = dict(color='black', linewidth=2, markeredgewidth=2)
#new axis props
fig = plt.figure(facecolor='white')
aa = fig.add_subplot(111, frame_on=False)
aa.scatter(ax, ay2, s=15, c='b', marker='^')
aa.set_xlim(-2.5,58.5)
aa.set_ylim(-0.01,0.25)

#plot new axes
make_xaxis(aa, -0.02, offset=0.01, **props)
#offset text values from axes
#select y axis intercept
#make_yaxis(aa, -4, offset=3, **props) #offset text values from axes

show()

>
time (h) n:c (a) n:c (b)
-2 0.12 0.21
-2 0.12 0.15
-2 0.1 0.14
0 0.12 0.14
0 0.11 0.13
0 0.11 0.21
2 0.11 0.15
2 0.11 0.13
2 0.11 0.14
4 0.11 0.14
4 0.1 0.14
4 0.09 0.12
6 0.09 0.14
6 0.1 0.12
6 0.1 0.1
8 0.11 0.13
8 0.08 0.13
8 0.1 0.11
10 0.1 0.12
10 0.08 0.11
10 0.11 0.1
12 0.07 0.1
12 0.09 0.1
12 0.08 0.1
14 0.1 0.1
14 0.16 0.1
14 0.1 0.1
16 0.1 0.1
16 0.17 0.1
16 0.07 0.1
18 0.1 0.09
18 0.09 0.11
18 0.09 0.11
20 0.09 0.12
20 0.09 0.1
20 0.07 0.11
22 0.12 0.11
22 0.09 0.12
22 0.09 0.13
24 0.09 0.13
24 0.11 0.13
24 0.11 0.13
26 0.09 0.12
26 0.09 0.13
26 0.11 0.14
28 0.09 0.13
28 0.1 0.14
28 0.09 0.13
30 0.09 0.12
30 0.1 0.13
30 0.1 0.12
32 0.09 0.12
32 0.08 0.12
32 0.09 0.12
34 0.08 0.12
34 0.08 0.12
34 0.11 0.11
36 0.09 0.11
36 0.07 0.11
36 0.09 0.1
38 0.1 0.11
38 0.08 0.11
38 0.09 0.1
40 0.09 0.11
40 0.09 0.11
40 0.09 0.11
42 0.09 0.11
42 0.11 0.12
42 0.08 0.11
44 0.12 0.12
44 0.12 0.16
44 0.11 0.12
46 0.11 0.12
46 0.12 0.11
46 0.1 0.12
48 0.1 0.12
48 0.14 0.13
48 0.1 0.14
56 0.1 0.12
56 0.11 0.12
56 0.11 0.12
58 0.12 0.11
58 0.12 0.11
58 0.12 0.1

------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users