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

Skip to content

Commit a2f6b3b

Browse files
committed
Add warning for multiple pyplot.figure calls with same ID
1 parent 47c96df commit a2f6b3b

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
@@ -975,18 +975,24 @@ def figure(
975975
fig_label = ''
976976
if num is None:
977977
num = next_num
978-
elif isinstance(num, str):
979-
fig_label = num
980-
all_labels = get_figlabels()
981-
if fig_label not in all_labels:
982-
if fig_label == 'all':
983-
_api.warn_external("close('all') closes all existing figures.")
984-
num = next_num
985-
else:
986-
inum = all_labels.index(fig_label)
987-
num = allnums[inum]
988978
else:
989-
num = int(num) # crude validation of num argument
979+
if any([figsize, dpi, facecolor, edgecolor, not frameon, clear,
980+
kwargs]) and num in allnums:
981+
_api.warn_external(
982+
"Ignoring specified arguments in this call"
983+
f"because figure with num: {num} already exists")
984+
if isinstance(num, str):
985+
fig_label = num
986+
all_labels = get_figlabels()
987+
if fig_label not in all_labels:
988+
if fig_label == 'all':
989+
_api.warn_external("close('all') closes all existing figures.")
990+
num = next_num
991+
else:
992+
inum = all_labels.index(fig_label)
993+
num = allnums[inum]
994+
else:
995+
num = int(num) # crude validation of num argument
990996

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

0 commit comments

Comments
 (0)