ó
Û¤[c           @  sð   d  Z  d d l m Z d d l Z d d l m Z m 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 d d d „ Z e e _ g  e _ d „  Z d „  Z e Z d „  Z e ƒ  d „  Z d „  Z d „  Z d S(   s<   A matplotlib backend for publishing figures via display_dataiÿÿÿÿ(   t   print_functionN(   t   new_figure_managert   FigureCanvasAgg(   t   colors(   t   Gcf(   t   get_ipython(   t   displayi   (   t   InlineBackendc         C  s‘   |  d k r t j ƒ  j }  n  z= x6 t j ƒ  D]( } t | j j d t	 | j j ƒ ƒq. WWd g  t
 _ |  rŒ t j ƒ  rŒ t j j d ƒ n  Xd S(   s÷  Show all figures as SVG/PNG payloads sent to the IPython clients.

    Parameters
    ----------
    close : bool, optional
      If true, a ``plt.close('all')`` call is automatically issued after
      sending all the figures. If this is set, the figures will entirely
      removed from the internal list of figures.
    block : Not used.
      The `block` parameter is a Matplotlib experimental parameter.
      We accept it in the function signature for compatibility with other
      backends.
    t   metadataNt   all(   t   NoneR   t   instancet   close_figuresR   t   get_all_fig_managersR   t   canvast   figuret   _fetch_figure_metadatat   showt   _to_drawt
   matplotlibt   pyplott   close(   R   t   blockt   figure_manager(    (    s=   lib/python2.7/site-packages/ipykernel/pylab/backend_inline.pyR      s    	c            s¡   t  j ƒ  }  |  d k r d S|  j j ‰  t ˆ  d ƒ sL ‡  f d †  ˆ  _ n  t j ƒ  s\ d Sy t j	 j
 ˆ  ƒ Wn t k
 rƒ n Xt j	 j ˆ  ƒ t t _ d S(   s5   
    Is called after every pylab drawing command
    NR   c            s   t  ˆ  d t ˆ  ƒ ƒS(   NR   (   R   R   (   t   a(   t   fig(    s=   lib/python2.7/site-packages/ipykernel/pylab/backend_inline.pyt   <lambda>O   s    (   R   t
   get_activeR
   R   R   t   hasattrR   R   t   is_interactiveR   t   removet
   ValueErrort   appendt   Truet   _draw_called(   t   manager(    (   R   s=   lib/python2.7/site-packages/ipykernel/pylab/backend_inline.pyt   draw_if_interactive7   s    c          C  sG  t  j s d St j ƒ  j ro y t  t ƒ SWqo t k
 rk }  t ƒ  } | d k rZ |  ‚ ql | j	 ƒ  d Sqo Xn  z¾ t
 g  t j ƒ  D] } | j j ^ q‚ ƒ } xŒ g  t  j D] } | | k rª | ^ qª D]b } y t | d t | ƒ ƒWqÆ t k
 r'}  t ƒ  } | d k r|  ‚ q(| j	 ƒ  d SqÆ XqÆ WWd g  t  _ t t  _ Xd S(   sÆ  Send all figures that changed

    This is meant to be called automatically and will call show() if, during
    prior code execution, there had been any calls to draw_if_interactive.

    This function is meant to be used as a post_execute callback in IPython,
    so user-caused errors are handled with showtraceback() instead of being
    allowed to raise.  If this function is not called from within IPython,
    then these exceptions will raise.
    NR   (   R   R"   R   R   R   R!   t	   ExceptionR   R
   t   showtracebackt   setR   R   R   R   R   R   R   t   False(   t   et   ipt   fmt   activeR   (    (    s=   lib/python2.7/site-packages/ipykernel/pylab/backend_inline.pyt   flush_figuresd   s0    			
+/		
	c            s¸   d d l  m }  t ƒ  ‰ |  ƒ  ‰ ˆ r´ ˆ d t k r´ d d l m ‰ m ‰  y ˆ  ˆ ƒ ˆ ˆ ˆ ƒ Wq´ t t f k
 r° ‡  ‡ ‡ ‡ ‡ f d †  ‰ ˆ j	 j
 d ˆ ƒ q´ Xn  d S(   sY   Enable extra IPython matplotlib integration when we are loaded as the matplotlib backend.iÿÿÿÿ(   t   get_backends   module://%s(   t   configure_inline_supportt   activate_matplotlibc            s.   ˆ  ˆ ƒ ˆ ˆ ˆ ƒ ˆ j  j d ˆ ƒ d  S(   Nt   post_run_cell(   t   eventst
   unregister(   t   args(   R0   t   backendR/   t   configure_onceR*   (    s=   lib/python2.7/site-packages/ipykernel/pylab/backend_inline.pyR6   £   s    
R1   N(   R   R.   R   t   __name__t   IPython.core.pylabtoolsR/   R0   t   ImportErrort   AttributeErrorR2   t   register(   R.   (    (   R0   R5   R/   R6   R*   s=   lib/python2.7/site-packages/ipykernel/pylab/backend_inline.pyt   _enable_matplotlib_integration—   s    		
c         C  s§   t  |  j ƒ  ƒ r£ t g  |  j D]> } | j | j f D]% } | j ƒ  D] } | j ƒ  ^ qE q5 q ƒ } | j r£ | | d k j	 ƒ  r£ i | d r˜ d n d d 6Sn  d S(   s3   Get some metadata to help with displaying a figure.i    t   darkt   lightt   needs_backgroundN(   t   _is_transparentt   get_facecolort	   _is_lightt   axest   xaxist   yaxist   get_ticklabelst	   get_colort   sizeR	   R
   (   R   RC   t   axist   labelt
   ticksLight(    (    s=   lib/python2.7/site-packages/ipykernel/pylab/backend_inline.pyR   «   s    +c         C  s8   t  j |  ƒ } | d d … d d … f j d ƒ d k S(   s®   Determines if a color (or each of a sequence of colors) is light (as
    opposed to dark). Based on ITU BT.601 luminance formula (see
    https://stackoverflow.com/a/596241).Ni   g‰A`åÐ"Ó?gbX9´Èâ?gÉv¾Ÿ/½?g      à?(   g‰A`åÐ"Ó?gbX9´Èâ?gÉv¾Ÿ/½?(   R   t   to_rgba_arrayt   dot(   t   colort   rgbaArr(    (    s=   lib/python2.7/site-packages/ipykernel/pylab/backend_inline.pyRB   º   s    c         C  s   t  j |  ƒ } | d d k  S(   s"   Determine transparency from alpha.i   g      à?(   R   t   to_rgba(   RN   t   rgba(    (    s=   lib/python2.7/site-packages/ipykernel/pylab/backend_inline.pyR@   Á   s    (   t   __doc__t
   __future__R    R   t   matplotlib.backends.backend_aggR   R   R   t   matplotlib._pylab_helpersR   t   IPython.core.getipythonR   t   IPython.core.displayR   t   configR   R
   R   R(   R"   R   R$   R-   t   FigureCanvasR<   R   RB   R@   (    (    (    s=   lib/python2.7/site-packages/ipykernel/pylab/backend_inline.pyt   <module>   s&   			-	1			