8000 fixed pdf backend saving and modified pdf to eps blank/nonblank compa… · matplotlib/matplotlib@74f8af2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 74f8af2

Browse files
author
Tuan Dung Tran
committed
fixed pdf backend saving and modified pdf to eps blank/nonblank comparison and unit test case
1 parent 1144e8c commit 74f8af2

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-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._rgb is None:
1630+
if gc.get_linewidth() != 0:
1631+
warnings.warn('if rgb is None, ' +
1632+
'linewidth should also be 0')
1633+
# doesn't matter what color here
1634+
gc._rgb = [1, 0, 0, 1]
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: 21 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_tex = pytest.mark.xfail(
2527
not checkdep_tex(),
@@ -191,3 +193,22 @@ def psfont(*args, **kwargs):
191193
ax.text(0.5, 0.5, 'hello')
192194
with tempfile.TemporaryFile() as tmpfile, pytest.raises(ValueError):
193195
fig.savefig(tmpfile, format='pdf')
196+
197+
198+
def test_pdf_savefig_when_color_is_none():
199+
backup_params = mpl.rcParams.copy()
200+
mpl.rcParams.update(mpl.rcParamsDefault)
201+
plt.subplot()
202+
plt.axis('off')
203+
plt.plot(np.sin(np.linspace(-5, 5, 100)), 'v', c='none')
204+
try:
205+
plt.savefig("figure.pdf", format='pdf')
206+
except Exception:
207+
pytest.fail("Failed to save pdf")
208+
plt.savefig("figure.eps", format='eps')
209+
result = compare_images('figure.pdf', 'figure.eps', 0)
210+
assert result is None
211+
from os import remove
212+
remove('figure.eps')
213+
remove('figure.pdf')
214+
mpl.rcParams.update(backup_params)

0 commit comments

Comments
 (0)
0