From 987e5501de93d4860757d726081cd317fac735e5 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Fri, 17 Jul 2015 00:51:04 -0400 Subject: [PATCH] FIX: fix afm + py3k + logscale Followed suggestion of @pgnub Closes #3473 Adds test coverage for afm handling --- lib/matplotlib/mathtext.py | 2 +- lib/matplotlib/tests/test_backend_ps.py | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/matplotlib/mathtext.py b/lib/matplotlib/mathtext.py index cbe8bfd6bdd4..69e85b0369ce 100644 --- a/lib/matplotlib/mathtext.py +++ b/lib/matplotlib/mathtext.py @@ -1034,7 +1034,7 @@ def __init__(self, default_font_prop): if filename is None: filename = findfont('Helvetica', fontext='afm', directory=self.basepath) - with open(filename, 'r') as fd: + with open(filename, 'rb') as fd: default_font = AFM(fd) default_font.fname = filename diff --git a/lib/matplotlib/tests/test_backend_ps.py b/lib/matplotlib/tests/test_backend_ps.py index cd95f1750117..dc9c535f7428 100644 --- a/lib/matplotlib/tests/test_backend_ps.py +++ b/lib/matplotlib/tests/test_backend_ps.py @@ -23,14 +23,18 @@ "This test needs a TeX installation") -def _test_savefig_to_stringio(format='ps'): +def _test_savefig_to_stringio(format='ps', use_log=False): buffers = [ six.moves.StringIO(), io.StringIO(), io.BytesIO()] plt.figure() - plt.plot([0, 1], [0, 1]) + + if use_log: + plt.yscale('log') + + plt.plot([1, 2], [1, 2]) plt.title("Déjà vu") for buffer in buffers: plt.savefig(buffer, format=format) @@ -78,6 +82,12 @@ def test_savefig_to_stringio_eps(): _test_savefig_to_stringio(format='eps') +@cleanup +def test_savefig_to_stringio_eps_afm(): + matplotlib.rcParams['ps.useafm'] = True + _test_savefig_to_stringio(format='eps', use_log=True) + + @cleanup @needs_tex def test_savefig_to_stringio_with_usetex_eps(): @@ -88,8 +98,8 @@ def test_savefig_to_stringio_with_usetex_eps(): @cleanup def test_composite_image(): - #Test that figures can be saved with and without combining multiple images - #(on a single set of axes) into a single composite image. + # Test that figures can be saved with and without combining multiple images + # (on a single set of axes) into a single composite image. X, Y = np.meshgrid(np.arange(-5, 5, 1), np.arange(-5, 5, 1)) Z = np.sin(Y ** 2) fig = plt.figure() @@ -110,6 +120,7 @@ def test_composite_image(): buff = ps.read() assert buff.count(six.b(' colorimage')) == 2 + if __name__ == '__main__': import nose nose.runmodule(argv=['-s', '--with-doctest'], exit=False)