From 74f8af2d42047544d8ad974bb14459f576096a03 Mon Sep 17 00:00:00 2001 From: Tuan Dung Tran Date: Sat, 27 May 2017 22:03:32 +1000 Subject: [PATCH 1/6] fixed pdf backend saving and modified pdf to eps blank/nonblank comparison and unit test case --- lib/matplotlib/backends/backend_pdf.py | 7 +++++++ lib/matplotlib/testing/compare.py | 4 ++-- lib/matplotlib/tests/test_backend_pdf.py | 21 +++++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/backends/backend_pdf.py b/lib/matplotlib/backends/backend_pdf.py index e14aadcb48bd..7ae584ac63df 100644 --- a/lib/matplotlib/backends/backend_pdf.py +++ b/lib/matplotlib/backends/backend_pdf.py @@ -1626,6 +1626,13 @@ def check_gc(self, gc, fillcolor=None): orig_alphas = getattr(gc, '_effective_alphas', (1.0, 1.0)) + if gc._rgb is None: + if gc.get_linewidth() != 0: + warnings.warn('if rgb is None, ' + + 'linewidth should also be 0') + # doesn't matter what color here + gc._rgb = [1, 0, 0, 1] + if gc._forced_alpha: gc._effective_alphas = (gc._alpha, gc._alpha) elif fillcolor is None or len(fillcolor) < 4: diff --git a/lib/matplotlib/testing/compare.py b/lib/matplotlib/testing/compare.py index c3d649e38069..b6f508660fc9 100644 --- a/lib/matplotlib/testing/compare.py +++ b/lib/matplotlib/testing/compare.py @@ -355,8 +355,8 @@ def crop_to_same(actual_path, actual_image, expected_path, expected_image): # clip the images to the same size -- this is useful only when # comparing eps to pdf if actual_path[-7:-4] == 'eps' and expected_path[-7:-4] == 'pdf': - aw, ah = actual_image.shape - ew, eh = expected_image.shape + aw, ah, ad = actual_image.shape + ew, eh, ed = expected_image.shape actual_image = actual_image[int(aw / 2 - ew / 2):int( aw / 2 + ew / 2), int(ah / 2 - eh / 2):int(ah / 2 + eh / 2)] return actual_image, expected_image diff --git a/lib/matplotlib/tests/test_backend_pdf.py b/lib/matplotlib/tests/test_backend_pdf.py index 3529ea8541db..fac9cd8635fd 100644 --- a/lib/matplotlib/tests/test_backend_pdf.py +++ b/lib/matplotlib/tests/test_backend_pdf.py @@ -19,7 +19,9 @@ _determinism_check) from matplotlib.testing.decorators import image_comparison from matplotlib import dviread +from matplotlib.testing.compare import compare_images +import matplotlib as mpl needs_tex = pytest.mark.xfail( not checkdep_tex(), @@ -191,3 +193,22 @@ def psfont(*args, **kwargs): ax.text(0.5, 0.5, 'hello') with tempfile.TemporaryFile() as tmpfile, pytest.raises(ValueError): fig.savefig(tmpfile, format='pdf') + + +def test_pdf_savefig_when_color_is_none(): + backup_params = mpl.rcParams.copy() + mpl.rcParams.update(mpl.rcParamsDefault) + plt.subplot() + plt.axis('off') + plt.plot(np.sin(np.linspace(-5, 5, 100)), 'v', c='none') + try: + plt.savefig("figure.pdf", format='pdf') + except Exception: + pytest.fail("Failed to save pdf") + plt.savefig("figure.eps", format='eps') + result = compare_images('figure.pdf', 'figure.eps', 0) + assert result is None + from os import remove + remove('figure.eps') + remove('figure.pdf') + mpl.rcParams.update(backup_params) From 8046c045f9dd6fa7599409889a2dad3ce54b09a0 Mon Sep 17 00:00:00 2001 From: Tuan Date: Sun, 28 May 2017 19:15:09 +1000 Subject: [PATCH 2/6] Update backend_pdf.py --- lib/matplotlib/backends/backend_pdf.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/matplotlib/backends/backend_pdf.py b/lib/matplotlib/backends/backend_pdf.py index 7ae584ac63df..5a00f0ad9051 100644 --- a/lib/matplotlib/backends/backend_pdf.py +++ b/lib/matplotlib/backends/backend_pdf.py @@ -1627,11 +1627,11 @@ def check_gc(self, gc, fillcolor=None): orig_alphas = getattr(gc, '_effective_alphas', (1.0, 1.0)) if gc._rgb is None: - if gc.get_linewidth() != 0: - warnings.warn('if rgb is None, ' + - 'linewidth should also be 0') - # doesn't matter what color here - gc._rgb = [1, 0, 0, 1] + # it should not matter what color here + # since linewidth should be 0 + # unless affected by global settings in rcParams + # hence setting zero alpha just incase + gc._rgb = [0, 0, 0, 0] if gc._forced_alpha: gc._effective_alphas = (gc._alpha, gc._alpha) From cbed449cbf00960fd7388314305f5eb978bf52ed Mon Sep 17 00:00:00 2001 From: Tuan Date: Sun, 28 May 2017 19:23:21 +1000 Subject: [PATCH 3/6] Update backend_pdf.py --- lib/matplotlib/backends/backend_pdf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/backends/backend_pdf.py b/lib/matplotlib/backends/backend_pdf.py index 5a00f0ad9051..bf710705f202 100644 --- a/lib/matplotlib/backends/backend_pdf.py +++ b/lib/matplotlib/backends/backend_pdf.py @@ -1627,7 +1627,7 @@ def check_gc(self, gc, fillcolor=None): orig_alphas = getattr(gc, '_effective_alphas', (1.0, 1.0)) if gc._rgb is None: - # it should not matter what color here + # it should not matter what color here # since linewidth should be 0 # unless affected by global settings in rcParams # hence setting zero alpha just incase From 36a0a76e278bdf30921784270c24821c21655512 Mon Sep 17 00:00:00 2001 From: Tuan Date: Fri, 2 Jun 2017 22:57:40 +1000 Subject: [PATCH 4/6] fixed up test case --- lib/matplotlib/tests/test_backend_pdf.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/lib/matplotlib/tests/test_backend_pdf.py b/lib/matplotlib/tests/test_backend_pdf.py index fac9cd8635fd..8a1105013f8e 100644 --- a/lib/matplotlib/tests/test_backend_pdf.py +++ b/lib/matplotlib/tests/test_backend_pdf.py @@ -195,20 +195,16 @@ def psfont(*args, **kwargs): fig.savefig(tmpfile, format='pdf') -def test_pdf_savefig_when_color_is_none(): - backup_params = mpl.rcParams.copy() - mpl.rcParams.update(mpl.rcParamsDefault) +@pytest.mark.style('default') +@pytest.fixture(scope='function') +def test_pdf_savefig_when_color_is_none(tempdir_factory): plt.subplot() plt.axis('off') plt.plot(np.sin(np.linspace(-5, 5, 100)), 'v', c='none') - try: - plt.savefig("figure.pdf", format='pdf') - except Exception: - pytest.fail("Failed to save pdf") - plt.savefig("figure.eps", format='eps') - result = compare_images('figure.pdf', 'figure.eps', 0) + tmpdir_name = str(np.random.randint(10000, 10000000)) + actual_image = tempdir_factory.mktemp(tmpdir_name).join('figure.pdf') + expected_image = tempdir_factory.mktemp(tmpdir_name).join('figure.eps') + plt.savefig(str(actual_image), format='pdf') + plt.savefig(str(expected_image), format='eps') + result = compare_images(str(actual_image), str(expected_image), 0) assert result is None - from os import remove - remove('figure.eps') - remove('figure.pdf') - mpl.rcParams.update(backup_params) From 8bfd7883f19e70893b3d4370d9f655cc24fac7e2 Mon Sep 17 00:00:00 2001 From: Tuan Date: Fri, 2 Jun 2017 23:39:49 +1000 Subject: [PATCH 5/6] Update test_backend_pdf.py --- lib/matplotlib/tests/test_backend_pdf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_backend_pdf.py b/lib/matplotlib/tests/test_backend_pdf.py index 8a1105013f8e..dd1f7e9e9d50 100644 --- a/lib/matplotlib/tests/test_backend_pdf.py +++ b/lib/matplotlib/tests/test_backend_pdf.py @@ -201,7 +201,7 @@ def test_pdf_savefig_when_color_is_none(tempdir_factory): plt.subplot() plt.axis('off') plt.plot(np.sin(np.linspace(-5, 5, 100)), 'v', c='none') - tmpdir_name = str(np.random.randint(10000, 10000000)) + tmpdir_name = str(np.random.randint(100000, 10000000)) actual_image = tempdir_factory.mktemp(tmpdir_name).join('figure.pdf') expected_image = tempdir_factory.mktemp(tmpdir_name).join('figure.eps') plt.savefig(str(actual_image), format='pdf') From 7b656942f94bda714193294bddf194942671c63f Mon Sep 17 00:00:00 2001 From: Tuan Date: Sat, 3 Jun 2017 10:02:28 +1000 Subject: [PATCH 6/6] Update test_backend_pdf.py --- lib/matplotlib/tests/test_backend_pdf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_backend_pdf.py b/lib/matplotlib/tests/test_backend_pdf.py index dd1f7e9e9d50..275748e2aec2 100644 --- a/lib/matplotlib/tests/test_backend_pdf.py +++ b/lib/matplotlib/tests/test_backend_pdf.py @@ -195,9 +195,9 @@ def psfont(*args, **kwargs): fig.savefig(tmpfile, format='pdf') -@pytest.mark.style('default') @pytest.fixture(scope='function') def test_pdf_savefig_when_color_is_none(tempdir_factory): + rcParams['_internal.classic_mode'] = False plt.subplot() plt.axis('off') plt.plot(np.sin(np.linspace(-5, 5, 100)), 'v', c='none') pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy