Skip to content

Commit 9ca5db0

Browse files
committed
set_xlim, set_ylim accept descriptive kwargs: left, right, bottom, top
svn path=/trunk/matplotlib/; revision=8496
1 parent fdac121 commit 9ca5db0

File tree

3 files changed

+82
-58
lines changed

3 files changed

+82
-58
lines changed

CHANGELOG

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
2010-07-05 Preferred kwarg names in set_xlim are now 'left' and
2+
'right'; in set_ylim, 'bottom' and 'top'; original
3+
kwargs are still accepted without complaint. - EF
4+
15
2010-07-05 TkAgg and FltkAgg backends are now consistent with other
26
interactive backends: when used in scripts from the
37
command line (not from ipython -pylab), show blocks,
4-
and can be called more than once.
8+
and can be called more than once. - EF
59

610
2010-07-02 Modified CXX/WrapPython.h to fix "swab bug" on solaris so
711
mpl can compile on Solaris with CXX6 in the trunk. Closes

doc/api/api_changes.rst

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ Changes beyond 0.99.x
1616
pyplot functions, has been changed: when view limits are
1717
set explicitly with one of these methods, autoscaling is turned
1818
off for the matching axis. A new *auto* kwarg is available to
19-
control this behavior.
19+
control this behavior. The limit kwargs have been renamed to
20+
*left* and *right* instead of *xmin* and *xmax*, and *bottom*
21+
and *top* instead of *ymin* and *ymax*. The old names may still
22+
be used, however.
2023

2124
* There are five new Axes methods with corresponding pyplot
2225
functions to facilitate autoscaling, tick location, and tick

lib/matplotlib/axes.py

+73-56
Original file line numberDiff line numberDiff line change
@@ -2298,11 +2298,11 @@ def set_xbound(self, lower=None, upper=None):
22982298

22992299
def get_xlim(self):
23002300
"""
2301-
Get the x-axis range [*xmin*, *xmax*]
2301+
Get the x-axis range [*left*, *right*]
23022302
"""
23032303
return tuple(self.viewLim.intervalx)
23042304

2305-
def set_xlim(self, xmin=None, xmax=None, emit=True, auto=False):
2305+
def set_xlim(self, left=None, right=None, emit=True, auto=False, **kw):
23062306
"""
23072307
call signature::
23082308
@@ -2314,23 +2314,23 @@ def set_xlim(self, xmin=None, xmax=None, emit=True, auto=False):
23142314
23152315
set_xlim((left, right))
23162316
set_xlim(left, right)
2317-
set_xlim(xmin=1) # right unchanged
2318-
set_xlim(xmax=1) # left unchanged
2317+
set_xlim(left=1) # right unchanged
2318+
set_xlim(right=1) # left unchanged
23192319
23202320
Keyword arguments:
23212321
2322-
*xmin*: scalar
2323-
the left xlim
2324-
*xmax*: scalar
2325-
the right xlim
2322+
*left*: scalar
2323+
the left xlim; *xmin*, the previous name, may still be used
2324+
*right*: scalar
2325+
the right xlim; *xmax*, the previous name, may still be used
23262326
*emit*: [ True | False ]
23272327
notify observers of lim change
23282328
*auto*: [ True | False | None ]
23292329
turn *x* autoscaling on (True), off (False; default),
23302330
or leave unchanged (None)
23312331
2332-
Note: the kwarg terminology may be confusing. The first value,
2333-
*xmin*, is the left, and the second, *xmax*, is the right.
2332+
Note: the *left* (formerly *xmin*) value may be greater than
2333+
the *right* (formerly *xmax*).
23342334
For example, suppose *x* is years before present.
23352335
Then one might use::
23362336
@@ -2343,26 +2343,34 @@ def set_xlim(self, xmin=None, xmax=None, emit=True, auto=False):
23432343
23442344
ACCEPTS: len(2) sequence of floats
23452345
"""
2346-
if xmax is None and iterable(xmin):
2347-
xmin,xmax = xmin
2348-
2349-
2350-
self._process_unit_info(xdata=(xmin, xmax))
2351-
if xmin is not None:
2352-
xmin = self.convert_xunits(xmin)
2353-
if xmax is not None:
2354-
xmax = self.convert_xunits(xmax)
2355-
2356-
old_xmin,old_xmax = self.get_xlim()
2357-
if xmin is None: xmin = old_xmin
2358-
if xmax is None: xmax = old_xmax
2359-
2360-
if xmin==xmax:
2361-
warnings.warn('Attempting to set identical xmin==xmax results in singular transformations; automatically expanding. xmin=%s, xmax=%s'%(xmin, xmax))
2362-
xmin, xmax = mtransforms.nonsingular(xmin, xmax, increasing=False)
2363-
xmin, xmax = self.xaxis.limit_range_for_scale(xmin, xmax)
2364-
2365-
self.viewLim.intervalx = (xmin, xmax)
2346+
if 'xmin' in kw:
2347+
left = kw.pop('xmin')
2348+
if 'xmax' in kw:
2349+
right = kw.pop('xmax')
2350+
if kw:
2351+
raise ValueError("unrecognized kwargs: %s" % kw.keys())
2352+
2353+
if right is None and iterable(left):
2354+
left,right = left
2355+
2356+
self._process_unit_info(xdata=(left, right))
2357+
if left is not None:
2358+
left = self.convert_xunits(left)
2359+
if right is not None:
2360+
right = self.convert_xunits(right)
2361+
2362+
old_left, old_right = self.get_xlim()
2363+
if left is None: left = old_left
2364+
if right is None: right = old_right
2365+
2366+
if left==right:
2367+
warnings.warn(('Attempting to set identical left==right results\n'
2368+
+ 'in singular transformations; automatically expanding.\n'
2369+
+ 'left=%s, right=%s') % (left, right))
2370+
left, right = mtransforms.nonsingular(left, right, increasing=False)
2371+
left, right = self.xaxis.limit_range_for_scale(left, right)
2372+
2373+
self.viewLim.intervalx = (left, right)
23662374
if auto is not None:
23672375
self._autoscaleXon = bool(auto)
23682376

@@ -2377,7 +2385,7 @@ def set_xlim(self, xmin=None, xmax=None, emit=True, auto=False):
23772385
other.figure.canvas is not None):
23782386
other.figure.canvas.draw_idle()
23792387

2380-
return xmin, xmax
2388+
return left, right
23812389

23822390
def get_xscale(self):
23832391
'return the xaxis scale string: %s' % (
@@ -2492,11 +2500,11 @@ def set_ybound(self, lower=None, upper=None):
24922500

24932501
def get_ylim(self):
24942502
"""
2495-
Get the y-axis range [*ymin*, *ymax*]
2503+
Get the y-axis range [*bottom*, *top*]
24962504
"""
24972505
return tuple(self.viewLim.intervaly)
24982506

2499-
def set_ylim(self, ymin=None, ymax=None, emit=True, auto=False):
2507+
def set_ylim(self, bottom=None, top=None, emit=True, auto=False, **kw):
25002508
"""
25012509
call signature::
25022510
@@ -2508,23 +2516,23 @@ def set_ylim(self, ymin=None, ymax=None, emit=True, auto=False):
25082516
25092517
set_ylim((bottom, top))
25102518
set_ylim(bottom, top)
2511-
set_ylim(ymin=1) # top unchanged
2512-
set_ylim(ymax=1) # bottom unchanged
2519+
set_ylim(bottom=1) # top unchanged
2520+
set_ylim(top=1) # bottom unchanged
25132521
25142522
Keyword arguments:
25152523
2516-
*ymin*: scalar
2517-
the bottom ylim
2518-
*ymax*: scalar
2519-
the top ylim
2524+
*bottom*: scalar
2525+
the bottom ylim; the previous name, *ymin*, may still be used
2526+
*top*: scalar
2527+
the top ylim; the previous name, *ymax*, may still be used
25202528
*emit*: [ True | False ]
25212529
notify observers of lim change
25222530
*auto*: [ True | False | None ]
25232531
turn *y* autoscaling on (True), off (False; default),
25242532
or leave unchanged (None)
25252533
2526-
Note: the kwarg terminology may be confusing. The first value,
2527-
*ymin*, is the bottom, and the second, *ymax*, is the top.
2534+
Note: the *bottom* (formerly *ymin*) value may be greater than
2535+
the *top* (formerly *ymax*).
25282536
For example, suppose *y* is depth in the ocean.
25292537
Then one might use::
25302538
@@ -2537,26 +2545,35 @@ def set_ylim(self, ymin=None, ymax=None, emit=True, auto=False):
25372545
25382546
ACCEPTS: len(2) sequence of floats
25392547
"""
2540-
if ymax is None and iterable(ymin):
2541-
ymin,ymax = ymin
2548+
if 'ymin' in kw:
2549+
bottom = kw.pop('ymin')
2550+
if 'ymax' in kw:
2551+
top = kw.pop('ymax')
2552+
if kw:
2553+
raise ValueError("unrecognized kwargs: %s" % kw.keys())
2554+
2555+
if top is None and iterable(bottom):
2556+
bottom,top = bottom
25422557

2543-
if ymin is not None:
2544-
ymin = self.convert_yunits(ymin)
2545-
if ymax is not None:
2546-
ymax = self.convert_yunits(ymax)
2558+
if bottom is not None:
2559+
bottom = self.convert_yunits(bottom)
2560+
if top is not None:
2561+
top = self.convert_yunits(top)
25472562

2548-
old_ymin,old_ymax = self.get_ylim()
2563+
old_bottom, old_top = self.get_ylim()
25492564

2550-
if ymin is None: ymin = old_ymin
2551-
if ymax is None: ymax = old_ymax
2565+
if bottom is None: bottom = old_bottom
2566+
if top is None: top = old_top
25522567

2553-
if ymin==ymax:
2554-
warnings.warn('Attempting to set identical ymin==ymax results in singular transformations; automatically expanding. ymin=%s, ymax=%s'%(ymin, ymax))
2568+
if bottom==top:
2569+
warnings.warn(('Attempting to set identical bottom==top results\n'
2570+
+ 'in singular transformations; automatically expanding.\n'
2571+
+ 'bottom=%s, top=%s') % (bottom, top))
25552572

2556-
ymin, ymax = mtransforms.nonsingular(ymin, ymax, increasing=False)
2557-
ymin, ymax = self.yaxis.limit_range_for_scale(ymin, ymax)
2573+
bottom, top = mtransforms.nonsingular(bottom, top, increasing=False)
2574+
bottom, top = self.yaxis.limit_range_for_scale(bottom, top)
25582575

2559-
self.viewLim.intervaly = (ymin, ymax)
2576+
self.viewLim.intervaly = (bottom, top)
25602577
if auto is not None:
25612578
self._autoscaleYon = bool(auto)
25622579

@@ -2571,7 +2588,7 @@ def set_ylim(self, ymin=None, ymax=None, emit=True, auto=False):
25712588
other.figure.canvas is not None):
25722589
other.figure.canvas.draw_idle()
25732590

2574-
return ymin, ymax
2591+
return bottom, top
25752592

25762593
def get_yscale(self):
25772594
'return the xaxis scale string: %s' % (

0 commit comments

Comments
 (0)