Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 146dcfa

Browse files
committed
Add warning for multiple pyplot.figure calls with same ID
1 parent bc13abf commit 146dcfa

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

lib/matplotlib/pyplot.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -992,18 +992,24 @@ def figure(
992992
fig_label = ''
993993
if num is None:
994994
num = next_num
995-
elif isinstance(num, str):
996-
fig_label = num
997-
all_labels = get_figlabels()
998-
if fig_label not in all_labels:
999-
if fig_label == 'all':
1000-
_api.warn_external("close('all') closes all existing figures.")
1001-
num = next_num
1002-
else:
1003-
inum = all_labels.index(fig_label)
1004-
num = allnums[inum]
1005995
else:
1006-
num = int(num) # crude validation of num argument
996+
if any([figsize, dpi, facecolor, edgecolor, not frameon, clear,
997+
kwargs]) and num in allnums:
998+
_api.warn_external(
999+
"Ignoring specified arguments in this call"
1000+
f"because figure with num: {num} already exists")
1001+
if isinstance(num, str):
1002+
fig_label = num
1003+
all_labels = get_figlabels()
1004+
if fig_label not in all_labels:
1005+
if fig_label == 'all':
1006+
_api.warn_external("close('all') closes all existing figures.")
1007+
num = next_num
1008+
else:
1009+
inum = all_labels.index(fig_label)
1010+
num = allnums[inum]
1011+
else:
1012+
num = int(num) # crude validation of num argument
10071013

10081014
# Type of "num" has narrowed to int, but mypy can't quite see it
10091015
manager = _pylab_helpers.Gcf.get_fig_manager(num) # type: ignore[arg-type]

0 commit comments

Comments
 (0)