Python matplotlib.style() Examples

The following are 25 code examples of matplotlib.style(). 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 , or try the search function .
Example #1
Source File: pyplot.py    From GraphicDesignPatternByPython with MIT License 5 votes vote down vote up
def ticklabel_format(
        *, axis='both', style='', scilimits=None, useOffset=None,
        useLocale=None, useMathText=None):
    return gca().ticklabel_format(
        axis=axis, style=style, scilimits=scilimits,
        useOffset=useOffset, useLocale=useLocale,
        useMathText=useMathText)

# Autogenerated by boilerplate.py.  Do not edit as changes will be lost. 
Example #2
Source File: decorators.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def setup(self):
        func = self.func
        plt.close('all')
        self.setup_class()
        try:
            matplotlib.style.use(self.style)
            matplotlib.testing.set_font_settings_for_testing()
            func()
            assert len(plt.get_fignums()) == len(self.baseline_images), (
                "Test generated {} images but there are {} baseline images"
                .format(len(plt.get_fignums()), len(self.baseline_images)))
        except:
            # Restore original settings before raising errors.
            self.teardown_class()
            raise 
Example #3
Source File: decorators.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def __init__(self, baseline_images, extensions, tol,
                 freetype_version, remove_text, savefig_kwargs, style):
        _ImageComparisonBase.__init__(self, tol, remove_text, savefig_kwargs)
        self.baseline_images = baseline_images
        self.extensions = extensions
        self.freetype_version = freetype_version
        self.style = style 
Example #4
Source File: decorators.py    From CogAlg with MIT License 5 votes vote down vote up
def setup(self):
        func = self.func
        plt.close('all')
        self.setup_class()
        try:
            matplotlib.style.use(self.style)
            matplotlib.testing.set_font_settings_for_testing()
            func()
            assert len(plt.get_fignums()) == len(self.baseline_images), (
                "Test generated {} images but there are {} baseline images"
                .format(len(plt.get_fignums()), len(self.baseline_images)))
        except:
            # Restore original settings before raising errors.
            self.teardown_class()
            raise 
Example #5
Source File: decorators.py    From CogAlg with MIT License 5 votes vote down vote up
def __init__(self, baseline_images, extensions, tol,
                 freetype_version, remove_text, savefig_kwargs, style):
        _ImageComparisonBase.__init__(self, tol, remove_text, savefig_kwargs)
        self.baseline_images = baseline_images
        self.extensions = extensions
        self.freetype_version = freetype_version
        self.style = style 
Example #6
Source File: decorators.py    From CogAlg with MIT License 5 votes vote down vote up
def cleanup(style=None):
    """
    A decorator to ensure that any global state is reset before
    running a test.

    Parameters
    ----------
    style : str, optional
        The name of the style to apply.
    """

    # If cleanup is used without arguments, `style` will be a callable, and we
    # pass it directly to the wrapper generator.  If cleanup if called with an
    # argument, it is a string naming a style, and the function will be passed
    # as an argument to what we return.  This is a confusing, but somewhat
    # standard, pattern for writing a decorator with optional arguments.

    def make_cleanup(func):
        if inspect.isgeneratorfunction(func):
            @functools.wraps(func)
            def wrapped_callable(*args, **kwargs):
                with _cleanup_cm(), matplotlib.style.context(style):
                    yield from func(*args, **kwargs)
        else:
            @functools.wraps(func)
            def wrapped_callable(*args, **kwargs):
                with _cleanup_cm(), matplotlib.style.context(style):
                    func(*args, **kwargs)

        return wrapped_callable

    if isinstance(style, str):
        return make_cleanup
    else:
        result = make_cleanup(style)
        # Default of mpl_test_settings fixture and image_comparison too.
        style = '_classic_test'
        return result 
Example #7
Source File: pyplot.py    From CogAlg with MIT License 5 votes vote down vote up
def ticklabel_format(
        *, axis='both', style='', scilimits=None, useOffset=None,
        useLocale=None, useMathText=None):
    return gca().ticklabel_format(
        axis=axis, style=style, scilimits=scilimits,
        useOffset=useOffset, useLocale=useLocale,
        useMathText=useMathText)


