Skip to content

Commit

Permalink
python3 compatible. tested with python-2.7.11 and python-3.5.1 using …
Browse files Browse the repository at this point in the history
…archlinux
  • Loading branch information
liubenyuan committed Apr 18, 2016
1 parent e5b2339 commit 84dfaa5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
5 changes: 5 additions & 0 deletions matplotlib/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
__pycahce__/
out/
tmp.py
*.pyc

17 changes: 8 additions & 9 deletions matplotlib/backend_ipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

# --------------------------------------------------------------------

from __future__ import division, print_function
from __future__ import division, print_function, unicode_literals

import os, base64, tempfile, urllib, gzip, io, sys, codecs, re

Expand Down Expand Up @@ -45,7 +45,7 @@

rcParams.validate['ipe.textsize'] = validate_bool
rcParams.validate['ipe.stylesheet'] = validate_path_exists
rcParams.validate['ipe.preamble'] = lambda (s) : s
rcParams.validate['ipe.preamble'] = lambda s : s

# ----------------------------------------------------------------------
# SimpleXMLWriter class
Expand Down Expand Up @@ -147,8 +147,7 @@ def start(self, tag, attrib={}, **extra):
if attrib or extra:
attrib = attrib.copy()
attrib.update(extra)
attrib = attrib.items()
attrib.sort()
attrib = sorted(attrib.items())
for k, v in attrib:
if not v == '':
k = escape_cdata(k)
Expand Down Expand Up @@ -216,7 +215,7 @@ def close(self, id):
# can be omitted.

def element(self, tag, text=None, attrib={}, **extra):
apply(self.start, (tag, attrib), extra)
self.start(*(tag, attrib), **extra)
if text:
self.data(text)
self.end(indent=False)
Expand Down Expand Up @@ -255,15 +254,15 @@ def __init__(self, width, height, ipewriter, basename):
version=u"70005",
creator="matplotlib")
pre = rcParams.get('ipe.preamble', "")
if pre <> "":
if pre != "":
self.writer.start(u'preamble')
self.writer.data(pre)
self.writer.end(indent=False)
sheet = rcParams.get('ipe.stylesheet', "")
if sheet <> "":
if sheet != "":
self.writer.insertSheet(sheet)
self.writer.start(u'ipestyle', name=u"opacity")

for i in range(10,100,10):
self.writer.element(u'opacity', name=u'%02d%%'% i,
value=u'%g'% (i/100.0))
Expand Down Expand Up @@ -519,7 +518,7 @@ def _cleanup():
LatexManager._cleanup_remaining_instances()
# This is necessary to avoid a spurious error
# caused by the atexit at the end of the PGF backend
LatexManager.__del__ = lambda (self) : None
LatexManager.__del__ = lambda self : None

atexit.register(_cleanup)

Expand Down
9 changes: 5 additions & 4 deletions matplotlib/run_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
# Run all the tests in tests subdirectory
# and save plots in ipe and svg format
#
from __future__ import division, print_function, unicode_literals

import os, sys

def fix_file(f):
data = open("tests/%s" % f, "rb").readlines()
data = open("tests/%s" % f, "r").readlines()
os.rename("tests/%s" % f, "tests/%s.bak" % f)
out = open("tests/%s" % f, "wb")
out = open("tests/%s" % f, "w")
for l in data:
ll = l.strip()
if ll == "import matplotlib as mpl": continue
Expand All @@ -30,13 +31,13 @@ def runall(form):

def run(form, f):
sys.stderr.write("# %s\n" % f)
t = open("tmp.py", "wb")
t = open("tmp.py", "w")
t.write("""# %s
import matplotlib as mpl
""" % f)
if form=="ipe":
t.write("mpl.use('module://backend_ipe')\n")
t.write(open("tests/%s.py" % f, "rb").read())
t.write(open("tests/%s.py" % f, "r").read())
t.write("plt.savefig('out/%s.%s', format='%s')\n" % (f, form, form))
t.close()
os.system("python tmp.py")
Expand Down

0 comments on commit 84dfaa5

Please sign in to comment.