Skip to content

Commit bb53c0a

Browse files
committed
added marks axis scaled patch
svn path=/trunk/matplotlib/; revision=1931
1 parent 0bfe4af commit bb53c0a

File tree

6 files changed

+91
-58
lines changed

6 files changed

+91
-58
lines changed

CHANGELOG

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
2006-1-4 Added Mark's scaled axes patch for shared axis
2+
3+
2005-12-28 Added Chris Barker's build_wxagg patch - JDH
4+
15
2005-12-27 Altered numerix/scipy to support new scipy package
26
structure - TEO
3-
47
2005-12-20 Fixed Jame's Boyles date tick reversal problem - JDH
58

69
2005-12-20 Added Jouni's rc patch to support lists of keys to set on -

TODO

+3-1
Original file line numberDiff line numberDiff line change
@@ -735,4 +735,6 @@ ZeroDivisionError: SeparableTransformation::eval_scalars yin interval is zero; c
735735
-- Fix latex texmanager caching bug that is preventing the cache from
736736
recognizing a font change
737737

738-
-- handle lineprops.glade install file
738+
-- handle lineprops.glade install file
739+
740+
-- support zoom to rect in x or y only

lib/matplotlib/axes.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -3780,7 +3780,7 @@ def dist(a):
37803780
ds.sort()
37813781
return ds[0][1]
37823782

3783-
def set_aspect(self,aspect='normal',fixLimits=False,alignment='center'):
3783+
def set_aspect(self,aspect='normal',fixLimits=False):
37843784
"""
37853785
Set aspect to 'normal' or 'equal'
37863786
'normal' means matplotlib determines aspect ratio
@@ -3791,15 +3791,13 @@ def set_aspect(self,aspect='normal',fixLimits=False,alignment='center'):
37913791
fixLimits: False means data limits will be changed, but height and widths of axes preserved.
37923792
True means height or width will be changed, but data limits preserved
37933793
3794-
alignment is 'center' or 'lowerleft', only used when fixLimits is True
3795-
3796-
ACCEPTS: str, boolean, str
3794+
ACCEPTS: str, boolean
37973795
"""
37983796

37993797
self._aspect = aspect
38003798
if self._aspect == 'normal':
38013799
self.set_position( self._originalPosition )
3802-
elif self._aspect == 'equal':
3800+
elif self._aspect == 'equal' or self._aspect == 'scaled':
38033801
figW,figH = self.get_figure().get_size_inches()
38043802
xmin,xmax = self.get_xlim()
38053803
ymin,ymax = self.get_ylim()
@@ -3808,17 +3806,17 @@ def set_aspect(self,aspect='normal',fixLimits=False,alignment='center'):
38083806
axW = w * figW; axH = h * figH
38093807
if (xmax-xmin) / axW > (ymax-ymin) / axH: # y axis too long
38103808
axH = axW * (ymax-ymin) / (xmax-xmin)
3811-
if alignment == 'center':
3809+
if self._aspect == 'equal':
38123810
axc = b + 0.5 * h
38133811
h = axH / figH; b = axc - 0.5 * h
3814-
elif alignment == 'lowerleft':
3812+
elif self._aspect == 'scaled':
38153813
h = axH / figH
38163814
else: # x axis too long
38173815
axW = axH * (xmax-xmin) / (ymax-ymin)
3818-
if alignment == 'center':
3816+
if self._aspect == 'equal':
38193817
axc = l + 0.5 * w
38203818
w = axW / figW; l = axc - 0.5 * w
3821-
elif alignment == 'lowerleft':
3819+
elif self._aspect == 'scaled':
38223820
w = axW / figW
38233821
self.set_position( (l,b,w,h) )
38243822
else: # Change limits on axes

lib/matplotlib/backend_bases.py

+26-1
Original file line numberDiff line numberDiff line change
@@ -1376,14 +1376,39 @@ def release_zoom(self, event):
13761376
a.set_xlim((x1, x2))
13771377
a.set_ylim((y1, y2))
13781378

1379-
if a.get_aspect() == 'equal': a.set_aspect('equal',True)
1379+
# Zoom with fixed aspect; modified for shared x-axes
1380+
aspect = a.get_aspect()
1381+
if aspect == 'equal' or aspect == 'scaled':
1382+
self.fix_aspect_after_zoom(a)
1383+
else:
1384+
aspect_shared = ''
1385+
if a._sharex != None: aspect_shared = a._sharex.get_aspect()
1386+
if aspect_shared == 'equal' or aspect_shared == 'scaled':
1387+
self.fix_aspect_after_zoom(a._sharex)
1388+
13801389
self.draw()
13811390
self._xypress = None
13821391
self._button_pressed == None
13831392

13841393
self.push_current()
13851394
self.release(event)
13861395

1396+
def fix_aspect_after_zoom(self,a):
1397+
'Fix the aspect ratio after zooming in case of aspect equal or scaled'
1398+
lold,bold,wold,hold = a.get_position()
1399+
aspect = a.get_aspect()
1400+
a.set_aspect(aspect,True)
1401+
l,b,w,h = a.get_position()
1402+
if w != wold: # width of axes was changed
1403+
ratio = w / wold
1404+
for ax in a.get_figure().axes: # see if any subplot shares this axis
1405+
if ax._sharex == a:
1406+
lax,bax,wax,hax = ax.get_position()
1407+
wnew = ratio * wax
1408+
lnew = lax
1409+
if aspect == 'equal': lnew = lax - 0.5 * ( wnew - wax )
1410+
ax.set_position( [lnew, bax, wnew, hax] )
1411+
13871412
def draw(self):
13881413
'redraw the canvases, update the locators'
13891414
for a in self.canvas.figure.get_axes():

