Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbdd5a3b

Browse files
committed
Deprecate the Axes-reuse-if-same-args behavior.
1 parentdd54033 commitbdd5a3b

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

‎lib/matplotlib/figure.py

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,14 @@ def get(self, key):
9191
item=dict(self._elements).get(key)
9292
ifitemisNone:
9393
returnNone
94-
returnitem[1]
94+
cbook.warn_deprecated(
95+
"2.1",
96+
"Adding an axes using the same arguments as a previous axes "
97+
"currently reuses the earlier instance. In a future version, "
98+
"a new instance will always be created and returned. Meanwhile, "
99+
"this warning can be suppressed, and the future behavior ensured, "
100+
"by passing a unique label to each axes instance.")
101+
returnitem[1]
95102

96103
def_entry_from_axes(self,e):
97104
ind,k= {a: (ind,k)fork, (ind,a)inself._elements}[e]
@@ -901,14 +908,14 @@ def add_axes(self, *args, **kwargs):
901908
fig.add_axes(rect, projection='polar')
902909
fig.add_axes(ax)
903910
904-
If the figure already has an axes with the same parameters,
905-
then itwill simply make that axes current and return it.If
906-
you do not want this behavior, e.g., you want to force the
907-
creation of a new Axes, youmust use a unique set ofargs and
908-
kwargs. The axes :attr:`~matplotlib.axes.Axes.label`
909-
attribute has been exposed for this purpose. e.g., if you want
910-
two axes that are otherwise identical to be added to the
911-
figure, make sure you give them unique labels::
911+
If the figure already has an axes with the same parameters, then it
912+
will simply make that axes current and return it.This behavior
913+
has been deprecated as of Matplotlib 2.1. Meanwhile, if you do
914+
not want this behavior (i.e., youwant to force the creation ofa
915+
new Axes), you must use a unique set of args andkwargs. The axes
916+
:attr:`~matplotlib.axes.Axes.label`attribute has been exposed for this
917+
purpose: if you wanttwo axes that are otherwise identical to be added
918+
to thefigure, make sure you give them unique labels::
912919
913920
fig.add_axes(rect, label='axes1')
914921
fig.add_axes(rect, label='axes2')
@@ -996,14 +1003,14 @@ def add_subplot(self, *args, **kwargs):
9961003
-----
9971004
If the figure already has a subplot with key (*args*,
9981005
*kwargs*) then it will simply make that subplot current and
999-
return it.
1006+
return it. This behavior is deprecated.
10001007
10011008
Examples
10021009
--------
10031010
fig.add_subplot(111)
10041011
10051012
# equivalent but more general
1006-
fig.add_subplot(1,1,1)
1013+
fig.add_subplot(1, 1,1)
10071014
10081015
# add subplot with red background
10091016
fig.add_subplot(212, facecolor='r')
@@ -1022,18 +1029,17 @@ def add_subplot(self, *args, **kwargs):
10221029
return
10231030

10241031
iflen(args)==1andisinstance(args[0],int):
1025-
args=tuple([int(c)forcinstr(args[0])])
1026-
iflen(args)!=3:
1027-
raiseValueError("Integer subplot specification must "+
1028-
"be a three digit number. "+
1029-
"Not {n:d}".format(n=len(args)))
1032+
ifnot100<=args[0]<=999:
1033+
raiseValueError("Integer subplot specification must be a "
1034+
"three-digit number, not {}".format(args[0]))
1035+
args=tuple(map(int,str(args[0])))
10301036

10311037
ifisinstance(args[0],SubplotBase):
10321038

10331039
a=args[0]
10341040
ifa.get_figure()isnotself:
1035-
msg= ("The Subplot must have been created in the present"
1036-
"figure")
1041+
msg= ("The Subplot must have been created in the present"
1042+
"figure")
10371043
raiseValueError(msg)
10381044
# make a key for the subplot (which includes the axes object id
10391045
# in the hash)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp