3
3
import codecs
4
4
import os
5
5
import matplotlib as mpl
6
+ import six
6
7
7
8
from . import axes
8
9
from . import legend
19
20
def get_tikz_code (
20
21
filepath ,
21
22
figure = 'gcf' ,
22
- encoding = None ,
23
23
figurewidth = None ,
24
24
figureheight = None ,
25
25
textsize = 10.0 ,
@@ -30,7 +30,7 @@ def get_tikz_code(
30
30
extra_tikzpicture_parameters = None ,
31
31
dpi = None ,
32
32
show_info = True
33
- ):
33
+ ):
34
34
'''Main function. Here, the recursion into the image starts and the
35
35
contents are picked up. The actual file gets written in this routine.
36
36
@@ -39,8 +39,6 @@ def get_tikz_code(
39
39
:param filepath: The file to which the TikZ output will be written.
40
40
:type filepath: str
41
41
42
- :param encoding: Which encoding to use for the file.
43
-
44
42
:param figurewidth: If not ``None``, this will be used as figure width
45
43
within the TikZ/PGFPlots output. If ``figureheight``
46
44
is not given, ``matplotlib2tikz`` will try to preserve
@@ -185,16 +183,13 @@ def save(*args, **kwargs):
185
183
'''
186
184
code = get_tikz_code (* args , ** kwargs )
187
185
188
- file_handle = codecs .open (
189
- args [0 ],
190
- 'w' ,
191
- kwargs ['encoding' ] if 'encoding' in kwargs else None
192
- )
186
+ encoding = kwargs ['encoding' ] if 'encoding' in kwargs else None
187
+ file_handle = codecs .open (args [0 ], 'w' , encoding )
193
188
try :
194
189
file_handle .write (code )
195
190
except UnicodeEncodeError :
196
- # We're probably using Python 2, so use proper unicode treatment
197
- file_handle .write (unicode (code ).encode ('utf-8' ))
191
+ # We're probably using Python 2, so treat unicode explicitly
192
+ file_handle .write (six . text_type (code ).encode ('utf-8' ))
198
193
file_handle .close ()
199
194
return
200
195
0 commit comments