@@ -1715,6 +1715,45 @@ def get_rasterization_zorder(self):
1715
1715
"""
1716
1716
return self ._rasterization_zorder
1717
1717
1718
+ def autoscale (self , enable = True , axis = 'both' , tight = None ):
1719
+ """
1720
+ Convenience method for simple axis view autoscaling.
1721
+ It turns autoscaling on or off, and then,
1722
+ if autoscaling for either axis is on, it performs
1723
+ the autoscaling on the specified axis or axes.
1724
+
1725
+ *enable*: [True | False | None]
1726
+ True (default) turns autoscaling on, False turns it off.
1727
+ None leaves the autoscaling state unchanged.
1728
+
1729
+ *axis*: ['x' | 'y' | 'both']
1730
+ which axis to operate on; default is 'both'
1731
+
1732
+ *tight*: [True | False | None]
1733
+ If True, set view limits to data limits;
1734
+ if False, let the locator and margins expand the view limits;
1735
+ if None, use tight scaling if the only artist is an image,
1736
+ otherwise treat *tight* as False.
1737
+ The *tight* setting is retained for future autoscaling
1738
+ until it is explicitly changed.
1739
+
1740
+
1741
+ Returns None.
1742
+ """
1743
+ if enable is None :
1744
+ scalex = True
1745
+ scaley = True
1746
+ else :
1747
+ scalex = False
1748
+ scaley = False
1749
+ if axis in ['x' , 'both' ]:
1750
+ self ._autoscaleXon = bool (enable )
1751
+ scalex = self ._autoscaleXon
1752
+ if axis in ['y' , 'both' ]:
1753
+ self ._autoscaleYon = bool (enable )
1754
+ scaley = self ._autoscaleYon
1755
+ self .autoscale_view (tight = tight , scalex = scalex , scaley = scaley )
1756
+
1718
1757
1719
1758
def autoscale_view (self , tight = None , scalex = True , scaley = True ):
1720
1759
"""
@@ -2209,7 +2248,7 @@ def set_axis_bgcolor(self, color):
2209
2248
def invert_xaxis (self ):
2210
2249
"Invert the x-axis."
2211
2250
left , right = self .get_xlim ()
2212
- self .set_xlim (right , left )
2251
+ self .viewLim . intervalx = (right , left )
2213
2252
2214
2253
def xaxis_inverted (self ):
2215
2254
'Returns True if the x-axis is inverted.'
@@ -2233,6 +2272,7 @@ def set_xbound(self, lower=None, upper=None):
2233
2272
"""
2234
2273
Set the lower and upper numerical bounds of the x-axis.
2235
2274
This method will honor axes inversion regardless of parameter order.
2275
+ It will not change the _autoscaleXon attribute.
2236
2276
"""
2237
2277
if upper is None and iterable (lower ):
2238
2278
lower ,upper = lower
@@ -2244,46 +2284,59 @@ def set_xbound(self, lower=None, upper=None):
2244
2284
2245
2285
if self .xaxis_inverted ():
2246
2286
if lower < upper :
2247
- self .set_xlim (upper , lower )
2287
+ self .set_xlim (upper , lower , auto = None )
2248
2288
else :
2249
- self .set_xlim (lower , upper )
2289
+ self .set_xlim (lower , upper , auto = None )
2250
2290
else :
2251
2291
if lower < upper :
2252
- self .set_xlim (lower , upper )
2292
+ self .set_xlim (lower , upper , auto = None )
2253
2293
else :
2254
- self .set_xlim (upper , lower )
2294
+ self .set_xlim (upper , lower , auto = None )
2255
2295
2256
2296
def get_xlim (self ):
2257
2297
"""
2258
2298
Get the x-axis range [*xmin*, *xmax*]
2259
2299
"""
2260
2300
return tuple (self .viewLim .intervalx )
2261
2301
2262
- def set_xlim (self , xmin = None , xmax = None , emit = True , ** kwargs ):
2302
+ def set_xlim (self , xmin = None , xmax = None , emit = True , auto = False ):
2263
2303
"""
2264
2304
call signature::
2265
2305
2266
- set_xlim(self, *args, **kwargs)
2267
-
2268
- Set the limits for the xaxis
2306
+ set_xlim(self, *args, **kwargs):
2269
2307
2270
- Returns the current xlimits as a length 2 tuple: [*xmin*, *xmax*]
2308
+ Set the data limits for the xaxis
2271
2309
2272
2310
Examples::
2273
2311
2274
- set_xlim((valmin, valmax ))
2275
- set_xlim(valmin, valmax )
2276
- set_xlim(xmin=1) # xmax unchanged
2277
- set_xlim(xmax=1) # xmin unchanged
2312
+ set_xlim((left, right ))
2313
+ set_xlim(left, right )
2314
+ set_xlim(xmin=1) # right unchanged
2315
+ set_xlim(xmax=1) # left unchanged
2278
2316
2279
2317
Keyword arguments:
2280
2318
2281
2319
*xmin*: scalar
2282
- the min of the ylim
2320
+ the left xlim
2283
2321
*xmax*: scalar
2284
- the max of the ylim
2322
+ the right xlim
2285
2323
*emit*: [ True | False ]
2286
2324
notify observers of lim change
2325
+ *auto*: [ True | False | None ]
2326
+ turn *x* autoscaling on (True), off (False; default),
2327
+ or leave unchanged (None)
2328
+
2329
+ Note: the kwarg terminology may be confusing. The first value,
2330
+ *xmin*, is the left, and the second, *xmax*, is the right.
2331
+ For example, suppose *x* is years before present.
2332
+ Then one might use::
2333
+
2334
+ set_ylim(5000, 0)
2335
+
2336
+ so 5000 years ago is on the left of the plot and the
2337
+ present is on the right.
2338
+
2339
+ Returns the current xlimits as a length 2 tuple
2287
2340
2288
2341
ACCEPTS: len(2) sequence of floats
2289
2342
"""
@@ -2307,6 +2360,8 @@ def set_xlim(self, xmin=None, xmax=None, emit=True, **kwargs):
2307
2360
xmin , xmax = self .xaxis .limit_range_for_scale (xmin , xmax )
2308
2361
2309
2362
self .viewLim .intervalx = (xmin , xmax )
2363
+ if auto is not None :
2364
+ self ._autoscaleXon = bool (auto )
2310
2365
2311
2366
if emit :
2312
2367
self .callbacks .process ('xlim_changed' , self )
@@ -2391,25 +2446,26 @@ def set_xticklabels(self, labels, fontdict=None, minor=False, **kwargs):
2391
2446
2392
2447
def invert_yaxis (self ):
2393
2448
"Invert the y-axis."
2394
- left , right = self .get_ylim ()
2395
- self .set_ylim ( right , left )
2449
+ bottom , top = self .get_ylim ()
2450
+ self .viewLim . intervaly = ( top , bottom )
2396
2451
2397
2452
def yaxis_inverted (self ):
2398
2453
'Returns True if the y-axis is inverted.'
2399
- left , right = self .get_ylim ()
2400
- return right < left
2454
+ bottom , top = self .get_ylim ()
2455
+ return top < bottom
2401
2456
2402
2457
def get_ybound (self ):
2403
2458
"Return y-axis numerical bounds in the form of lowerBound < upperBound"
2404
- left , right = self .get_ylim ()
2405
- if left < right :
2406
- return left , right
2459
+ bottom , top = self .get_ylim ()
2460
+ if bottom < top :
2461
+ return bottom , top
2407
2462
else :
2408
- return right , left
2463
+ return top , bottom
2409
2464
2410
2465
def set_ybound (self , lower = None , upper = None ):
2411
2466
"""Set the lower and upper numerical bounds of the y-axis.
2412
2467
This method will honor axes inversion regardless of parameter order.
2468
+ It will not change the _autoscaleYon attribute.
2413
2469
"""
2414
2470
if upper is None and iterable (lower ):
2415
2471
lower ,upper = lower
@@ -2421,42 +2477,57 @@ def set_ybound(self, lower=None, upper=None):
2421
2477
2422
2478
if self .yaxis_inverted ():
2423
2479
if lower < upper :
2424
- self .set_ylim (upper , lower )
2480
+ self .set_ylim (upper , lower , auto = None )
2425
2481
else :
2426
- self .set_ylim (lower , upper )
2482
+ self .set_ylim (lower , upper , auto = None )
2427
2483
else :
2428
2484
if lower < upper :
2429
- self .set_ylim (lower , upper )
2485
+ self .set_ylim (lower , upper , auto = None )
2430
2486
else :
2431
- self .set_ylim (upper , lower )
2487
+ self .set_ylim (upper , lower , auto = None )
2432
2488
2433
2489
def get_ylim (self ):
2434
2490
"""
2435
2491
Get the y-axis range [*ymin*, *ymax*]
2436
2492
"""
2437
2493
return tuple (self .viewLim .intervaly )
2438
2494
2439
- def set_ylim (self , ymin = None , ymax = None , emit = True , ** kwargs ):
2495
+ def set_ylim (self , ymin = None , ymax = None , emit = True , auto = False ):
2440
2496
"""
2441
2497
call signature::
2442
2498
2443
2499
set_ylim(self, *args, **kwargs):
2444
2500
2445
- Set the limits for the yaxis; v = [ymin, ymax]::
2501
+ Set the data limits for the yaxis
2502
+
2503
+ Examples::
2446
2504
2447
- set_ylim((valmin, valmax ))
2448
- set_ylim(valmin, valmax )
2449
- set_ylim(ymin=1) # ymax unchanged
2450
- set_ylim(ymax=1) # ymin unchanged
2505
+ set_ylim((bottom, top ))
2506
+ set_ylim(bottom, top )
2507
+ set_ylim(ymin=1) # top unchanged
2508
+ set_ylim(ymax=1) # bottom unchanged
2451
2509
2452
2510
Keyword arguments:
2453
2511
2454
2512
*ymin*: scalar
2455
- the min of the ylim
2513
+ the bottom ylim
2456
2514
*ymax*: scalar
2457
- the max of the ylim
2515
+ the top ylim
2458
2516
*emit*: [ True | False ]
2459
2517
notify observers of lim change
2518
+ *auto*: [ True | False | None ]
2519
+ turn *y* autoscaling on (True), off (False; default),
2520
+ or leave unchanged (None)
2521
+
2522
+ Note: the kwarg terminology may be confusing. The first value,
2523
+ *ymin*, is the bottom, and the second, *ymax*, is the top.
2524
+ For example, suppose *y* is depth in the ocean.
2525
+ Then one might use::
2526
+
2527
+ set_ylim(5000, 0)
2528
+
2529
+ so 5000 m depth is at the bottom of the plot and the
2530
+ surface, 0 m, is at the top.
2460
2531
2461
2532
Returns the current ylimits as a length 2 tuple
2462
2533
@@ -2480,7 +2551,10 @@ def set_ylim(self, ymin=None, ymax=None, emit=True, **kwargs):
2480
2551
2481
2552
ymin , ymax = mtransforms .nonsingular (ymin , ymax , increasing = False )
2482
2553
ymin , ymax = self .yaxis .limit_range_for_scale (ymin , ymax )
2554
+
2483
2555
self .viewLim .intervaly = (ymin , ymax )
2556
+ if auto is not None :
2557
+ self ._autoscaleYon = bool (auto )
2484
2558
2485
2559
if emit :
2486
2560
self .callbacks .process ('ylim_changed' , self )
@@ -6647,14 +6721,10 @@ def imshow(self, X, cmap=None, norm=None, aspect=None,
6647
6721
im .autoscale_None ()
6648
6722
im .set_url (url )
6649
6723
6650
- xmin , xmax , ymin , ymax = im .get_extent ()
6724
+ # update ax.dataLim, and, if autoscaling, set viewLim
6725
+ # to tightly fit the image, regardless of dataLim.
6726
+ im .set_extent (im .get_extent ())
6651
6727
6652
- corners = (xmin , ymin ), (xmax , ymax )
6653
- self .update_datalim (corners )
6654
- if self ._autoscaleXon :
6655
- self .set_xlim ((xmin , xmax ))
6656
- if self ._autoscaleYon :
6657
- self .set_ylim ((ymin , ymax ))
6658
6728
self .images .append (im )
6659
6729
im ._remove_method = lambda h : self .images .remove (h )
6660
6730
0 commit comments