Deterministic LaTeX text in SVG images #5766

Merged
merged 1 commit into from Dec 30, 2015
@@ -119,14 +119,15 @@ def test_bold_font_output_with_none_fonttype():
ax.set_title('bold-title', fontweight='bold')
-def _test_determinism(filename):
+def _test_determinism_save(filename, usetex):
# This function is mostly copy&paste from "def test_visibility"
# To require no GUI, we use Figure and FigureCanvasSVG
# instead of plt.figure and fig.savefig
from matplotlib.figure import Figure
from matplotlib.backends.backend_svg import FigureCanvasSVG
from matplotlib import rc
rc('svg', hashsalt='asdf')
+ rc('text', usetex=usetex)
fig = Figure()
ax = fig.add_subplot(111)
@@ -138,12 +139,14 @@ def _test_determinism(filename):
a, b, c = ax.errorbar(x, y, yerr=yerr, fmt='ko')
for artist in b:
artist.set_visible(False)
+ ax.set_title('A string $1+2+\sigma$')
+ ax.set_xlabel('A string $1+2+\sigma$')
+ ax.set_ylabel('A string $1+2+\sigma$')
FigureCanvasSVG(fig).print_svg(filename)
-@cleanup
-def test_determinism():
+def _test_determinism(filename, usetex):
import os
import sys
from subprocess import check_call
@@ -154,15 +157,27 @@ def test_determinism():
'import matplotlib; '
'matplotlib.use("svg"); '
'from matplotlib.tests.test_backend_svg '
- 'import _test_determinism;'
- '_test_determinism("determinism.svg")'])
- with open('determinism.svg', 'rb') as fd:
+ 'import _test_determinism_save;'
+ '_test_determinism_save(%r, %r)' % (filename, usetex)])
+ with open(filename, 'rb') as fd:
plots.append(fd.read())
- os.unlink('determinism.svg')
+ os.unlink(filename)
for p in plots[1:]:
assert_equal(p, plots[0])
+@cleanup
+def test_determinism_notex():
+ # unique filename to allow for parallel testing
+ _test_determinism('determinism_notex.svg', usetex=False)
+
+
+@cleanup
+def test_determinism_tex():
+ # unique filename to allow for parallel testing
+ _test_determinism('determinism_tex.svg', usetex=True)
+
+
if __name__ == '__main__':
import nose
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)
View
@@ -182,7 +182,7 @@ def get_glyphs_with_font(self, font, s, glyph_map=None,
glyph_ids = []
if glyph_map is None:
- glyph_map = dict()
+ glyph_map = OrderedDict()
if return_new_glyphs_only:
glyph_map_new = OrderedDict()
@@ -241,10 +241,10 @@ def get_glyphs_mathtext(self, prop, s, glyph_map=None,
s, self.DPI, prop)
if not glyph_map:
- glyph_map = dict()
+ glyph_map = OrderedDict()
if return_new_glyphs_only:
- glyph_map_new = dict()
+ glyph_map_new = OrderedDict()
else:
glyph_map_new = glyph_map
@@ -318,10 +318,10 @@ def get_glyphs_tex(self, prop, s, glyph_map=None,
page = next(iter(dvi))
if glyph_map is None:
- glyph_map = dict()
+ glyph_map = OrderedDict()
if return_new_glyphs_only:
- glyph_map_new = dict()
+ glyph_map_new = OrderedDict()
else:
glyph_map_new = glyph_map