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

Appearance settings

Commit 0346946

Browse filesBrowse files
committed
Merge pull request #4219 from jasonliw93/master
ENH : check existence of arbitrarily named figures Closes #2880
2 parents c90469b + cd08a19 commit 0346946
Copy full SHA for 0346946

File tree

Expand file treeCollapse file tree

3 files changed

+27
-1
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+27
-1
lines changed
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Updated fignum_exists to take figure name
2+
-------------------------------------------
3+
Added the ability to check the existence of a figure using it's name
4+
instead of just the figure number.
5+
Example:
6+
figure('figure')
7+
fignum_exists('figure') #true

‎lib/matplotlib/pyplot.py

Copy file name to clipboardExpand all lines: lib/matplotlib/pyplot.py
+3-1Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_figure.py
+17Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.