8000 Add warning for multiple pyplot.figure calls with same ID · matplotlib/matplotlib@d41b048 · GitHub
[go: up one dir, main page]

Skip to content

Commit d41b048

Browse files
committed
Add warning for multiple pyplot.figure calls with same ID
Exclude the 'clear' argument
1 parent b989445 commit d41b048

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
@@ -995,18 +995,24 @@ def figure(
995995
fig_label = ''
996996
if num is None:
997997
num = next_num
998-
elif isinstance(num, str):
999-
fig_label = num
1000-
all_labels = get_figlabels()
1001-
if fig_label not in all_labels:
1002-
if fig_label == 'all':
1003-
_api.warn_external("close('all') closes all existing figures.")
1004-
num = next_num
1005-
else:
1006-
inum = all_labels.index(fig_label)
1007-
num = allnums[inum]
1008998
else:
1009-
num = int(num) # crude validation of num argument
999+
if any([figsize, dpi, facecolor, edgecolor, not frameon,
1000+
kwargs]) and num in allnums:
1001+
_api.warn_external(
1002+
"Ignoring specified arguments in this call "
1003+
f"because figure with num: {num} already exists")
1004+
if isinstance(num, str):
1005+
fig_label = num
1006+
all_labels = get_figlabels()
1007+
if fig_label not in all_labels:
1008+
if fig_label == 'all':
1009+
_api.warn_external("close('all') closes all existing figures.")
1010+
num = next_num
1011+
else:
1012+
inum = all_labels.index(fig_label)
1013+
num = allnums[inum]
1014+
else:
1015+
num = int(num) # crude validation of num argument
10101016

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

0 commit comments

Comments
 (0)
0