lib/matplotlib/pylab.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -565,12 +565,12 @@ def axis(*v, **kwargs):
565565
566566
axis('scaled') makes scale equal, changes lengths of axes while
567567
keeping limits of x and y axes fixed. Keeps lower left hand corner
568-
in original position
568+
in original position. Fixes axis limits.
569569
570570
axis('tight') changes limits x and y axis such that all data is
571571
shown. If all data is already shown, it will move it to the center
572572
of the figure without modifying (xmax-xmin) or (ymax-ymin). Note
573-
this is slightly different than in matlab.
573+
this is slightly different than in matlab. Fixes axis limits.
574574
575575
axis('normal') sets the axis to normal, i.e. turns equal scale off
576576
@@ -591,13 +591,14 @@ def axis(*v, **kwargs):
591591
draw_if_interactive()
592592
elif s.lower()=='tight':
593593
ax.autoscale_view()
594-
if ax.get_aspect() == 'equal':
595-
ax.set_aspect('equal',True)
594+
ax.set_autoscale_on(False)
596595
draw_if_interactive()
597596
elif s.lower()=='scaled':
598-
ax.set_aspect('equal',True,'lowerleft')
597+
ax.set_autoscale_on(False)
598+
ax.set_aspect('scaled',True)
599599
draw_if_interactive()
600600
elif s.lower()=='normal':
601+
ax.set_autoscale_on(True)
601602
ax.set_aspect('normal')
602603
else:
603604
raise ValueError('Unrecognized string %s to axis; try on or off' % s)

setupext.py

+45-41
Original file line numberDiff line numberDiff line change
@@ -486,55 +486,59 @@ def build_tkagg(ext_modules, packages, numerix):
486486

487487

488488
def build_wxagg(ext_modules, packages, numerix, abortOnFailure):
489-
global BUILT_WXAGG
490-
if BUILT_WXAGG:
491-
return
489+
global BUILT_WXAGG
490+
if BUILT_WXAGG:
491+
return
492492

493-
wxconfig = find_wx_config()
493+
wxconfig = find_wx_config()
494494

495-
# Avoid aborting the whole build process if `wx-config' can't be found and
496-
# BUILD_WXAGG in setup.py is set to "auto"
497-
if wxconfig is None:
498-
print 'WXAgg\'s accelerator requires `wx-config\'.'
495+
# Avoid aborting the whole build process if `wx-config' can't be found and
496+
# BUILD_WXAGG in setup.py is set to "auto"
497+
if wxconfig is None:
498+
print """
499+
WXAgg's accelerator requires `wx-config'.
499500
500-
if not abortOnFailure:
501-
BUILT_WXAGG = True
502-
return
503-
else:
504-
print '''\n\
505-
The `wx-config\' executable could not be located in any directory of the PATH
506-
environment variable. If it is in some other location or has some other name,
507-
set the WX_CONFIG environment variable to the full path of the execuatable.'''
508-
sys.exit(1)
509-
elif not check_wxpython_headers(wxconfig):
510-
print 'WXAgg\'s accelerator requires the wxPython headers.'
511-
512-
if not abortOnFailure:
513-
BUILT_WXAGG = True
514-
return
515-
else:
516-
print '''\n\
517-
The wxPython header files could not be located in any of the standard include
518-
directories or include directories reported by `wx-config --cppflags'.'''
519-
sys.exit(1)
501+
The `wx-config\' executable could not be located in any directory of the
502+
PATH environment variable. If you want to build WXAgg, and wx-config is
503+
in some other location or has some other name, set the WX_CONFIG
504+
environment variable to the full path of the executable like so:
520505
521-
deps = ['src/_wxagg.cpp', 'src/mplutils.cpp']#, 'src/_transforms.cpp']
522-
deps.extend(glob.glob('CXX/*.cxx'))
523-
deps.extend(glob.glob('CXX/*.c'))
506+
export WX_CONFIG=/usr/lib/wxPython-2.6.1.0-gtk2-unicode/bin/wx-config
507+
"""
508+
if not abortOnFailure:
509+
print """Building MPL without wxAgg"""
510+
BUILT_WXAGG = True
511+
return
512+
else:
513+
sys.exit(1)
514+
elif not check_wxpython_headers(wxconfig):
515+
print 'WXAgg\'s accelerator requires the wxPython headers.'
524516

525-
module = Extension('matplotlib.backends._wxagg', deps)
517+
if not abortOnFailure:
518+
BUILT_WXAGG = True
519+
return
520+
else:
521+
print """
522+
The wxPython header files could not be located in any of the standard
523+
include
524+
directories or include directories reported by `wx-config --cppflags'."""
525+
sys.exit(1)
526526

527-
# wxagg implicitly needs the scipy flags when targetting
528-
# scipy because of src/_transforms.c
529-
if 'scipy' in numerix:
530-
add_scipy_flags(module)
531527

532-
add_agg_flags(module)
533-
add_ft2font_flags(module)
534-
add_wx_flags(module, wxconfig)
528+
deps = ['src/_wxagg.cpp', 'src/mplutils.cpp']
529+
deps.extend(glob.glob('CXX/*.cxx'))
530+
deps.extend(glob.glob('CXX/*.c'))
531+
532+
module = Extension('matplotlib.backends._wxagg', deps)
533+
534+
add_agg_flags(module)
535+
add_ft2font_flags(module)
536+
add_wx_flags(module, wxconfig)
537+
538+
ext_modules.append(module)
539+
BUILT_WXAGG = True
540+
535541

536-
ext_modules.append(module)
537-
BUILT_WXAGG = True
538542

539543

540544
def build_agg(ext_modules, packages, numerix):

0 commit comments

Comments
 (0)