# Autogenerated by boilerplate.py.  Do not edit as changes will be lost. 
Example #8
Source File: decorators.py    From coffeegrindsize with MIT License 5 votes vote down vote up
def setup(self):
        func = self.func
        plt.close('all')
        self.setup_class()
        try:
            matplotlib.style.use(self.style)
            matplotlib.testing.set_font_settings_for_testing()
            func()
            assert len(plt.get_fignums()) == len(self.baseline_images), (
                "Test generated {} images but there are {} baseline images"
                .format(len(plt.get_fignums()), len(self.baseline_images)))
        except:
            # Restore original settings before raising errors.
            self.teardown_class()
            raise 
Example #9
Source File: decorators.py    From coffeegrindsize with MIT License 5 votes vote down vote up
def __init__(self, baseline_images, extensions, tol,
                 freetype_version, remove_text, savefig_kwargs, style):
        _ImageComparisonBase.__init__(self, tol, remove_text, savefig_kwargs)
        self.baseline_images = baseline_images
        self.extensions = extensions
        self.freetype_version = freetype_version
        self.style = style 
Example #10
Source File: decorators.py    From coffeegrindsize with MIT License 5 votes vote down vote up
def cleanup(style=None):
    """
    A decorator to ensure that any global state is reset before
    running a test.

    Parameters
    ----------
    style : str, optional
        The name of the style to apply.
    """

    # If cleanup is used without arguments, `style` will be a callable, and we
    # pass it directly to the wrapper generator.  If cleanup if called with an
    # argument, it is a string naming a style, and the function will be passed
    # as an argument to what we return.  This is a confusing, but somewhat
    # standard, pattern for writing a decorator with optional arguments.

    def make_cleanup(func):
        if inspect.isgeneratorfunction(func):
            @functools.wraps(func)
            def wrapped_callable(*args, **kwargs):
                with _cleanup_cm(), matplotlib.style.context(style):
                    yield from func(*args, **kwargs)
        else:
            @functools.wraps(func)
            def wrapped_callable(*args, **kwargs):
                with _cleanup_cm(), matplotlib.style.context(style):
                    func(*args, **kwargs)

        return wrapped_callable

    if isinstance(style, str):
        return make_cleanup
    else:
        result = make_cleanup(style)
        # Default of mpl_test_settings fixture and image_comparison too.
        style = '_classic_test'
        return result 
Example #11
Source File: pyplot.py    From coffeegrindsize with MIT License 5 votes vote down vote up
def ticklabel_format(
        *, axis='both', style='', scilimits=None, useOffset=None,
        useLocale=None, useMathText=None):
    return gca().ticklabel_format(
        axis=axis, style=style, scilimits=scilimits,
        useOffset=useOffset, useLocale=useLocale,
        useMathText=useMathText)


# Autogenerated by boilerplate.py.  Do not edit as changes will be lost. 
Example #12
Source File: decorators.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def setup(self):
        func = self.func
        plt.close('all')
        self.setup_class()
        try:
            matplotlib.style.use(self.style)
            matplotlib.testing.set_font_settings_for_testing()
            func()
            assert len(plt.get_fignums()) == len(self.baseline_images), (
                "Test generated {} images but there are {} baseline images"
                .format(len(plt.get_fignums()), len(self.baseline_images)))
        except:
            # Restore original settings before raising errors.
            self.teardown_class()
            raise 
Example #13
Source File: decorators.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __init__(self, baseline_images, extensions, tol,
                 freetype_version, remove_text, savefig_kwargs, style):
        _ImageComparisonBase.__init__(self, tol, remove_text, savefig_kwargs)
        self.baseline_images = baseline_images
        self.extensions = extensions
        self.freetype_version = freetype_version
        self.style = style 
