Python matplotlib.style.context() Examples
The following are 30
code examples of matplotlib.style.context().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
matplotlib.style
, or try the search function
.
Example #1
Source File: build.py From matplotlib-style-gallery with BSD 3-Clause "New" or "Revised" License | 6 votes |
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')
Example #2
Source File: test_style.py From twitter-stock-recommendation with MIT License | 5 votes |
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"
Example #3
Source File: test_style.py From coffeegrindsize with MIT License | 5 votes |
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'
Example #4
Source File: test_style.py From coffeegrindsize with MIT License | 5 votes |
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
Example #5
Source File: test_style.py From coffeegrindsize with MIT License | 5 votes |
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
Example #6
Source File: test_style.py From coffeegrindsize with MIT License | 5 votes |
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)
Example #7
Source File: test_style.py From coffeegrindsize with MIT License | 5 votes |
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
Example #8
Source File: test_style.py From coffeegrindsize with MIT License | 5 votes |
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
Example #9
Source File: test_style.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_use(): mpl.rcParams[PARAM] = 'gray' with temp_style('test', DUMMY_SETTINGS): with style.context('test'): assert mpl.rcParams[PARAM] == VALUE
Example #10
Source File: test_style.py From coffeegrindsize with MIT License | 5 votes |
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"
Example #11
Source File: test_style.py From twitter-stock-recommendation with MIT License | 5 votes |
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'
Example #12
Source File: test_style.py From twitter-stock-recommendation with MIT License | 5 votes |
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
Example #13
Source File: test_style.py From twitter-stock-recommendation with MIT License | 5 votes |
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
Example #14
Source File: test_style.py From twitter-stock-recommendation with MIT License | 5 votes |
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)
Example #15
Source File: test_style.py From twitter-stock-recommendation with MIT License | 5 votes |
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
Example #16
Source File: test_style.py From twitter-stock-recommendation with MIT License | 5 votes |
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
Example #17
Source File: test_patches.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_multi_color_hatch(): fig, ax = plt.subplots() rects = ax.bar(range(5), range(1, 6)) for i, rect in enumerate(rects): rect.set_facecolor('none') rect.set_edgecolor('C{}'.format(i)) rect.set_hatch('/') for i in range(5): with mstyle.context({'hatch.color': 'C{}'.format(i)}): r = Rectangle((i - .8 / 2, 5), .8, 1, hatch='//', fc='none') ax.add_patch(r)
Example #18
Source File: test_style.py From coffeegrindsize with MIT License | 5 votes |
def test_use(): mpl.rcParams[PARAM] = 'gray' with temp_style('test', DUMMY_SETTINGS): with style.context('test'): assert mpl.rcParams[PARAM] == VALUE
Example #19
Source File: test_style.py From ImageFusion with MIT License | 5 votes |
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'
Example #20
Source File: test_style.py From ImageFusion with MIT License | 5 votes |
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"
Example #21
Source File: test_style.py From ImageFusion with MIT License | 5 votes |
def test_use(): mpl.rcParams[PARAM] = 'gray' with temp_style('test', DUMMY_SETTINGS): with style.context('test'): assert mpl.rcParams[PARAM] == VALUE
Example #22
Source File: test_style.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example #23
Source File: test_style.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example #24
Source File: test_style.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #25
Source File: test_style.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example #26
Source File: test_style.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example #27
Source File: test_style.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
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'
Example #28
Source File: test_style.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
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"
Example #29
Source File: test_style.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_use(): mpl.rcParams[PARAM] = 'gray' with temp_style('test', DUMMY_SETTINGS): with style.context('test'): assert mpl.rcParams[PARAM] == VALUE
Example #30
Source File: test_style.py From neural-network-animation with MIT License | 5 votes |
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'