
NXc           @  sq  d  Z  d d l m Z d d l m Z d d l m Z d d l m Z d d l	 m
 Z
 i d d 6d	 d
 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6Z e e e j   e j     Z d e d <d
 e d <e d <d e d <d e d <d e d <d    Z d!   Z d" d# d$  Z d%   Z d&   Z d'   Z d, d, d(  Z d)   Z e d*  Z d+   Z d, S(-   s%   Pylab (matplotlib) support utilities.i(   t   print_function(   t   BytesIO(   t   _pngxy(   t
   flag_calls(   t	   py3compatt   TkAggt   tkt   GTKAggt   gtkt   GTK3Aggt   gtk3t   WXAggt   wxt   Qt4Aggt   qtt   qt4t   Qt5Aggt   qt5t   MacOSXt   osxt   nbAggt   nbaggt   notebooks'   module://ipykernel.pylab.backend_inlinet   inlinet   GTKt   GTKCairot	   GTK3Cairot   WXt   CocoaAggc          G  s   d d l  m } |  s? | j   } g  | D] } | j j ^ q) Sg  } xP |  D]H } | j j |  } | d k r t d |  qL | j	 | j j  qL W| Sd S(   s  Get a list of matplotlib figures by figure numbers.

    If no arguments are given, all available figures are returned.  If the
    argument list contains references to invalid figures, a warning is printed
    but the function continues pasting further figures.

    Parameters
    ----------
    figs : tuple
        A tuple of ints giving the figure numbers of the figures to return.
    i(   t   Gcfs!   Warning: figure %s not available.N(
   t   matplotlib._pylab_helpersR   t   get_all_fig_managerst   canvast   figuret   figst   gett   Nonet   printt   append(   t   fig_numsR   t   fig_managerst   fmR"   t   numt   f(    (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/pylabtools.pyt   getfigs/   s    c         C  s#   d d l  } |  | g | j d <d S(   s   Set the default figure size to be [sizex, sizey].

    This is just an easy to remember, convenience wrapper that sets::

      matplotlib.rcParams['figure.figsize'] = [sizex, sizey]
    iNs   figure.figsize(   t
   matplotlibt   rcParams(   t   sizext   sizeyR-   (    (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/pylabtools.pyt   figsizeJ   s    t   pngt   tightc   	      K  s   d d l  m } |  j r( |  j r( d S| d } | d k rQ | d } d } n  t d | d	 |  j   d
 |  j   d | d |  } | j |  t   } |  j	 j
 | |  | j   } | d k r | j d  } n  | S(   s  Print a figure to an image, and return the resulting file data
    
    Returned data will be bytes unless ``fmt='svg'``,
    in which case it will be unicode.
    
    Any keyword args are passed to fig.canvas.print_figure,
    such as ``quality`` or ``bbox_inches``.
    i(   R.   Ns   savefig.dpit   retinai   R2   t   formatt	   facecolort	   edgecolort   dpit   bbox_inchest   svgs   utf-8(   R-   R.   t   axest   linest   dictt   get_facecolort   get_edgecolort   updateR   R    t   print_figuret   getvaluet   decode(	   t   figt   fmtR9   t   kwargsR.   R8   t   kwt   bytes_iot   data(    (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/pylabtools.pyRA   U   s(    	

			c         K  sN   t  |  d d | } t |  \ } } t d | d d | d  } | | f S(   s/   format a figure as a pixel-doubled (retina) PNGRE   R4   t   widthi   t   height(   RA   R   R=   (   RD   RF   t   pngdatat   wt   ht   metadata(    (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/pylabtools.pyt   retina_figure{   s    c           s     f d   } | S(   sX  Factory to return a matplotlib-enabled runner for %run.

    Parameters
    ----------
    safe_execfile : function
      This must be a function with the same interface as the
      :meth:`safe_execfile` method of IPython.

    Returns
    -------
    A function suitable for use as the ``runner`` argument of the %run magic
    function.
    c           s{   d d l  } d d l j } | j d } | j t    |  | |  | j |  | j j rw | j   t | j _ n  d S(   s   matplotlib-aware wrapper around safe_execfile.

        Its interface is identical to that of the :func:`execfile` builtin.

        This is ultimately a call to execfile(), but wrapped in safeties to
        properly handle interactive rendering.iNt   interactive(	   R-   t   matplotlib.pylabt   pylabR.   RQ   t   Falset   draw_if_interactivet   calledt   draw(   t   fnamet   whereRG   R-   RS   t   is_interactive(   t   safe_execfile(    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/pylabtools.pyt   mpl_execfile   s    
(    (   R[   R\   (    (   R[   sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/pylabtools.pyt
   mpl_runner   s    c           s>  d d l  m } d d l m } |  j j d } |  j j d } |  j j d } |  j j d } t | t j  r~ | h } n  t	 |  } g  |  j j j
   D] }	 |	 j | d  ^ q d d	 d
 d d d d h }
 | j |
  } | rZd d j g  | D] }	 t |	  ^ q  } d d j g  |
 D] }	 t |	  ^ q% } t d | | f   n  d | k r| j |   f d    n  d
 | k sd	 | k r| j |   f d    n  d | k sd | k r| j |   f d    n  d | k r| j |   f d    n  d | k r:| j |   f d    n  d S(   s_  Select figure formats for the inline backend.

    Parameters
    ==========
    shell : InteractiveShell
        The main IPython instance.
    formats : str or set
        One or a set of figure formats to enable: 'png', 'retina', 'jpeg', 'svg', 'pdf'.
    **kwargs : any
        Extra keyword arguments to be passed to fig.canvas.print_figure.
    i(   t   Figure(   t   backend_inlines   image/svg+xmls	   image/pngs
   image/jpegs   application/pdfR2   t   png2xR4   t   jpgt   jpegR:   t   pdfs   %st   ,s    supported formats are: %s not %sc           s   t  |  d    S(   NR2   (   RA   (   RD   (   RF   (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/pylabtools.pyt   <lambda>   s    c           s   t  |     S(   N(   RP   (   RD   (   RF   (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/pylabtools.pyRe      s    c           s   t  |  d    S(   NRa   (   RA   (   RD   (   RF   (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/pylabtools.pyRe      s    c           s   t  |  d    S(   NR:   (   RA   (   RD   (   RF   (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/pylabtools.pyRe      s    c           s   t  |  d    S(   NRc   (   RA   (   RD   (   RF   (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/pylabtools.pyRe      s    N(   t   matplotlib.figureR^   t   ipykernel.pylabR_   t   display_formattert
   formatterst
   isinstanceR   t   string_typest   sett   valuest   popR$   t
   differencet   joint   reprt
   ValueErrort   for_type(   t   shellt   formatsRF   R^   R_   t   svg_formattert   png_formattert   jpg_formattert   pdf_formatterR+   t	   supportedt   badt   bst   gs(    (   RF   sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/pylabtools.pyt   select_figure_formats   s4    /,,c         C  sy   d d l  } |  r+ |  d k r+ t |  } nD | j d } t j | d  }  | ro |  | k ro | }  t |  } n  |  | f S(   s  Given a gui string return the gui and mpl backend.

    Parameters
    ----------
    gui : str
        Can be one of ('tk','gtk','wx','qt','qt4','inline').
    gui_select : str
        Can be one of ('tk','gtk','wx','qt','qt4','inline').
        This is any gui already selected by the shell.

    Returns
    -------
    A tuple of (gui, backend) where backend is one of ('TkAgg','GTKAgg',
    'WXAgg','Qt4Agg','module://ipykernel.pylab.backend_inline').
    iNt   autot   backend(   R-   t   backendst   rcParamsOrigt   backend2guiR#   R$   (   t   guit
   gui_selectR-   R   (    (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/pylabtools.pyt   find_gui_and_backend   s    c         C  ss   d d l  } | j t  |  | j d <d d l } | j j |   d d l j } t	 | j
 _ t | j  | _ d S(   s7   Activate the given backend and set interactive to True.iNR   (   R-   RQ   t   TrueR.   t   matplotlib.pyplott   pyplott   switch_backendRR   RS   RT   t   showt	   _needmainR   RU   (   R   R-   RS   (    (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/pylabtools.pyt   activate_matplotlib  s    c         B  sc   d } | |  f d U| r1 d } | |  f d Un  e  |  d <d d l m } | |  d <e |  d <d S(	   s   Populate the namespace with pylab-related values.
    
    Imports matplotlib, pylab, numpy, and everything from pylab and numpy.
    
    Also imports a few names from IPython (figsize, display, getfigs)
    
    sb   import numpy
import matplotlib
from matplotlib import pylab, mlab, pyplot
np = numpy
plt = pyplot
Ns3   from matplotlib.pylab import *
from numpy import *
R1   i(   t   displayR   R,   (   R1   t   IPython.core.displayR   R,   (   t   user_nst
   import_allt   sR   (    (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/pylabtools.pyt   import_pylab  s    

c         C  ss  y d d l  m } Wn t k
 r( d SXd d l m } | j d |   } |  | _ | |  j k rv |  j j |  n  | t	 d k r d d l  m
 } |  j j d |  t   |  _ x% | j D] } | j | |  j | <q W| j j | j  nf d d l  m
 } y |  j j d |  Wn t k
 r-n Xt |  d	  rY| j j |  j  |  ` n  t |  | j | j  d S(
   s   Configure an IPython shell object for matplotlib use.

    Parameters
    ----------
    shell : InteractiveShell instance

    backend : matplotlib backend
    i(   t   InlineBackendN(   R   t   parentR   (   t   flush_figurest   post_executet   _saved_rcParams(   t   ipykernel.pylab.backend_inlineR   t   ImportErrorR-   R   t   instanceRt   t   configurablesR&   R   R   t   eventst   registerR=   R   t   rcR.   R@   t
   unregisterRr   t   hasattrR~   t   figure_formatst   print_figure_kwargs(   Rt   R   R   R   t   cfgR   t   k(    (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/pylabtools.pyt   configure_inline_support@  s2    		N(   t   __doc__t
   __future__R    t   ioR   R   R   t   IPython.utils.decoratorsR   t   IPython.utilsR   R   R=   t   zipRm   t   keysR   R,   R1   RA   RP   R]   R~   R$   R   R   R   R   R   (    (    (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/pylabtools.pyt   <module>   s@   

!



		&			(	2)	!