File tree Expand file tree Collapse file tree 3 files changed +27
-1
lines changed Expand file tree Collapse file tree 3 files changed +27
-1
lines changed Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change @@ -460,7 +460,9 @@ def gcf():
460
460
else :
461
461
return figure ()
462
462
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
464
466
465
467
466
468
def get_fignums ():
Original file line number Diff line number Diff line change @@ -32,6 +32,23 @@ def test_figure_label():
32
32
assert_equal (plt .get_figlabels (), ['' , 'today' ])
33
33
34
34
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
+
35
52
@image_comparison (baseline_images = ['figure_today' ])
36
53
def test_figure ():
37
54
# named figure support
You can’t perform that action at this time.
0 commit comments