本文整理匯總了Python中matplotlib.get_cachedir方法的典型用法代碼示例。如果您正苦於以下問題:Python matplotlib.get_cachedir方法的具體用法?Python matplotlib.get_cachedir怎麽用?Python matplotlib.get_cachedir使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類matplotlib
的用法示例。
在下文中一共展示了matplotlib.get_cachedir方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: hardcopy_fonts
# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import get_cachedir [as 別名]
def hardcopy_fonts():
path = os.path.abspath(__file__)
pkg_dir = "/" + "/".join(path.split("/")[:-1])
os.system(
"cp -r {}/fonts/firasans/* ".format(pkg_dir)
+ os.path.join(mpl.rcParams["datapath"] + "/fonts/ttf/")
)
os.system(
"cp -r {}/fonts/firamath/* ".format(pkg_dir)
+ os.path.join(mpl.rcParams["datapath"] + "/fonts/ttf/")
)
os.system(
"cp -r {}/fonts/texgyreheros/* ".format(pkg_dir)
+ os.path.join(mpl.rcParams["datapath"] + "/fonts/ttf/")
)
os.system("rm " + os.path.join(mpl.get_cachedir() + "/font*"))
示例2: get_cache_dir
# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import get_cachedir [as 別名]
def get_cache_dir():
cachedir = matplotlib.get_cachedir()
if cachedir is None:
raise RuntimeError('Could not find a suitable configuration directory')
cache_dir = os.path.join(cachedir, 'test_cache')
try:
Path(cache_dir).mkdir(parents=True, exist_ok=True)
except IOError:
return None
if not os.access(cache_dir, os.W_OK):
return None
return cache_dir
示例3: get_cache_dir
# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import get_cachedir [as 別名]
def get_cache_dir():
cachedir = mpl.get_cachedir()
if cachedir is None:
raise RuntimeError('Could not find a suitable configuration directory')
cache_dir = os.path.join(cachedir, 'test_cache')
try:
Path(cache_dir).mkdir(parents=True, exist_ok=True)
except IOError:
return None
if not os.access(cache_dir, os.W_OK):
return None
return cache_dir
示例4: convert
# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import get_cachedir [as 別名]
def convert(filename, cache):
"""
Convert the named file to png; return the name of the created file.
If *cache* is True, the result of the conversion is cached in
`matplotlib.get_cachedir() + '/test_cache/'`. The caching is based on a
hash of the exact contents of the input file. There is no limit on the
size of the cache, so it may need to be manually cleared periodically.
"""
base, extension = filename.rsplit('.', 1)
if extension not in converter:
reason = "Don't know how to convert %s files to png" % extension
from . import is_called_from_pytest
if is_called_from_pytest():
import pytest
pytest.skip(reason)
else:
from nose import SkipTest
raise SkipTest(reason)
newname = base + '_' + extension + '.png'
if not os.path.exists(filename):
raise IOError("'%s' does not exist" % filename)
# Only convert the file if the destination doesn't already exist or
# is out of date.
if (not os.path.exists(newname) or
os.stat(newname).st_mtime < os.stat(filename).st_mtime):
if cache:
cache_dir = get_cache_dir()
else:
cache_dir = None
if cache_dir is not None:
hash_value = get_file_hash(filename)
new_ext = os.path.splitext(newname)[1]
cached_file = os.path.join(cache_dir, hash_value + new_ext)
if os.path.exists(cached_file):
shutil.copyfile(cached_file, newname)
return newname
converter[extension](filename, newname)
if cache_dir is not None:
shutil.copyfile(newname, cached_file)
return newname