Example #14
Source File: decorators.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def cleanup(style=None):
    """
    A decorator to ensure that any global state is reset before
    running a test.

    Parameters
    ----------
    style : str, optional
        The name of the style to apply.
    """

    # If cleanup is used without arguments, `style` will be a callable, and we
    # pass it directly to the wrapper generator.  If cleanup if called with an
    # argument, it is a string naming a style, and the function will be passed
    # as an argument to what we return.  This is a confusing, but somewhat
    # standard, pattern for writing a decorator with optional arguments.

    def make_cleanup(func):
        if inspect.isgeneratorfunction(func):
            @functools.wraps(func)
            def wrapped_callable(*args, **kwargs):
                with _cleanup_cm(), matplotlib.style.context(style):
                    yield from func(*args, **kwargs)
        else:
            @functools.wraps(func)
            def wrapped_callable(*args, **kwargs):
                with _cleanup_cm(), matplotlib.style.context(style):
                    func(*args, **kwargs)

        return wrapped_callable

    if isinstance(style, str):
        return make_cleanup
    else:
        result = make_cleanup(style)
        # Default of mpl_test_settings fixture and image_comparison too.
        style = '_classic_test'
        return result 
Example #15
Source File: pyplot.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def ticklabel_format(
        *, axis='both', style='', scilimits=None, useOffset=None,
        useLocale=None, useMathText=None):
    return gca().ticklabel_format(
        axis=axis, style=style, scilimits=scilimits,
        useOffset=useOffset, useLocale=useLocale,
        useMathText=useMathText)


# Autogenerated by boilerplate.py.  Do not edit as changes will be lost. 
Example #16
Source File: decorators.py    From GraphicDesignPatternByPython with MIT License 5 votes vote down vote up
def setup(self):
        func = self.func
        plt.close('all')
        self.setup_class()
        try:
            matplotlib.style.use(self.style)
            matplotlib.testing.set_font_settings_for_testing()
            func()
            assert len(plt.get_fignums()) == len(self.baseline_images), (
                "Test generated {} images but there are {} baseline images"
                .format(len(plt.get_fignums()), len(self.baseline_images)))
        except:
            # Restore original settings before raising errors.
            self.teardown_class()
            raise 
Example #17
Source File: decorators.py    From GraphicDesignPatternByPython with MIT License 5 votes vote down vote up
def __init__(self, baseline_images, extensions, tol,
                 freetype_version, remove_text, savefig_kwargs, style):
        _ImageComparisonBase.__init__(self, tol, remove_text, savefig_kwargs)
        self.baseline_images = baseline_images
        self.extensions = extensions
        self.freetype_version = freetype_version
        self.style = style 
Example #18
Source File: decorators.py    From GraphicDesignPatternByPython with MIT License 5 votes vote down vote up
def cleanup(style=None):
    """
    A decorator to ensure that any global state is reset before
    running a test.

    Parameters
    ----------
    style : str, optional
        The name of the style to apply.
    """

    # If cleanup is used without arguments, `style` will be a callable, and we
    # pass it directly to the wrapper generator.  If cleanup if called with an
    # argument, it is a string naming a style, and the function will be passed
    # as an argument to what we return.  This is a confusing, but somewhat
    # standard, pattern for writing a decorator with optional arguments.

    def make_cleanup(func):
        if inspect.isgeneratorfunction(func):
            @functools.wraps(func)
            def wrapped_callable(*args, **kwargs):
                with _cleanup_cm(), matplotlib.style.context(style):
                    yield from func(*args, **kwargs)
        else:
            @functools.wraps(func)
            def wrapped_callable(*args, **kwargs):
                with _cleanup_cm(), matplotlib.style.context(style):
                    func(*args, **kwargs)

        return wrapped_callable

    if isinstance(style, str):
        return make_cleanup
    else:
        result = make_cleanup(style)
        # Default of mpl_test_settings fixture and image_comparison too.
        style = '_classic_test'
        return result 
Example #19
Source File: pyplot.py    From coffeegrindsize with MIT License 4 votes vote down vote up
def xkcd(scale=1, length=100, randomness=2):
    """
    Turn on `xkcd <https://xkcd.com/>`_ sketch-style drawing mode.
    This will only have effect on things drawn after this function is
    called.

    For best results, the "Humor Sans" font should be installed: it is
    not included with matplotlib.

    Parameters
    ----------
    scale : float, optional
        The amplitude of the wiggle perpendicular to the source line.
    length : float, optional
        The length of the wiggle along the line.
    randomness : float, optional
        The scale factor by which the length is shrunken or expanded.

    Notes
    -----
    This function works by a number of rcParams, so it will probably
    override others you have set before.

    If you want the effects of this function to be temporary, it can
    be used as a context manager, for example::

        with plt.xkcd():
            # This figure will be in XKCD-style
            fig1 = plt.figure()
            # ...

        # This figure will be in regular style
        fig2 = plt.figure()
    """
    if rcParams['text.usetex']:
        raise RuntimeError(
            "xkcd mode is not compatible with text.usetex = True")

    from matplotlib import patheffects
    return rc_context({
        'font.family': ['xkcd', 'xkcd Script', 'Humor Sans', 'Comic Sans MS'],
        'font.size': 14.0,
        'path.sketch': (scale, length, randomness),
        'path.effects': [patheffects.withStroke(linewidth=4, foreground="w")],
        'axes.linewidth': 1.5,
        'lines.linewidth': 2.0,
        'figure.facecolor': 'white',
        'grid.linewidth': 0.0,
        'axes.grid': False,
        'axes.unicode_minus': False,
        'axes.edgecolor': 'black',
        'xtick.major.size': 8,
        'xtick.major.width': 3,
        'ytick.major.size': 8,
        'ytick.major.width': 3,
    })


## Figures ## 
Example #20
Source File: pyplot.py    From CogAlg with MIT License 4 votes vote down vote up
def xkcd(scale=1, length=100, randomness=2):
    """
    Turn on `xkcd <https://xkcd.com/>`_ sketch-style drawing mode.
    This will only have effect on things drawn after this function is
    called.

    For best results, the "Humor Sans" font should be installed: it is
    not included with matplotlib.

    Parameters
    ----------
    scale : float, optional
        The amplitude of the wiggle perpendicular to the source line.
    length : float, optional
        The length of the wiggle along the line.
    randomness : float, optional
        The scale factor by which the length is shrunken or expanded.

    Notes
    -----
    This function works by a number of rcParams, so it will probably
    override others you have set before.

    If you want the effects of this function to be temporary, it can
    be used as a context manager, for example::

        with plt.xkcd():
            # This figure will be in XKCD-style
            fig1 = plt.figure()
            # ...

        # This figure will be in regular style
        fig2 = plt.figure()
    """
    if rcParams['text.usetex']:
        raise RuntimeError(
            "xkcd mode is not compatible with text.usetex = True")

    from matplotlib import patheffects
    return rc_context({
        'font.family': ['xkcd', 'xkcd Script', 'Humor Sans', 'Comic Sans MS'],
        'font.size': 14.0,
        'path.sketch': (scale, length, randomness),
        'path.effects': [patheffects.withStroke(linewidth=4, foreground="w")],
        'axes.linewidth': 1.5,
        'lines.linewidth': 2.0,
        'figure.facecolor': 'white',
        'grid.linewidth': 0.0,
        'axes.grid': False,
        'axes.unicode_minus': False,
        'axes.edgecolor': 'black',
        'xtick.major.size': 8,
        'xtick.major.width': 3,
        'ytick.major.size': 8,
        'ytick.major.width': 3,
    })


## Figures ## 
Example #21
Source File: pyplot.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def xkcd(scale=1, length=100, randomness=2):
    """
    Turn on `xkcd <https://xkcd.com/>`_ sketch-style drawing mode.
    This will only have effect on things drawn after this function is
    called.

    For best results, the "Humor Sans" font should be installed: it is
    not included with matplotlib.

    Parameters
    ----------
    scale : float, optional
        The amplitude of the wiggle perpendicular to the source line.
    length : float, optional
        The length of the wiggle along the line.
    randomness : float, optional
        The scale factor by which the length is shrunken or expanded.

    Notes
    -----
    This function works by a number of rcParams, so it will probably
    override others you have set before.

    If you want the effects of this function to be temporary, it can
    be used as a context manager, for example::

        with plt.xkcd():
            # This figure will be in XKCD-style
            fig1 = plt.figure()
            # ...

        # This figure will be in regular style
        fig2 = plt.figure()
    """
    if rcParams['text.usetex']:
        raise RuntimeError(
            "xkcd mode is not compatible with text.usetex = True")

    from matplotlib import patheffects
    return rc_context({
        'font.family': ['xkcd', 'xkcd Script', 'Humor Sans', 'Comic Sans MS'],
        'font.size': 14.0,
        'path.sketch': (scale, length, randomness),
        'path.effects': [patheffects.withStroke(linewidth=4, foreground="w")],
        'axes.linewidth': 1.5,
        'lines.linewidth': 2.0,
        'figure.facecolor': 'white',
        'grid.linewidth': 0.0,
        'axes.grid': False,
        'axes.unicode_minus': False,
        'axes.edgecolor': 'black',
        'xtick.major.size': 8,
        'xtick.major.width': 3,
        'ytick.major.size': 8,
        'ytick.major.width': 3,
    })


## Figures ## 
Example #22
Source File: pyplot.py    From twitter-stock-recommendation with MIT License 4 votes vote down vote up
def xkcd(scale=1, length=100, randomness=2):
    """
    Turns on `xkcd <https://xkcd.com/>`_ sketch-style drawing mode.
    This will only have effect on things drawn after this function is
    called.

    For best results, the "Humor Sans" font should be installed: it is
    not included with matplotlib.

    Parameters
    ----------
    scale : float, optional
        The amplitude of the wiggle perpendicular to the source line.
    length : float, optional
        The length of the wiggle along the line.
    randomness : float, optional
        The scale factor by which the length is shrunken or expanded.

    Notes
    -----
    This function works by a number of rcParams, so it will probably
    override others you have set before.

    If you want the effects of this function to be temporary, it can
    be used as a context manager, for example::

        with plt.xkcd():
            # This figure will be in XKCD-style
            fig1 = plt.figure()
            # ...

        # This figure will be in regular style
        fig2 = plt.figure()
    """
    if rcParams['text.usetex']:
        raise RuntimeError(
            "xkcd mode is not compatible with text.usetex = True")

    from matplotlib import patheffects
    return rc_context({
        'font.family': ['xkcd', 'Humor Sans', 'Comic Sans MS'],
        'font.size': 14.0,
        'path.sketch': (scale, length, randomness),
        'path.effects': [patheffects.withStroke(linewidth=4, foreground="w")],
        'axes.linewidth': 1.5,
        'lines.linewidth': 2.0,
        'figure.facecolor': 'white',
        'grid.linewidth': 0.0,
        'axes.grid': False,
        'axes.unicode_minus': False,
        'axes.edgecolor': 'black',
        'xtick.major.size': 8,
        'xtick.major.width': 3,
        'ytick.major.size': 8,
        'ytick.major.width': 3,
    })


## Figures ## 
Example #23
Source File: decorators.py    From twitter-stock-recommendation with MIT License 4 votes vote down vote up
def cleanup(style=None):
    """
    A decorator to ensure that any global state is reset before
    running a test.

    Parameters
    ----------
    style : str, optional
        The name of the style to apply.
    """

    # If cleanup is used without arguments, `style` will be a
    # callable, and we pass it directly to the wrapper generator.  If
    # cleanup if called with an argument, it is a string naming a
    # style, and the function will be passed as an argument to what we
    # return.  This is a confusing, but somewhat standard, pattern for
    # writing a decorator with optional arguments.

    def make_cleanup(func):
        if inspect.isgeneratorfunction(func):
            @functools.wraps(func)
            def wrapped_callable(*args, **kwargs):
                original_units_registry = matplotlib.units.registry.copy()
                original_settings = mpl.rcParams.copy()
                matplotlib.style.use(style)
                try:
                    for yielded in func(*args, **kwargs):
                        yield yielded
                finally:
                    _do_cleanup(original_units_registry,
                                original_settings)
        else:
            @functools.wraps(func)
            def wrapped_callable(*args, **kwargs):
                original_units_registry = matplotlib.units.registry.copy()
                original_settings = mpl.rcParams.copy()
                matplotlib.style.use(style)
                try:
                    func(*args, **kwargs)
                finally:
                    _do_cleanup(original_units_registry,
                                original_settings)

        return wrapped_callable

    if isinstance(style, six.string_types):
        return make_cleanup
    else:
        result = make_cleanup(style)
        # Default of mpl_test_settings fixture and image_comparison too.
        style = '_classic_test'
        return result 
Example #24
Source File: pyplot.py    From GraphicDesignPatternByPython with MIT License 4 votes vote down vote up
def xkcd(scale=1, length=100, randomness=2):
    """
    Turn on `xkcd <https://xkcd.com/>`_ sketch-style drawing mode.
    This will only have effect on things drawn after this function is
    called.

    For best results, the "Humor Sans" font should be installed: it is
    not included with matplotlib.

    Parameters
    ----------
    scale : float, optional
        The amplitude of the wiggle perpendicular to the source line.
    length : float, optional
        The length of the wiggle along the line.
    randomness : float, optional
        The scale factor by which the length is shrunken or expanded.

    Notes
    -----
    This function works by a number of rcParams, so it will probably
    override others you have set before.

    If you want the effects of this function to be temporary, it can
    be used as a context manager, for example::

        with plt.xkcd():
            # This figure will be in XKCD-style
            fig1 = plt.figure()
            # ...

        # This figure will be in regular style
        fig2 = plt.figure()
    """
    if rcParams['text.usetex']:
        raise RuntimeError(
            "xkcd mode is not compatible with text.usetex = True")

    from matplotlib import patheffects
    return rc_context({
        'font.family': ['xkcd', 'Humor Sans', 'Comic Sans MS'],
        'font.size': 14.0,
        'path.sketch': (scale, length, randomness),
        'path.effects': [patheffects.withStroke(linewidth=4, foreground="w")],
        'axes.linewidth': 1.5,
        'lines.linewidth': 2.0,
        'figure.facecolor': 'white',
        'grid.linewidth': 0.0,
        'axes.grid': False,
        'axes.unicode_minus': False,
        'axes.edgecolor': 'black',
        'xtick.major.size': 8,
        'xtick.major.width': 3,
        'ytick.major.size': 8,
        'ytick.major.width': 3,
    })


## Figures ## 
Example #25
Source File: decorators.py    From twitter-stock-recommendation with MIT License 4 votes vote down vote up
def _pytest_image_comparison(baseline_images, extensions, tol,
                             freetype_version, remove_text, savefig_kwargs,
                             style):
    """
    Decorate function with image comparison for pytest.

    This function creates a decorator that wraps a figure-generating function
    with image comparison code. Pytest can become confused if we change the
    signature of the function, so we indirectly pass anything we need via the
    `mpl_image_comparison_parameters` fixture and extra markers.
    """
    import pytest

    extensions = map(_mark_xfail_if_format_is_uncomparable, extensions)

    def decorator(func):
        # Parameter indirection; see docstring above and comment below.
        @pytest.mark.usefixtures('mpl_image_comparison_parameters')
        @pytest.mark.parametrize('extension', extensions)
        @pytest.mark.baseline_images(baseline_images)
        # END Parameter indirection.
        @pytest.mark.style(style)
        @_checked_on_freetype_version(freetype_version)
        @functools.wraps(func)
        def wrapper(*args, **kwargs):
            __tracebackhide__ = True
            img = _ImageComparisonBase(tol=tol, remove_text=remove_text,
                                       savefig_kwargs=savefig_kwargs)
            img.delayed_init(func)
            matplotlib.testing.set_font_settings_for_testing()
            func(*args, **kwargs)

            # Parameter indirection:
            # This is hacked on via the mpl_image_comparison_parameters fixture
            # so that we don't need to modify the function's real signature for
            # any parametrization. Modifying the signature is very very tricky
            # and likely to confuse pytest.
            baseline_images, extension = func.parameters

            assert len(plt.get_fignums()) == len(baseline_images), (
                "Test generated {} images but there are {} baseline images"
                .format(len(plt.get_fignums()), len(baseline_images)))
            for idx, baseline in enumerate(baseline_images):
                img.compare(idx, baseline, extension)

        wrapper.__wrapped__ = func  # For Python 2.7.
        return _copy_metadata(func, wrapper)

    return decorator