Esempio n. 1
0
def test_RcParams_class():
    rc = mpl.RcParams({
        'font.cursive':
        ['Apple Chancery', 'Textile', 'Zapf Chancery', 'cursive'],
        'font.family':
        'sans-serif',
        'font.weight':
        'normal',
        'font.size':
        12
    })

    expected_repr = """
RcParams({'font.cursive': ['Apple Chancery',
                           'Textile',
                           'Zapf Chancery',
                           'cursive'],
          'font.family': ['sans-serif'],
          'font.size': 12.0,
          'font.weight': 'normal'})""".lstrip()

    assert expected_repr == repr(rc)

    expected_str = """
font.cursive: ['Apple Chancery', 'Textile', 'Zapf Chancery', 'cursive']
font.family: ['sans-serif']
font.size: 12.0
font.weight: normal""".lstrip()

    assert expected_str == str(rc)

    # test the find_all functionality
    assert ['font.cursive', 'font.size'] == sorted(rc.find_all('i[vz]'))
    assert ['font.family'] == list(rc.find_all('family'))
Esempio n. 2
0
def test_rcparams_update():
    rc = mpl.RcParams({'figure.figsize': (3.5, 42)})
    bad_dict = {'figure.figsize': (3.5, 42, 1)}
    # make sure validation happens on input
    with pytest.raises(ValueError), \
         pytest.warns(UserWarning, match="validate"):
        rc.update(bad_dict)
Esempio n. 3
0
def test_rcparams_init():
    with pytest.raises(ValueError):
        with warnings.catch_warnings():
            warnings.filterwarnings('ignore',
                                    message='.*(validate)',
                                    category=UserWarning)
            mpl.RcParams({'figure.figsize': (3.5, 42, 1)})
Esempio n. 4
0
def test_rcparams_init():
    if sys.version_info[:2] < (2, 7):
        raise nose.SkipTest("assert_raises as context manager "
                            "not supported with Python < 2.7")
    with assert_raises(ValueError):
        with warnings.catch_warnings():
            warnings.filterwarnings('ignore',
                                    message='.*(validate)',
                                    category=UserWarning)
            mpl.RcParams({'figure.figsize': (3.5, 42, 1)})
def test_rcparams_update():
    rc = mpl.RcParams({'figure.figsize': (3.5, 42)})
    bad_dict = {'figure.figsize': (3.5, 42, 1)}
    # make sure validation happens on input
    with pytest.raises(ValueError):

        with warnings.catch_warnings():
            warnings.filterwarnings('ignore',
                                    message='.*(validate)',
                                    category=UserWarning)
            rc.update(bad_dict)
Esempio n. 6
0
def test_RcParams_class():
    rc = mpl.RcParams({
        'font.cursive':
        ['Apple Chancery', 'Textile', 'Zapf Chancery', 'cursive'],
        'font.family':
        'sans-serif',
        'font.weight':
        'normal',
        'font.size':
        12
    })

    if six.PY3:
        expected_repr = """
RcParams({'font.cursive': ['Apple Chancery',
                           'Textile',
                           'Zapf Chancery',
                           'cursive'],
          'font.family': ['sans-serif'],
          'font.size': 12.0,
          'font.weight': 'normal'})""".lstrip()
    else:
        expected_repr = """
RcParams({u'font.cursive': [u'Apple Chancery',
                            u'Textile',
                            u'Zapf Chancery',
                            u'cursive'],
          u'font.family': [u'sans-serif'],
          u'font.size': 12.0,
          u'font.weight': u'normal'})""".lstrip()

    assert_str_equal(expected_repr, repr(rc))

    if six.PY3:
        expected_str = """
font.cursive: ['Apple Chancery', 'Textile', 'Zapf Chancery', 'cursive']
font.family: ['sans-serif']
font.size: 12.0
font.weight: normal""".lstrip()
    else:
        expected_str = """
font.cursive: [u'Apple Chancery', u'Textile', u'Zapf Chancery', u'cursive']
font.family: [u'sans-serif']
font.size: 12.0
font.weight: normal""".lstrip()

    assert_str_equal(expected_str, str(rc))

    # test the find_all functionality
    assert ['font.cursive', 'font.size'] == sorted(rc.find_all('i[vz]').keys())
    assert ['font.family'] == list(six.iterkeys(rc.find_all('family')))
