8000 Implemented new feature for Issue 2880 · matplotlib/matplotlib@8d29841 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8d29841

Browse files
committed
Implemented new feature for Issue 2880
Added the ability to check the existance of a figure label instead of just figure number.
1 parent c90469b commit 8d29841

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/matplotlib/pyplot.py 8000

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,9 @@ def gcf():
460460
else:
461461
return figure()
462462

463-
fignum_exists = _pylab_helpers.Gcf.has_fignum
463+
def fignum_exists(num):
464+
allLabels = get_figlabels()
465+
return _pylab_helpers.Gcf.has_fignum(num) or num in allLabels
464466

465467

466468
def get_fignums():

lib/matplotlib/tests/test_figure.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,23 @@ def test_figure_label():
3232
assert_equal(plt.get_figlabels(), ['', 'today'])
3333

3434

35+
@cleanup
36+
def test_fignum_exists():
37+
# pyplot figure creation, selection and closing with fignum_exists
38+
plt.figure('one')
39+
plt.figure(2)
40+
plt.figure('three')
41+
plt.figure()
42+
assert_equal(plt.fignum_exists('one'), True)
43+
assert_equal(plt.fignum_exists(2), True)
44+
assert_equal(plt.fignum_exists('three'), True)
45+
assert_equal(plt.fignum_exists(4), True)
46+
plt.close('one')
47+
plt.close(4)
48+
assert_equal(plt.fignum_exists('one'), False)
49+
assert_equal(plt.fignum_exists(4), False)
50+
51+
3552
@image_comparison(baseline_images=['figure_today'])
3653
def test_figure():
3754
# named figure support

0 commit comments

Comments
 (0)
0