当前位置: 首页>>代码示例>>Python>>正文


Python style.context方法代码示例

本文整理汇总了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') 
开发者ID:tonysyu,项目名称:matplotlib-style-gallery,代码行数:23,代码来源:build.py

示例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 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:7,代码来源:test_style.py

示例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" 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:6,代码来源:test_style.py

示例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' 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:9,代码来源:test_style.py

示例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 
开发者ID:holzschu,项目名称:python3_ios,代码行数:9,代码来源:test_style.py

示例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 
开发者ID:holzschu,项目名称:python3_ios,代码行数:11,代码来源:test_style.py

示例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) 
开发者ID:holzschu,项目名称:python3_ios,代码行数:16,代码来源:test_style.py

示例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 
开发者ID:holzschu,项目名称:python3_ios,代码行数:13,代码来源:test_style.py

示例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 
开发者ID:holzschu,项目名称:python3_ios,代码行数:11,代码来源:test_style.py


注:本文中的matplotlib.style.context方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。