Beispiel #1
0
def use(arg, warn=True):
    """
    Set the matplotlib backend to one of the known backends.
    The argument is case-insensitive.  For the Cairo backend,
    the argument can have an extension to indicate the type of
    output.  Example:
        use('cairo.pdf')
    will specify a default of pdf output generated by Cairo.
    Note: this function must be called *before* importing pylab for
    the first time; or, if you are not using pylab, it must be called
    before importing matplotlib.backends.  If warn is True, a warning
    is issued if you try and callthis after pylab or pyplot have been
    loaded.  In certain black magic use cases, eg
    pyplot.switch_backends, we are doing the reloading necessary to
    make the backend switch work (in some cases, eg pure image
    backends) so one can set warn=False to supporess the warnings
    """
    if "matplotlib.backends" in sys.modules:
        if warn:
            warnings.warn(_use_error_msg)
        return
    arg = arg.lower()
    if arg.startswith("module://"):
        name = arg
    else:
        be_parts = arg.split(".")
        name = validate_backend(be_parts[0])
        if len(be_parts) > 1:
            if name == "cairo":
                rcParams["cairo.format"] = validate_cairo_format(be_parts[1])
            else:
                raise ValueError("Only cairo backend has a format option")
    rcParams["backend"] = name
Beispiel #2
0
def use(arg, warn=True):
    """
    Set the matplotlib backend to one of the known backends.

    The argument is case-insensitive.  For the Cairo backend,
    the argument can have an extension to indicate the type of
    output.  Example:

        use('cairo.pdf')

    will specify a default of pdf output generated by Cairo.

    Note: this function must be called *before* importing pylab for
    the first time; or, if you are not using pylab, it must be called
    before importing matplotlib.backends.  If warn is True, a warning
    is issued if you try and callthis after pylab or pyplot have been
    loaded.  In certain black magic use cases, eg
    pyplot.switch_backends, we are doing the reloading necessary to
    make the backend switch work (in some cases, eg pure image
    backends) so one can set warn=False to supporess the warnings
    """
    if 'matplotlib.backends' in sys.modules:
        if warn: warnings.warn(_use_error_msg)
    be_parts = arg.split('.')
    name = validate_backend(be_parts[0])
    rcParams['backend'] = name
    if name == 'Cairo' and len(be_parts) > 1:
        rcParams['cairo.format'] = validate_cairo_format(be_parts[1])
Beispiel #3
0
def use(arg):
    """
    Set the matplotlib backend to one of the known backends.

    The argument is case-insensitive.  For the Cairo backend,
    the argument can have an extension to indicate the type of
    output.  Example:

        use('cairo.pdf')

    will specify a default of pdf output generated by Cairo.

    Note: this function must be called *before* importing pylab
    for the first time; or, if you are not using pylab, it must
    be called before importing matplotlib.backends.
    """
    if 'matplotlib.backends' in sys.modules:
        raise RuntimeError(_use_error_msg)
    be_parts = arg.split('.')
    name = validate_backend(be_parts[0])
    rcParams['backend'] = name
    if name == 'Cairo' and len(be_parts) > 1:
        rcParams['cairo.format'] = validate_cairo_format(be_parts[1])
Beispiel #4
0
def use(arg):
    """
    Set the matplotlib backend to one of the known backends.

    The argument is case-insensitive.  For the Cairo backend,
    the argument can have an extension to indicate the type of
    output.  Example:

        use('cairo.pdf')

    will specify a default of pdf output generated by Cairo.

    Note: this function must be called *before* importing pylab
    for the first time; or, if you are not using pylab, it must
    be called before importing matplotlib.backends.
    """
    if 'matplotlib.backends' in sys.modules:
        warnings.warn(_use_error_msg)
    be_parts = arg.split('.')
    name = validate_backend(be_parts[0])
    rcParams['backend'] = name
    if name == 'Cairo' and len(be_parts) > 1:
        rcParams['cairo.format'] = validate_cairo_format(be_parts[1])