本文整理匯總了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