##// END OF EJS Templates
allow_none=False by default for Type and Instance
allow_none=False by default for Type and Instance

File last commit:

r20940:4c8e4259
r20940:4c8e4259
Show More
config.py
120 lines | 4.8 KiB | text/x-python | PythonLexer
MinRK
define InlineBackend configurable in its own file...
r13167 """Configurable for configuring the IPython inline backend
This module does not import anything from matplotlib.
"""
#-----------------------------------------------------------------------------
# Copyright (C) 2011 The IPython Development Team
#
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
Thomas Kluyver
Don't calculate default value when setting traitlet for the first time
r19121 from IPython.config import Config
MinRK
define InlineBackend configurable in its own file...
r13167 from IPython.config.configurable import SingletonConfigurable
Brian E. Granger
Adding support for multiple figure formats in InlineBackend.
r15122 from IPython.utils.traitlets import (
Dict, Instance, CaselessStrEnum, Set, Bool, Int, TraitError, Unicode
)
MinRK
define InlineBackend configurable in its own file...
r13167 from IPython.utils.warn import warn
#-----------------------------------------------------------------------------
# Configurable for inline backend options
#-----------------------------------------------------------------------------
Daniel B. Vasquez
Move testing for PIL[low] in the _figure_format_changed(...) function instead...
r14772 def pil_available():
"""Test if PIL/Pillow is available"""
out = False
try:
from PIL import Image
out = True
except:
pass
return out
Daniel B. Vasquez
Add JPEG as an image format for inline backend if PIL/pillow is available.
r14770
MinRK
define InlineBackend configurable in its own file...
r13167 # inherit from InlineBackendConfig for deprecation purposes
class InlineBackendConfig(SingletonConfigurable):
pass
class InlineBackend(InlineBackendConfig):
"""An object to store configuration of the inline backend."""
def _config_changed(self, name, old, new):
# warn on change of renamed config section
Thomas Kluyver
Don't calculate default value when setting traitlet for the first time
r19121 if new.InlineBackendConfig != getattr(old, 'InlineBackendConfig', Config()):
MinRK
define InlineBackend configurable in its own file...
r13167 warn("InlineBackendConfig has been renamed to InlineBackend")
super(InlineBackend, self)._config_changed(name, old, new)
# The typical default figure size is too large for inline use,
# so we shrink the figure size to 6x4, and tweak fonts to
# make that fit.
rc = Dict({'figure.figsize': (6.0,4.0),
# play nicely with white background in the Qt and notebook frontend
Matthias BUSSONNIER
transparent background match ... all colors
r13718 'figure.facecolor': (1,1,1,0),
'figure.edgecolor': (1,1,1,0),
Matthias BUSSONNIER
Set axis background to transparent in inlinebackend...
r17111 'axes.facecolor': (1,1,1,0),
MinRK
define InlineBackend configurable in its own file...
r13167 # 12pt labels get cutoff on 6x4 logplots, so use 10pt.
'font.size': 10,
# 72 dpi matches SVG/qtconsole
# this only affects PNG export, as SVG has no dpi setting
'savefig.dpi': 72,
# 10pt still needs a little more room on the xlabel:
'figure.subplot.bottom' : .125
}, config=True,
help="""Subset of matplotlib rcParams that should be different for the
inline backend."""
)
Brian E. Granger
Adding support for multiple figure formats in InlineBackend.
r15122 figure_formats = Set({'png'}, config=True,
help="""A set of figure formats to enable: 'png',
'retina', 'jpeg', 'svg', 'pdf'.""")
Daniel B. Vasquez
Add JPEG as an image format for inline backend if PIL/pillow is available.
r14770
MinRK
add InlineBackend.print_figure_kwargs...
r15342 def _update_figure_formatters(self):
if self.shell is not None:
Thomas Kluyver
Fix local import of select_figure_formats....
r15778 from IPython.core.pylabtools import select_figure_formats
MinRK
add InlineBackend.print_figure_kwargs...
r15342 select_figure_formats(self.shell, self.figure_formats, **self.print_figure_kwargs)
Brian E. Granger
Adding support for multiple figure formats in InlineBackend.
r15122 def _figure_formats_changed(self, name, old, new):
if 'jpg' in new or 'jpeg' in new:
Daniel B. Vasquez
Move testing for PIL[low] in the _figure_format_changed(...) function instead...
r14772 if not pil_available():
raise TraitError("Requires PIL/Pillow for JPG figures")
MinRK
remove redundant check for self.shell is None
r15396 self._update_figure_formatters()
Daniel B. Vasquez
Move testing for PIL[low] in the _figure_format_changed(...) function instead...
r14772
Brian E. Granger
Making figure_format config=True.
r15123 figure_format = Unicode(config=True, help="""The figure format to enable (deprecated
use `figure_formats` instead)""")
Brian E. Granger
Adding support for multiple figure formats in InlineBackend.
r15122
def _figure_format_changed(self, name, old, new):
if new:
self.figure_formats = {new}
MinRK
add InlineBackend.print_figure_kwargs...
r15342 print_figure_kwargs = Dict({'bbox_inches' : 'tight'}, config=True,
help="""Extra kwargs to be passed to fig.canvas.print_figure.
Logical examples include: bbox_inches, quality (for jpeg figures), etc.
"""
)
_print_figure_kwargs_changed = _update_figure_formatters
MinRK
define InlineBackend configurable in its own file...
r13167
close_figures = Bool(True, config=True,
help="""Close all figures at the end of each cell.
When True, ensures that each cell starts with no active figures, but it
also means that one must keep track of references in order to edit or
redraw figures in subsequent cells. This mode is ideal for the notebook,
where residual plots from other cells might be surprising.
When False, one must call figure() to create new figures. This means
that gcf() and getfigs() can reference figures created in other cells,
and the active figure can continue to be edited with pylab/pyplot
methods that reference the current active figure. This mode facilitates
iterative editing of figures, and behaves most consistently with
other matplotlib backends, but figure barriers between cells must
be explicit.
""")
MinRK
add InlineBackend.print_figure_kwargs...
r15342
Sylvain Corlay
allow_none=False by default for Type and Instance
r20940 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC',
allow_none=True)
MinRK
define InlineBackend configurable in its own file...
r13167