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/testing/decorators.py b/lib/matplotlib/testing/decorators.py index 3a0dd4e0f9a8..1237ca85fecc 100644 --- a/lib/matplotlib/testing/decorators.py +++ b/lib/matplotlib/testing/decorators.py @@ -223,7 +223,12 @@ def _xfail_if_format_is_uncomparable(extension): def _mark_xfail_if_format_is_uncomparable(extension): - will_fail = extension not in comparable_formats() + will_fail = True + for compare_type in comparable_formats(): + if (isinstance(extension, type(compare_type)) and + extension == compare_type): + will_fail = False + break if will_fail: fail_msg = 'Cannot compare %s files on this system' % extension import pytest 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)
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: