� �)�Uc@s\dZddlZddlZddlZddlZddlZddlZddlZyddlm Z Wn!e k r�ddl m Z nXddl m Z yddl mZWn*e k r�ddl mZejZnXddlZejjd�Zeged D]"Zeejd e�d �^q�ZddlZddljZejd �ddljZddljZdd lm Z dd l!m"Z"de#fd��YZ$e%ej&d�r�ej&j'Z'nej(d�Z'dZ)dZ*dZ+e,�Z-d�Z.e/d�Z0d�Z1d�Z2e/d�Z3d�Z4d�Z5d�Z6d�Z7dS(s} A special directive for including a matplotlib plot. The source code for the plot may be included in one of two ways: 1. A path to a source file as the argument to the directive:: .. plot:: path/to/plot.py When a path to a source file is given, the content of the directive may optionally contain a caption for the plot:: .. plot:: path/to/plot.py This is the caption for the plot Additionally, one my specify the name of a function to call (with no arguments) immediately after importing the module:: .. plot:: path/to/plot.py plot_function1 2. Included as inline content to the directive:: .. plot:: import matplotlib.pyplot as plt import matplotlib.image as mpimg import numpy as np img = mpimg.imread('_static/stinkbug.png') imgplot = plt.imshow(img) In HTML output, `plot` will include a .png file with a link to a high-res .png and .pdf. In LaTeX output, it will include a .pdf. To customize the size of the plot, this directive supports all of the options of the `image` directive, except for `target` (since plot will add its own target). These include `alt`, `height`, `width`, `scale`, `align` and `class`. Additionally, if the `:include-source:` option is provided, the literal source will be displayed inline in the text, (as well as a link to the source in HTML). If this source file is in a non-UTF8 or non-ASCII encoding, the encoding must be specified using the `:encoding:` option. If the `:context:` option is plotted, the code will be run in the context of all previous plot directives for which the context option was specified. This only applies to inline code plot directives, not those run from files. If the ``:nofigs:`` option is specified, the code block will be run, but no figures will be inserted. This is usually useful with the ``:context:`` option. The set of file formats to generate can be specified with the `plot_formats` configuration variable. Error handling: Any errors generated during the running of the code are emitted as warnings using the Python `warnings` module, using a custom category called `PlotWarning`. To turn the warnings into fatal errors that stop the documentation build, after adjusting your `sys.path` in your `conf.py` Sphinx configuration file, use:: import plot_directive warnings.simplefilter('error', plot_directive.PlotWarning) i����N(tmd5(t directives(talign(tImaget.is[a-z]itAgg(t_pylab_helpers(tonly_directivest PlotWarningcBseZdZRS(soWarning category for all warnings generated by this directive. By printing our warnings with this category, it becomes possible to turn them into errors by using in your conf.py:: warnings.simplefilter('error', plot_directive.PlotWarning) This way, you can ensure that your docs only build if all your examples actually run successfully. (t__name__t __module__t__doc__(((sV/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/sphinxext/plot_directive.pyRes trelpathcCs]tjj|�s"td|�ntjj|�sDtd|�ntjj|�jtj�}tjj|�jtj�}tjd kr�|d|dkr�td|dj �d|dj ��nxKt t t |�t |���D]}||||kr�Pq�q�W|d 7}tj gt |�|||}|rUtjj|�Sd Sd S( s� Return a relative path to the target from either the current dir or an optional base dir. Base can be a directory specified either as absolute or relative to current dir. sTarget does not exist: s+Base is not a directory or does not exist: tnttdostos2is0Target is on a different drive to base. Target: s, base: itN(sntRsos2(tostpathtexiststOSErrortisdirtabspathtsplittseptnametuppertrangetmintlentpardirtjoin(ttargettbaset base_listt target_listtitrel_list((sV/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/sphinxext/plot_directive.pyR ys #,( "s� .. htmlonly:: %(links)s .. figure:: %(prefix)s%(tmpdir)s/%(outname)s.png %(options)s %(caption)s .. latexonly:: .. figure:: %(prefix)s%(tmpdir)s/%(outname)s.pdf %(options)s %(caption)s sh .. htmlonly:: [`source code <%(linkdir)s/%(basename)s.py>`__] Exception occurred rendering plot. s cCsGtjj|� pFtjj|�oFtj|�jtj|�jkS(sh Returns True if derivative is out-of-date wrt original, both of which are full file paths. (RRRtstattst_mtime(toriginaltderived((sV/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/sphinxext/plot_directive.pyt out_of_date�sc Bs=|dk r;d|}|r0|defdUq9|dUn�ej�}ejj|�\}}ejjdejj|��ej }e j �e_ ej |�d} z4e |�} ejd| |ddejf�} Wdejd=ej |�|e_ | dk r| j�nX|dk r9e| |��ndS(ss Import a Python module from a path, and run the function given by name, if function_name is not None. s6import numpy as np; import matplotlib.pyplot as plt %sNit__plot__tpytr(tNonet plot_contextRtgetcwdRRtsystinsertRtstdoutt cStringIOtStringIOtchdirtopentimpt load_modulet PY_SOURCEtclosetgetattr( t plot_patht function_namet plot_codetcontextt exec_codetpwdRtfnameR3tfdtmodule((sV/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/sphinxext/plot_directive.pytrun_code�s.       "     cCs tjj�}xt|�D]�\}}x�t|�D]�\}\} } t|�dkrb|} nd||f} | d| } tjj|| �} y|jj j | d| �Wn+t j d|�} t j| t�dSX|dkr5tj| tjj|| ��q5q5WqWt|�S(s� Once a plot script has been imported, this function runs savefig on all of the figures in all of the desired formats. is%s_%02dRtdpisException saving plot %si(RtGcftget_all_fig_managerst enumerateRRRRtcanvastfiguretsavefigtcbooktexception_to_strtwarningstwarnRtshutiltcopyfile(R=tbasenamettmpdirtdestdirtformatst fig_managersR$tfigmantjtformatRGtoutnametoutpathts((sV/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/sphinxext/plot_directive.pyt run_savefig�s"  *cCstjd�tj�dS(Ntall(tpltR;t matplotlibtrc_file_defaults(((sV/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/sphinxext/plot_directive.pyt clear_state s cCs�t|�}tjj|�\}}tjj|�\} } t} xL|D]D\} } tjj|d| | f�}t||�rIt} PqIqIW| r�| r�dSd}xvtr t} xO|D]G\} } tjj|d| || f�}t||�r�t} Pq�q�W| r|d7}q�Pq�W| r8|dkr8|S|sHt �nyt |||d|�Wn+t j d|�}t j|t�dSX| s�t|| |||�}dtjkr�tjd=n|SdSdS( sY Run a pyplot script and save the low and high res PNGs and a PDF in outdir. s%s.%siis %s_%02d.%sR@sException running plot %sR+N(tstrRRRtsplitexttTrueRR*tFalseRdRFRNRORPRQRR_R1tmodules(R=R>R?RURVRWR@tbasedirRCRTtextt all_existsR[RGR\R$R^tnum_figs((sV/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/sphinxext/plot_directive.pytrender_figuressN       c Cs�|jd�}|r|d=n|jd�}|r>|d=ntjj} t| �tksnt| �tkr}t| �} ntj j |�} tj j | �\} } tj j |j jd�\} }tj jd|�}ttj| �}tj j||�}tj jd|�}tj j|�}tdkrAd}nd }tj j|�sitj|�ntj jtj jtjjj|��}tj j|�s�tj|�nd jd �|j d �D��}t|||||| d|�}g}|dkr,tj|tj j|| ��n|jd �r|dkr�tdkr\d }ntjjj}|jdtj j||�dg�|jd�r|j d|d�|d=qnF|jddg�|jg|j d �D]}d|j!�^q��|j d�|d =ng}|s}|dkr]g|j"�D]\}}dt#||f^qD}d j|�}x�t$|�D]�}|d kr�| }nd| |f}g}|dkr�|j d�nx5| d D])\}}|j d||||f�q�Wt%|�r3ddj|�t&�}nd}|jt't&�j d ��q�Wq}|jt(t&�j d ��nt%|�r�|j)||j*j+d��ngS(NR@tnofigstsourcetplot_directivetbuildiiRt/s css|]}t|j�VqdS(N(ttemplate_content_indenttstrip(t.0tline((sV/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/sphinxext/plot_directive.pys <genexpr>�ssinclude-sourceis.. include:: %ss :literal:tencodings :encoding: %ss::s %ss %s:%s: %ss%s_%02ds-`source code <%(linkdir)s/%(basename)s.py>`__s`%s <%s/%s.%s>`__s[%s]s, (ii(i(,thas_keytsetuptconfigt plot_formatsttypeRetunicodetevalRRRTRfRtdocumentt attributesRR tconfdirRtsphinx_versionRRNtmkdirstapptbuildertoutdirRnR.RRRStsrcdirtextendtappendtrstriptitemsRtRRtlocalsttemplatetexception_templatet insert_inputt input_linesRp( R=RjR>R?tcaptiontoptionst state_machineR@RoRWRCRTRktrstdirtrstfileR�treldirtlinkdirRUtprefixRVRmtlinestinclude_prefixtrowtkeytvalR$R\tlinksR[RG((sV/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/sphinxext/plot_directive.pyt_plot_directivePs�   $"   *  "      *   /   ! $  c Cs�t|�r�tj|d�} ttjj| �tjj j �} dj |�} t|�dkrq|d} nd} t | | | d| ||�Sdj |�} t| �j�d} t | dd| d||�SdS( sd Handle the arguments to the plot directive. The real work happens in _plot_directive. is iii����tinlineRN(RRturiR RRtdirnameRzR�R�R�RR.R�Rt hexdigest(Rt argumentsR�tcontenttlinenotcontent_offsett block_texttstateR�R=RjR�R>R?((sV/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/sphinxext/plot_directive.pyRq�s $  c Cs1x*|jj�D]\}}|s(qn|j|}|dkrGqn|j|}|jdkrx�|D]�}|jdkrj|}x-|D]%}|jdkr�|j�}Pq�q�W|dj|�|dj|�|dj|�|dj|�|j j j ||f|j j j |<PqjqjWqqWdS( s� To make plots referenceable, we need to move the reference from the "htmlonly" (or "latexonly") node to the actual figure node itself. t html_onlyt latex_onlyRLR�tidstnamesN(R�R�( t nametypest iteritemstnameidsR.R�ttagnametastexttremoveR�tsettingstenvtdocnametlabels( R�R�Rtexplicittlabelidtnodetntsectnametc((sV/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/sphinxext/plot_directive.pytmark_plot_labels�s*      %cCs�|t_|jt_|jt_i tjd6tjd6tjd6tjd6t d6tj d6tj d6tj d6tj d 6tj d 6}|j d ttd|�|jddddgt�|jdt�dS(NtalttheighttwidthtscaleRtclasssinclude-sourceR@RoRxtplotiiR|tpngiPs hires.pngi�tpdfi2s doctree-read(iii(R�iP(s hires.pngi�(R�i2(RzR�R{R�Rt unchangedtlength_or_unitlesst length_or_percentage_or_unitlesstnonnegative_intRt class_optiontflagRxt add_directiveRqRgtadd_config_valuetconnectR�(R�R�((sV/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/sphinxext/plot_directive.pyRz s&             (8R R1RRRR8RPR4trethashlibRt ImportErrortdocutils.parsers.rstRt&docutils.parsers.rst.directives.imagesRRtsphinxt __version__RR�ttupletxtintRbtmatplotlib.cbookRNtusetmatplotlib.pyplottpyplotRatmatplotlib.imagetimageRtmatplotlib.sphinxextRtWarningRthasattrRR tcurdirR�R�RttdictR/R*RhRFR_RdRnR�RqR�Rz(((sV/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/sphinxext/plot_directive.pyt<module>DsNT    3  6   (   @ z #