本文整理汇总了Python中matplotlib.style.context方法的典型用法代码示例。如果您正苦于以下问题:Python style.context方法的具体用法?Python style.context怎么用?Python style.context使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.style
的用法示例。
在下文中一共展示了style.context方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_plots
# 需要导入模块: from matplotlib import style [as 别名]
# 或者: from matplotlib.style import context [as 别名]
def save_plots(stylesheet, image_ext=IMAGE_EXT, base_dir=None):
"""Save plots for a given stylessheet.
Each script in the plot-scripts directory is run with the given
stylesheet and saved to a subdirectory in `base_dir`.
"""
base_dir = base_dir or disk.images_dir
style_dir = pth.join(base_dir, base_filename(stylesheet))
with style.context(stylesheet):
# Create directory after trying to load style so we don't create an
# empty directory if the stylesheet isn't valid.
if not pth.exists(style_dir):
os.makedirs(style_dir)
for script in disk.iter_plot_scripts():
image_name = base_filename(script) + image_ext
with open(script) as f:
exec(compile(f.read(), script, 'exec'), {})
plt.savefig(pth.join(style_dir, image_name))
plt.close('all')
示例2: test_use
# 需要导入模块: from matplotlib import style [as 别名]
# 或者: from matplotlib.style import context [as 别名]
def test_use():
mpl.rcParams[PARAM] = 'gray'
with temp_style('test', DUMMY_SETTINGS):
with style.context('test'):
assert mpl.rcParams[PARAM] == VALUE
示例3: test_use_url
# 需要导入模块: from matplotlib import style [as 别名]
# 或者: from matplotlib.style import context [as 别名]
def test_use_url():
with temp_style('test', DUMMY_SETTINGS):
with style.context('https://gist.github.com/adrn/6590261/raw'):
assert mpl.rcParams['axes.facecolor'] == "#adeade"
示例4: test_context
# 需要导入模块: from matplotlib import style [as 别名]
# 或者: from matplotlib.style import context [as 别名]
def test_context():
mpl.rcParams[PARAM] = 'gray'
with temp_style('test', DUMMY_SETTINGS):
with style.context('test'):
assert mpl.rcParams[PARAM] == VALUE
# Check that this value is reset after the exiting the context.
assert mpl.rcParams[PARAM] == 'gray'
示例5: test_context_with_dict
# 需要导入模块: from matplotlib import style [as 别名]
# 或者: from matplotlib.style import context [as 别名]
def test_context_with_dict():
original_value = 'gray'
other_value = 'blue'
mpl.rcParams[PARAM] = original_value
with style.context({PARAM: other_value}):
assert mpl.rcParams[PARAM] == other_value
assert mpl.rcParams[PARAM] == original_value
示例6: test_context_with_dict_after_namedstyle
# 需要导入模块: from matplotlib import style [as 别名]
# 或者: from matplotlib.style import context [as 别名]
def test_context_with_dict_after_namedstyle():
# Test dict after style name where dict modifies the same parameter.
original_value = 'gray'
other_value = 'blue'
mpl.rcParams[PARAM] = original_value
with temp_style('test', DUMMY_SETTINGS):
with style.context(['test', {PARAM: other_value}]):
assert mpl.rcParams[PARAM] == other_value
assert mpl.rcParams[PARAM] == original_value
示例7: test_context_with_union_of_dict_and_namedstyle
# 需要导入模块: from matplotlib import style [as 别名]
# 或者: from matplotlib.style import context [as 别名]
def test_context_with_union_of_dict_and_namedstyle():
# Test dict after style name where dict modifies the a different parameter.
original_value = 'gray'
other_param = 'text.usetex'
other_value = True
d = {other_param: other_value}
mpl.rcParams[PARAM] = original_value
mpl.rcParams[other_param] = (not other_value)
with temp_style('test', DUMMY_SETTINGS):
with style.context(['test', d]):
assert mpl.rcParams[PARAM] == VALUE
assert mpl.rcParams[other_param] == other_value
assert mpl.rcParams[PARAM] == original_value
assert mpl.rcParams[other_param] == (not other_value)
示例8: test_context_with_badparam
# 需要导入模块: from matplotlib import style [as 别名]
# 或者: from matplotlib.style import context [as 别名]
def test_context_with_badparam():
original_value = 'gray'
other_value = 'blue'
d = OrderedDict([(PARAM, original_value), ('badparam', None)])
with style.context({PARAM: other_value}):
assert mpl.rcParams[PARAM] == other_value
x = style.context([d])
with pytest.raises(KeyError):
with x:
pass
assert mpl.rcParams[PARAM] == other_value
示例9: test_alias
# 需要导入模块: from matplotlib import style [as 别名]
# 或者: from matplotlib.style import context [as 别名]
def test_alias(equiv_styles):
rc_dicts = []
for sty in equiv_styles:
with style.context(sty):
rc_dicts.append(dict(mpl.rcParams))
rc_base = rc_dicts[0]
for nm, rc in zip(equiv_styles[1:], rc_dicts[1:]):
assert rc_base == rc