@@ -1021,16 +1021,6 @@ def set_frameon(self, b):
1021
1021
1022
1022
frameon = property (get_frameon , set_frameon )
1023
1023
1024
- def delaxes (self , ax ):
1025
- """
1026
- Remove the `~matplotlib.axes.Axes` *ax* from the figure and update the
1027
- current axes.
1028
- """
1029
- self ._axstack .remove (ax )
1030
- for func in self ._axobservers :
1031
- func (self )
1032
- self .stale = True
1033
-
1034
1024
def add_artist (self , artist , clip = False ):
1035
1025
"""
1036
1026
Add any :class:`~matplotlib.artist.Artist` to the figure.
@@ -1357,25 +1347,17 @@ def add_subplot(self, *args, **kwargs):
1357
1347
::
1358
1348
1359
1349
fig = plt.figure()
1360
- fig.add_subplot(221)
1361
-
1362
- # equivalent but more general
1363
- ax1 = fig.add_subplot(2, 2, 1)
1364
-
1365
- # add a subplot with no frame
1366
- ax2 = fig.add_subplot(222, frameon=False)
1367
1350
1368
- # add a polar subplot
1369
- fig.add_subplot(223, projection='polar')
1351
+ fig.add_subplot(231)
1352
+ ax1 = fig.add_subplot(2, 3, 1) # equivalent but more general
1370
1353
1371
- # add a red subplot that share the x-axis with ax1
1372
- fig.add_subplot(224, sharex=ax1, facecolor='red')
1354
+ fig.add_subplot(232, frameon=False) # subplot with no frame
1355
+ fig.add_subplot(233, projection='polar') # polar subplot
1356
+ fig.add_subplot(234, sharex=ax1) # subplot sharing x-axis with ax1
1357
+ fig.add_subplot(235, facecolor="red") # red subplot
1373
1358
1374
- #delete x2 from the figure
1375
- fig.delaxes(ax2)
1376
-
1377
- #add x2 to the figure again
1378
- fig.add_subplot(ax2)
1359
+ ax1.remove() # delete ax1 from the figure
1360
+ fig.add_subplot(ax1) # add ax1 back to the figure
1379
1361
"""
1380
1362
if not len (args ):
1381
1363
args = (1 , 1 , 1 )
@@ -1429,7 +1411,7 @@ def _add_axes_internal(self, key, ax):
1429
1411
"""Private helper for `add_axes` and `add_subplot`."""
1430
1412
self ._axstack .add (key , ax )
1431
1413
self .sca (ax )
1432
- ax ._remove_method = self ._remove_ax
1414
+ ax ._remove_method = self .delaxes
1433
1415
self .stale = True
1434
1416
ax .stale_callback = _stale_figure_callback
1435
1417
return ax
@@ -1602,7 +1584,11 @@ def subplots(self, nrows=1, ncols=1, sharex=False, sharey=False,
1602
1584
# Returned axis array will be always 2-d, even if nrows=ncols=1.
1603
1585
return axarr
1604
1586
1605
- def _remove_ax (self , ax ):
1587
+ def delaxes (self , ax ):
1588
+ """
1589
+ Remove the `~.axes.Axes` *ax* from the figure; update the current axes.
1590
+ """
1591
+
1606
1592
def _reset_locators_and_formatters (axis ):
1607
1593
# Set the formatters and locators to be associated with axis
1608
1594
# (where previously they may have been associated with another
@@ -1644,7 +1630,11 @@ def _break_share_link(ax, grouper):
1644
1630
return last_ax
1645
1631
return None
1646
1632
1647
- self .delaxes (ax )
1633
+ self ._axstack .remove (ax )
1634
+ for func in self ._axobservers :
1635
+ func (self )
1636
+ self .stale = True
1637
+
1648
1638
last_ax = _break_share_link (ax , ax ._shared_y_axes )
1649
1639
if last_ax is not None :
1650
1640
_reset_locators_and_formatters (last_ax .yaxis )
0 commit comments