Esempio n. 7
0
def test_rcparams_update():
    if sys.version_info[:2] < (2, 7):
        raise nose.SkipTest("assert_raises as context manager "
                            "not supported with Python < 2.7")
    rc = mpl.RcParams({'figure.figsize': (3.5, 42)})
    bad_dict = {'figure.figsize': (3.5, 42, 1)}
    # make sure validation happens on input
    with assert_raises(ValueError):

        with warnings.catch_warnings():
            warnings.filterwarnings('ignore',
                                    message='.*(validate)',
                                    category=UserWarning)
            rc.update(bad_dict)
Esempio n. 8
0
def mpl_style():
    import matplotlib as mpl
    import matplotlib.pyplot as plt
    rcp = mpl.RcParams()
    rcp["axes.facecolor"] = PLOT_BGCOLOR
    rcp["figure.facecolor"] = PAPER_BGCOLOR

    # ticks
    for xy in ["x", "y"]:
        rcp[f'{xy}tick.color'] = TEXT_COLOR
        rcp[f'{xy}tick.direction'] = "out"
        rcp[f'{xy}tick.major.size'] = 10

    rcp["axes.spines.top"] = False
    rcp["axes.spines.right"] = False
    rcp["axes.grid"] = True
    rcp["grid.color"] = BORDER_COLOR
    rcp["grid.alpha"] = 0.9
    rcp["grid.linewidth"] = 1.0
    rcp["axes.linewidth"] = 2.0
    rcp["axes.edgecolor"] = BORDER_COLOR
    rcp["lines.color"] = BORDER_COLOR
    rcp['axes.prop_cycle'] = mpl.rcsetup.cycler('color', COLOR_CYCLE)

    # fonts and text
    rcp["font.family"] = ["Source Sans Pro", "DejaVu Sans"]
    rcp["font.size"] = 14
    rcp["text.color"] = TEXT_COLOR
    rcp['axes.labelcolor'] = TEXT_COLOR
    rcp['axes.titlesize'] = 'x-large'
    rcp['axes.labelsize'] = 'large'

    plt.style.library["qeds"] = rcp
    plt.style.reload_library()
    plt.style.use("qeds")

    return rcp
Esempio n. 9
0
def test_rcparams_init():
    with pytest.raises(ValueError), \
         pytest.warns(UserWarning, match="validate"):
        mpl.RcParams({'figure.figsize': (3.5, 42, 1)})
Esempio n. 10
0
 def __init__(self, name):
     self.name = name
     self.rc_params = matplotlib.RcParams(RC_DEFAULTS.copy())
     self.preset_params = set()
Esempio n. 11
0
import os
import glob
import appdirs
import matplotlib

import nputils

import pkg_resources

RC_DEFAULTS = matplotlib.RcParams(matplotlib.rcParams.copy())

DEFAULT_PRESETS_PATH = 'presets'

USER_PRESETS_PATH = appdirs.user_data_dir('libwise')

mpl_1_5 = float(matplotlib.__version__[:3]) >= 1.5


def set_rc_preset(preset_name, kargs={}):
    preset = RcPreset.load(preset_name)
    for key, value in kargs.items():
        preset.set_key(key, value)
    preset.apply()


def set_color_cycles(colors):
    if mpl_1_5:
        matplotlib.rcParams["axes.prop_cycle"] = matplotlib.cycler(
            'color', colors)
    else:
        matplotlib.rcParams["axes.color_cycle"] = colors
Esempio n. 12
0
import matplotlib


'''
matplotlib.RcParams (stands for runtime configuration parameters) is class that creates dict-like objects
- It is a class that is defined directly in matplotlib namespace (i.e. it is defined in the __init__.py file)
- It is used to create the "rcParams" object, which is an instance of RcParams that contains (all of?) the default settings for matplotlib (e.g. the
  default figure size)
'''
Esempio n. 13
0
def _validate_legend_loc(loc):
    rc = matplotlib.RcParams()
    rc["legend.loc"] = loc
    return loc