8000 Backend pdf · Pull Request #8673 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Backend pdf #8673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
added unit test for back end pdf and fixed small bug in testing facility
  • Loading branch information
Tuan333 committed May 26, 2017
commit 396648546ecde263b39f621d9c04ef1455c2caa2
8 changes: 8 additions & 0 deletions lib/matplotlib/backends/backend_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -2621,3 +2628,4 @@ class FigureManagerPdf(FigureManagerBase):

FigureCanvas = FigureCanvasPdf
FigureManager = FigureManagerPdf

5 changes: 3 additions & 2 deletions lib/matplotlib/testing/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -492,3 +492,4 @@ def save_diff_image(expected, actual, output):
save_image_np[:, :, 3] = 255

_png.write_png(save_image_np, output)

22 changes: 22 additions & 0 deletions lib/matplotlib/tests/test_backend_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -191,3 +193,23 @@ 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)

0