本文整理汇总了Python中matplotlib.cbook.file_requires_unicode方法的典型用法代码示例。如果您正苦于以下问题:Python cbook.file_requires_unicode方法的具体用法?Python cbook.file_requires_unicode怎么用?Python cbook.file_requires_unicode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.cbook
的用法示例。
在下文中一共展示了cbook.file_requires_unicode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: print_svg
# 需要导入模块: from matplotlib import cbook [as 别名]
# 或者: from matplotlib.cbook import file_requires_unicode [as 别名]
def print_svg(self, filename, *args, **kwargs):
with cbook.open_file_cm(filename, "w", encoding="utf-8") as fh:
filename = getattr(fh, 'name', '')
if not isinstance(filename, str):
filename = ''
if cbook.file_requires_unicode(fh):
detach = False
else:
fh = io.TextIOWrapper(fh, 'utf-8')
detach = True
result = self._print_svg(filename, fh, **kwargs)
# Detach underlying stream from wrapper so that it remains open in
# the caller.
if detach:
fh.detach()
return result
示例2: print_pgf
# 需要导入模块: from matplotlib import cbook [as 别名]
# 或者: from matplotlib.cbook import file_requires_unicode [as 别名]
def print_pgf(self, fname_or_fh, *args, **kwargs):
"""
Output pgf commands for drawing the figure so it can be included and
rendered in latex documents.
"""
if kwargs.get("dryrun", False):
self._print_pgf_to_fh(None, *args, **kwargs)
return
with cbook.open_file_cm(fname_or_fh, "w", encoding="utf-8") as file:
if not cbook.file_requires_unicode(file):
file = codecs.getwriter("utf-8")(file)
self._print_pgf_to_fh(file, *args, **kwargs)
示例3: print_svg
# 需要导入模块: from matplotlib import cbook [as 别名]
# 或者: from matplotlib.cbook import file_requires_unicode [as 别名]
def print_svg(self, filename, *args, **kwargs):
with cbook.open_file_cm(filename, "w", encoding="utf-8") as fh:
filename = getattr(fh, 'name', '')
if not isinstance(filename, six.string_types):
filename = ''
if cbook.file_requires_unicode(fh):
detach = False
else:
if six.PY3:
fh = io.TextIOWrapper(fh, 'utf-8')
else:
fh = codecs.getwriter('utf-8')(fh)
detach = True
result = self._print_svg(filename, fh, **kwargs)
# Detach underlying stream from wrapper so that it remains open in
# the caller.
if detach:
if six.PY3:
fh.detach()
else:
fh.reset()
fh.stream = io.BytesIO()
return result