From 8d2984192db4810c1846ba825ea56fd6b54aef77 Mon Sep 17 00:00:00 2001 From: Jason Liw Yan Chong Date: Sat, 14 Mar 2015 11:57:18 -0400 Subject: [PATCH 1/2] Implemented new feature for Issue 2880 Added the ability to check the existance of a figure label instead of just figure number. --- lib/matplotlib/pyplot.py | 4 +++- lib/matplotlib/tests/test_figure.py | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index a13d87ee2ba0..03e3b05e927a 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -460,7 +460,9 @@ def gcf(): else: return figure() -fignum_exists = _pylab_helpers.Gcf.has_fignum +def fignum_exists(num): + allLabels = get_figlabels() + return _pylab_helpers.Gcf.has_fignum(num) or num in allLabels def get_fignums(): diff --git a/lib/matplotlib/tests/test_figure.py b/lib/matplotlib/tests/test_figure.py index 0731205ed051..2f5fb4d68e2b 100644 --- a/lib/matplotlib/tests/test_figure.py +++ b/lib/matplotlib/tests/test_figure.py @@ -32,6 +32,23 @@ def test_figure_label(): assert_equal(plt.get_figlabels(), ['', 'today']) +@cleanup +def test_fignum_exists(): + # pyplot figure creation, selection and closing with fignum_exists + plt.figure('one') + plt.figure(2) + plt.figure('three') + plt.figure() + assert_equal(plt.fignum_exists('one'), True) + assert_equal(plt.fignum_exists(2), True) + assert_equal(plt.fignum_exists('three'), True) + assert_equal(plt.fignum_exists(4), True) + plt.close('one') + plt.close(4) + assert_equal(plt.fignum_exists('one'), False) + assert_equal(plt.fignum_exists(4), False) + + @image_comparison(baseline_images=['figure_today']) def test_figure(): # named figure support From cd08a1958fdad7a5b1374b8747ac769950e98ae0 Mon Sep 17 00:00:00 2001 From: Jason Liw Yan Chong Date: Sun, 15 Mar 2015 10:19:00 -0400 Subject: [PATCH 2/2] Added what's new entry --- doc/users/whats_new/updated_pyplot.rst | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 doc/users/whats_new/updated_pyplot.rst diff --git a/doc/users/whats_new/updated_pyplot.rst b/doc/users/whats_new/updated_pyplot.rst new file mode 100644 index 000000000000..7e525c9f761a --- /dev/null +++ b/doc/users/whats_new/updated_pyplot.rst @@ -0,0 +1,7 @@ +Updated fignum_exists to take figure name +------------------------------------------- +Added the ability to check the existence of a figure using it's name +instead of just the figure number. +Example: + figure('figure') + fignum_exists('figure') #true \ No newline at end of file