Skip to content

Commit 6847119

Browse files
authored
Merge pull request #8850 from tacaswell/pdf_color_none
Pdf color none
2 parents 4ec14fb + 51f0705 commit 6847119

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

lib/matplotlib/backends/backend_pdf.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,6 +1626,13 @@ def check_gc(self, gc, fillcolor=None):
16261626

16271627
orig_alphas = getattr(gc, '_effective_alphas', (1.0, 1.0))
16281628

1629+
if gc.get_rgb() is None:
1630+
# it should not matter what color here
1631+
# since linewidth should be 0
1632+
# unless affected by global settings in rcParams
1633+
# hence setting zero alpha just incase
1634+
gc.set_foreground((0, 0, 0, 0), isRGBA=True)
1635+
16291636
if gc._forced_alpha:
16301637
gc._effective_alphas = (gc._alpha, gc._alpha)
16311638
elif fillcolor is None or len(fillcolor) < 4:

lib/matplotlib/testing/compare.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,8 @@ def crop_to_same(actual_path, actual_image, expected_path, expected_image):
355355
# clip the images to the same size -- this is useful only when
356356
# comparing eps to pdf
357357
if actual_path[-7:-4] == 'eps' and expected_path[-7:-4] == 'pdf':
358-
aw, ah = actual_image.shape
359-
ew, eh = expected_image.shape
358+
aw, ah, ad = actual_image.shape
359+
ew, eh, ed = expected_image.shape
360360
actual_image = actual_image[int(aw / 2 - ew / 2):int(
361361
aw / 2 + ew / 2), int(ah / 2 - eh / 2):int(ah / 2 + eh / 2)]
362362
return actual_image, expected_image

lib/matplotlib/tests/test_backend_pdf.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
_determinism_check)
2020
from matplotlib.testing.decorators import image_comparison
2121
from matplotlib import dviread
22+
from matplotlib.testing.compare import compare_images
2223

24+
import matplotlib as mpl
2325

2426
needs_usetex = pytest.mark.xfail(
2527
not checkdep_usetex(True),
@@ -193,3 +195,16 @@ def psfont(*args, **kwargs):
193195
ax.text(0.5, 0.5, 'hello')
194196
with tempfile.TemporaryFile() as tmpfile, pytest.raises(ValueError):
195197
fig.savefig(tmpfile, format='pdf')
198+
199+
200+
@pytest.mark.style('default')
201+
def test_pdf_savefig_when_color_is_none(tmpdir):
202+
fig, ax = plt.subplots()
203+
plt.axis('off')
204+
ax.plot(np.sin(np.linspace(-5, 5, 100)), 'v', c='none')
205+
actual_image = tmpdir.join('figure.pdf')
206+
expected_image = tmpdir.join('figure.eps')
207+
fig.savefig(str(actual_image), format='pdf')
208+
fig.savefig(str(expected_image), format='eps')
209+
result = compare_images(str(actual_image), str(expected_image), 0)
210+
assert result is None

0 commit comments

Comments
 (0)
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