Logo Search packages:      
Sourcecode: ipython version File versions  Download package

def IPython::Shell::MatplotlibShellBase::_matplotlib_config (   self,
  name,
  user_ns,
  user_global_ns = None 
) [private]

Return items needed to setup the user's shell with matplotlib

Definition at line 511 of file Shell.py.

00511                                                                  :
        """Return items needed to setup the user's shell with matplotlib"""

        # Initialize matplotlib to interactive mode always
        import matplotlib
        from matplotlib import backends
        matplotlib.interactive(True)

        def use(arg):
            """IPython wrapper for matplotlib's backend switcher.

            In interactive use, we can not allow switching to a different
            interactive backend, since thread conflicts will most likely crash
            the python interpreter.  This routine does a safety check first,
            and refuses to perform a dangerous switch.  It still allows
            switching to non-interactive backends."""

            if arg in backends.interactive_bk and arg != self.mpl_backend:
                m=('invalid matplotlib backend switch.\n'
                   'This script attempted to switch to the interactive '
                   'backend: `%s`\n'
                   'Your current choice of interactive backend is: `%s`\n\n'
                   'Switching interactive matplotlib backends at runtime\n'
                   'would crash the python interpreter, '
                   'and IPython has blocked it.\n\n'
                   'You need to either change your choice of matplotlib backend\n'
                   'by editing your .matplotlibrc file, or run this script as a \n'
                   'standalone file from the command line, not using IPython.\n' %
                   (arg,self.mpl_backend) )
                raise RuntimeError, m
            else:
                self.mpl_use(arg)
                self.mpl_use._called = True
        
        self.matplotlib = matplotlib
        self.mpl_backend = matplotlib.rcParams['backend']

        # we also need to block switching of interactive backends by use()
        self.mpl_use = matplotlib.use
        self.mpl_use._called = False
        # overwrite the original matplotlib.use with our wrapper
        matplotlib.use = use

        # This must be imported last in the matplotlib series, after
        # backend/interactivity choices have been made
        import matplotlib.pylab as pylab
        self.pylab = pylab

        self.pylab.show._needmain = False
        # We need to detect at runtime whether show() is called by the user.
        # For this, we wrap it into a decorator which adds a 'called' flag.
        self.pylab.draw_if_interactive = flag_calls(self.pylab.draw_if_interactive)

        # Build a user namespace initialized with matplotlib/matlab features.
        user_ns, user_global_ns = IPython.ipapi.make_user_namespaces(user_ns,
            user_global_ns)

        # Import numpy as np/pyplot as plt are conventions we're trying to
        # somewhat standardize on.  Making them available to users by default
        # will greatly help this. 
        exec ("import numpy\n"
              "import numpy as np\n"
              "import matplotlib\n"
              "import matplotlib.pylab as pylab\n"
              "try:\n"
              "    import matplotlib.pyplot as plt\n"
              "except ImportError:\n"
              "    pass\n"
              ) in user_ns
        
        # Build matplotlib info banner
        b="""
  Welcome to pylab, a matplotlib-based Python environment.
  For more information, type 'help(pylab)'.
"""
        return user_ns,user_global_ns,b

    def mplot_exec(self,fname,*where,**kw):


Generated by  Doxygen 1.6.0   Back to index