OL i/dZddlZddlmZddlmZddlmZddlm Z ddlm Z ddl m Z dd l mZdd lmZdd lmZd d lmZeddZdZddZde_ge_dZeZdZdZedZdZdZ dZ!ddZ"y)ztj|}tds fd_t j s|S tj jtj jdt_ |S#t$rY7wxYw)z Return a new figure manager for a given figure instance. This function is part of the API expected by Matplotlib backends. showc0ttS)Nmetadata)r_fetch_figure_metadata)afigures rz1new_figure_manager_given_figure../s 3F;" rT) r rhasattrr matplotlibis_interactive_to_drawremove ValueErrorappend _draw_called)rrmanagers ` rrrs 99#vFG 66 "    $ $ &   V$  MM D N    sB BBc|tjj} tjD]@}t |j jt|j jB gt_ |r5tjr tjjdyyy#gt_ |r5tjr tjjdwwwxYw)aShow 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. Nrall)r instance close_figuresrget_all_fig_managersrcanvasrrrr#r!pyplotclose)r0blockfigure_managers rrrHs }&&(66 +!668 N %%,,/0E0E0L0LM     S--/    # #E *05  S--/    # #E *05s AB==ADFcFtjsy tjjr" tdgt_dt_SttjDcgc]}|jjc}}tj Dcgc] }||vs| c}D]} t|t| gt_dt_y#t $r>}t}|||jYd}~gt_dt_yd}~wwxYwcc}wcc}w#t $r?}t}|||jYd}~gt_dt_yd}~wwxYw#gt_dt_wxYw)aSend 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. NTFr)rr'r r+r,r# Exceptionr showtracebacksetrr-r.rrr)eipfmactivefigs r flush_figuresr<lsX   "  ! ! # 1 1 Dz2 !1I1I1KL2bii&&LM#'==BCC6MCB C &A'1':':1'=E ! !! $ > ""366*#  LL # #NM B 5+ ,    & &u'<'< =%" 24EwOK;&eS%7%7S3;R;RS3C 0'   s E-- E98E9c\tddl}|jdk\r|jdn|jj dr!dvrddlm tyyy#ttf$r'fd jjd YywxYw) zYEnable extra IPython matplotlib integration when we are loaded as the matplotlib backend.rN) F) auto_selectrRr?)activate_matplotlibcftjjdy)N post_run_cell)rOrHrM)rr[rRconfigure_oncer8s rr^z6_enable_matplotlib_integration..configure_onces)#G,(W5 $$_nErr]) rr!__version_info__ get_backendrK_getIPython.core.pylabtoolsr[rO ImportErrorAttributeErrorrHrI)r!r[rRr^r8s @@@@r_enable_matplotlib_integrationres B""g-(*((U;%%**95 gPP? @  ( $R 1 Qr ^, @ F II   ? @sA553B+*B+c nt|jrt|jDcgc]D}|j|j fD]'}|j D]}|j)Fc}}}}|jr"||dk(jr d|drdiSdiSycc}}}w)z3Get some metadata to help with displaying a figure.rneeds_backgrounddarklightN) _is_transparent get_facecolor _is_lightaxesxaxisyaxisget_ticklabels get_colorsizer*)r;rmaxislabel ticksLights rrrss((*+ HH  !ZZ4 !002  ! ! !   ?? jm ;@@B&*Q-M MWM M  sA B0 cftj|}|ddddfjddkDS)zDetermines 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).NrX)gA`"?gbX9?gv/??)r to_rgba_arraydot)colorrgbaArrs rrlrls7""5)G 1bqb5>  3 4s ::rc<tj|}|ddkS)z"Determine transparency from alpha.rXrw)rto_rgba)rzrgbas rrjrj s >>% D 7S=rctj}i}|j|j|jdi|t j}t ||fi|y)aSelect figure formats for the inline backend. Optionally pass quality for JPEG. For example, this enables PNG and JPEG output with a JPEG quality of 90%:: In [1]: set_matplotlib_formats('png', 'jpeg', pil_kwargs={'quality': 90}) To set this in your notebook by `%config` magic:: In [1]: %config InlineBackend.figure_formats = {'png', 'jpeg'} %config InlineBackend.print_figure_kwargs = \ {'pil_kwargs': {'quality' : 90}} To set this in your config files use the following:: c.InlineBackend.figure_formats = {'png', 'jpeg'} c.InlineBackend.print_figure_kwargs.update({ 'pil_kwargs': {'quality' : 90} }) Parameters ---------- *formats : strs One or more figure formats to enable: 'png', 'retina', 'jpeg', 'svg', 'pdf'. **kwargs Keyword args will be relayed to ``figure.canvas.print_figure``. In addition, see the docstrings of `plt.savefig()`, `matplotlib.figure.Figure.savefig()`, `PIL.Image.Image.save()` and :ref:`Pillow Image file formats `. N)r r+rLrQrr)formatsrrSkwrFs rset_matplotlib_formatsrsXB  "C BIIc%%& BII  % % 'E%/B/rc:tj}||_y)aSet whether the inline backend closes all figures automatically or not. By default, the inline backend used in the IPython Notebook will close all matplotlib figures automatically after each cell is run. This means that plots in different cells won't interfere. Sometimes, you may want to make a plot in one cell and then refine it in later cells. This can be accomplished by:: In [1]: set_matplotlib_close(False) To set this in your config files use the following:: c.InlineBackend.close_figures = False Parameters ---------- close : bool Should all matplotlib figures be automatically closed after each cell is run? N)r r+r,)r0rSs rset_matplotlib_closer:s*  "CCr)NN)T)#__doc__r!IPython.core.getipythonrIPython.core.interactiveshellrrbrIPython.displayrrmatplotlib._pylab_helpersrmatplotlib.backendsr matplotlib.backends.backend_aggr matplotlib.figurer configr rrrr'r#r< FigureCanvasrOrerrlrjrrrrrrsB /:9#)+;$!06N(V+> ,"d -D`@6 (; &0Rr