Skip to content

Commit

Permalink
FIX: fix afm + py3k + logscale
Browse files Browse the repository at this point in the history
Followed suggestion of @pgnub

Closes matplotlib#3473

Adds test coverage for afm handling
  • Loading branch information
tacaswell committed Jul 17, 2015
1 parent 5c24f88 commit 987e550
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/matplotlib/mathtext.py
Expand Up @@ -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

Expand Down
19 changes: 15 additions & 4 deletions lib/matplotlib/tests/test_backend_ps.py
Expand Up @@ -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)
Expand Down Expand Up @@ -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():
Expand All @@ -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()
Expand All @@ -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)

0 comments on commit 987e550

Please sign in to comment.