)Uc@ sTdZddlmZddlZddlZddlmZddlm Z m Z ddl m Z m Z mZmZddlmZddlmZdd lmZmZmZmZdd lmZmZmZdd lmZmZm Z m!Z!m"Z"dd l#m$Z$m%Z%m&Z&m'Z'm(Z(d e(fdYZ)de fdYZ*dS(s Place a legend on the axes at location loc. Labels are a sequence of strings and loc can be a string or an integer specifying the legend location The location codes are 'best' : 0, (only implemented for axis legends) 'upper right' : 1, 'upper left' : 2, 'lower left' : 3, 'lower right' : 4, 'right' : 5, 'center left' : 6, 'center right' : 7, 'lower center' : 8, 'upper center' : 9, 'center' : 10, Return value is a sequence of text, line instances that make up the legend i(tdivisionN(trcParams(tArtisttallow_rasterization(tis_string_liketiterablet silent_listtsafezip(tFontProperties(tLine2D(tPatcht RectangletShadowtFancyBboxPatch(tLineCollectiontRegularPolyCollectiontCircleCollection(tBboxtBboxBasetTransformedBboxtBboxTransformTotBboxTransformFrom(tHPackertVPackertTextAreat DrawingAreatDraggableOffsetBoxtDraggableLegendcB s&eZedZdZdZRS(cC s)||_tj|||jd|dS(Ntuse_blit(tlegendRt__init__t _legend_box(tselfRR((sD/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/legend.pyR*s cC s|jjj|S(N(Rt legendPatchtcontains(R Rtevt((sD/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/legend.pyt artist_picker/scC s|j}|jj}|jdks9|jdkr[|jjd|jj}nt|}t|j ||j_ dS(Ni( tget_loc_in_canvasRtget_bbox_to_anchortwidththeighttset_bbox_to_anchortNoneRttuplettransform_pointt_loc(R t loc_in_canvastbboxt_bbox_transform((sD/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/legend.pytfinalize_offset2s  (t__name__t __module__tFalseRR$R1(((sD/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/legend.pyR)s  tLegendcB seZdZi dd6dd6dd6dd6d d 6d d 6d d6dd6dd6dd6dd6Zd ZdZeeedeeeeeeeeeeeeedeeeeeeedZdZ dZ dZ e e e Z dZdZedZedZd Zd!Zd"Zd#Zd$Zd%Zd&Zd'Zd(Zd)Zd*Zd+Zd,Zd-Z ed.Z!d/Z"ed0Z#ee$d1Z%RS(2s Place a legend on the axes at location loc. Labels are a sequence of strings and loc can be a string or an integer specifying the legend location The location codes are:: 'best' : 0, (only implemented for axis legends) 'upper right' : 1, 'upper left' : 2, 'lower left' : 3, 'lower right' : 4, 'right' : 5, 'center left' : 6, 'center right' : 7, 'lower center' : 8, 'upper center' : 9, 'center' : 10, loc can be a tuple of the noramilzed coordinate values with respect its parent. Return value is a sequence of text, line instances that make up the legend itbestis upper rightis upper leftis lower leftis lower rightitrightis center leftis center rightis lower centeri s upper centeri tcentercC sdS(NR5((R ((sD/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/legend.pyt__str__lsc)C sddlm}ddlm}tj|| d7krRtdtd|_ nMt | t rt| |_ d| kr|j j tdqn | |_ |j j |_dddd d g}g|_g|_d7|_t} xI|D]A}!| |!d7krtd |!}"n | |!}"t||!|"qWid d 6dd6dd6dd6dd6}#|j}$t|$j|$j|j}%x|#jD]\}&}'| |&d7k r| |'d7krtjd|'|&ftt||'| |&|%qn| |'d7kr t||'td |'qt||'| |'qW~ t|}t|dkrbd}n||_|jdkrt d|n|d7krt!j"d8d9d:g|_#nt!j$||_#t%|j&t|j#d}(t!j'|j#|(|j& |_#d7|_(t ||rIt)|_*|j+||j,|j-n4t ||rqt.|_*|j,|n t/d||_0|d7krtd }|j* r|d;krd"}qnt1|rV||j2krF|j*rtjd#|d$j3|j2j4fd}qStjd%|d$j3|j2j4fd}qV|j2|}n|j* r|dkrtjd&d}n||_5|j6||t7d'd<d)d*d+d*d,td-d.td/d0|jd1t)|_8|d7krtd2}n|t)kr |j8j9d3d dd4d5n|j8j9d6d d|j:|j8||_;|j<||||_=|j>||j|_?d7|_@d7S(=s~ - *parent* : the artist that contains the legend - *handles* : a list of artists (lines, patches) to add to the legend - *labels* : a list of strings to label the legend Optional keyword arguments: ================ ================================================================== Keyword Description ================ ================================================================== loc a location code prop the font property markerscale the relative size of legend markers vs. original numpoints the number of points in the legend for line scatterpoints the number of points in the legend for scatter plot scatteryoffsets a list of yoffsets for scatter symbols in legend frameon if True, draw a frame (default is True) fancybox if True, draw a frame with a round fancybox. If None, use rc shadow if True, draw a shadow behind legend ncol number of columns borderpad the fractional whitespace inside the legend border labelspacing the vertical space between the legend entries handlelength the length of the legend handles handletextpad the pad between the legend handle and text borderaxespad the pad between the axes and legend border columnspacing the spacing between columns title the legend title bbox_to_anchor the bbox that the legend will be anchored. bbox_transform the transform for the bbox. transAxes if None. ================ ================================================================== The pad and spacing parameters are measure in font-size units. E.g., a fontsize of 10 points and a handlelength=5 implies a handlelength of 50 points. Values from rcParams will be used if None. Users can specify any arbitrary location for the legend using the *bbox_to_anchor* keyword argument. bbox_to_anchor can be an instance of BboxBase(or its derivatives) or a tuple of 2 or 4 floats. See :meth:`set_bbox_to_anchor` for more detail. The legend location can be specified by setting *loc* with a tuple of 2 floats, which is interpreted as the lower-left corner of the legend in the normalized axes coordinate. i(tAxes(tFiguretsizeslegend.fontsizet numpointst markerscaletshadowt columnspacingt scatterpointsslegend.t borderpadtpadt labelspacingtlabelsept handlelengtht handlelent handletextpadt handletextsept borderaxespadtaxespadsUse '%s' instead of '%s'.iiis!numpoints must be >= 0; it was %dg@g @g@g@s,Legend needs either Axes or Figure as parents legend.locR6s upper rightsLUnrecognized location "%s". Falling back on "best"; valid locations are %s s sSUnrecognized location "%s". Falling back on "upper right"; valid locations are %s siAutomatic legend placement (loc="best") not implemented for figure legend. Falling back on "upper right".txygR'g?R(t facecolorsaxes.facecolort edgecolorsaxes.edgecolortmutation_scaletsnapslegend.fancyboxtroundt rounding_sizeg?tsquareNg?g?g?(iR6(gg(Atmatplotlib.axesR:tmatplotlib.figureR;RRR*RRtpropt isinstancetdicttset_sizetget_size_in_pointst _fontsizettextst legendHandlest_legend_title_boxtlocalstsetattrR/tminR'R(titemstwarningstwarntDeprecationWarningtlisttlent_ncolR=t ValueErrortnptarrayt_scatteryoffsetstasarraytintRAttileRtTruetisaxestset_axest set_figuretfigureR4t TypeErrortparentRtcodestjointkeyst_modeR)R R!t set_boxstylet_set_artist_propst _drawFramet_init_legend_boxR-t set_titlet_last_fontsize_pointst _draggable()R RvthandlestlabelstlocR=R>RAtscatteryoffsetsRVRCRERGRIRKRBRDRFRHRJR@tncoltmodetfancyboxR?ttitletbbox_to_anchortbbox_transformtframeonR:R;t propnamest localdicttnametvaluetdeprecated_kwdsR/taxessize_fontsizetktvtreps((sD/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/legend.pyRosN                                                     cC sC|j|j|jr,|j|jn|j|jdS(sE set the boilerplate props for artists added to axes N(RsRtRqRrtaxest set_transformt get_transform(R ta((sD/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/legend.pyR|\s cC sG||_|dkr!|j}n |j}|jj|||_dS(Ni(t _loc_realt_findoffset_bestt_findoffset_locRt set_offset(R Rt _findoffset((sD/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/legend.pyt_set_locfs     cC s|jS(N(R(R ((sD/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/legend.pyt_get_locwscC s-|j|||\}}||||fS(s9Helper function to locate the legend at its best position(t_find_best_position(R R'R(txdescenttydescenttrenderertoxtoy((sD/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/legend.pyR|sc C st|jrkt|jdkrk|j\}}|j}|j|j||j|j|} } n?tj dd||}|j |j||j|\} } | || |fS(s;Heper function to locate the legend using the location codeii( RR-RgR&tx0R'ty0R(Rt from_boundst_get_anchored_bbox( R R'R(RRRtfxtfyR/txty((sD/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/legend.pyRs$ ,'cC s(|jsdS|jd|j|j}|jdkrvd|j|j|}|jj|j j |n|j r|jj |}|j j|j|j|j |j|j j||jrt|j dd}|j|n|j j|n|jj||jddS(s*Draw everything that belongs to the legendNRtexpandii(sexpand(t get_visiblet open_grouptpoints_to_pixelsR[RzRJRBRt set_widthR&R'R}tget_window_extentR!t set_boundsRRR(tset_mutation_scaleR?R tdrawt close_group(R RtfontsizeRCR/R?((sD/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/legend.pyRs$     cC s'|dkr|jS|j|jSdS(sm Return the approximate height of the text. This is used to place the legend handle. N(R*R[R(R R((sD/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/legend.pyt_approx_text_heights c- C sw |j}g}g}tddddd|j}g}g}|jd} d} xt||D]\} } t| tst| tr|j} n |j } | dkrt j d ||j d || }|}n?| dkrt j d |j |d }d |j |g}nt| t rN| | d t j|jt}t ||}|j| |j||jd)|jd)|jd|jd|j|t ||t| }|j| |j||jd)|jd)|jd|jdkrB|j|j}|j|n||_nt| trt dd*d|j |d| | }|j| |j||jd)|jd)|j|n_t| t!r| | d t j|jt}t ||}|j||jd)|jd)| j"d }| j#d }| j$d }|j%||j&||d d)k r|j'|dn|j|n{t| tr| |j(}t)| j*|jd t+| j*|jd }}|jdkr+d ||||g}n$||t j d d|j|}t,| | j-d| j.d|dt||d|j/}|j| |j0|j1|jd)|jd)|j|nKt| tr| |j(}t)| j*|jd t+| j*|jd }}|jdkr[d ||||g}n$||t j d d|j|}t,| |dt||d|j/}|j| |j0|j1|jd)|jd)|j|n3t,| }t2j3dt4|f|jd)|d} | d)k ret5| d|dt6dt6}|j|j7|j|t8d|j |d| ddd| }|j9| t| tst| tr|j/| _:| j;d)nt<| dr |j9| jn|j|qeqeWt|d krt+|j=t|}t>t||\}} || }!t?t@d | |d|d|dg| }"t?t@| |dt|||g|!}#n gg}"}#t?||}$g}%x|"|#D]\}&}'g|$|&|&|'!D]:\}(})tAd d d!|jB|d"|(|)gd#d^q}*|*djCdjDtE|%jtFd d d!|jG|d#dd"|*qW|jHd$krd$}+nd%}+|jI|},tAd d d!|,d#dd&|+d"|%|_Jt5d'|_KtFd |jL|d!|jG|d#d(d"|jK|jJg|_M|jMj0|j1||_N||_Od)S(+s Initiallize the legend_box. The legend_box is an instance of the OffsetBox, which is packed with legend handles and texts. Once packed, their location is calculated during the drawing time. tverticalalignmenttbaselinethorizontalalignmenttlefttfontpropertiesgffffff?gig333333?iig?g@tdefaultR*RLR'R(itrotationtsizestoffsetst transOffsetsLegend does not support %s Use proxy artist instead. http://matplotlib.sourceforge.net/users/legend_guide.html#using-proxy-artist it textpropstmultilinebaselinetminimumdescentRRt _legmarkerRCtseptchildrentalignRtfixedRtR8N(gg(PR[RXRVRtzipRWRRRAR=RjtlinspaceRFR tonestshapetfloatt update_fromR|t set_clip_boxR*t set_clip_patht set_drawstylet set_markertappendRgt set_linestyleR>tget_markersizetset_markersizeRR R Rt get_linewidtht get_dashest get_colorst set_colort set_linewidtht set_dashesRltmaxt get_sizesRattypet get_numsidest get_rotationRRsRtRcRdtstrRRpt_textRt add_artistt _transOffsetRthasattrRhtdivmodRtrangeRRHt get_childrentset_minimumdescentR4RRDRzR@t_legend_handle_boxR^RBRR\R](-R RRRt text_listt handle_listt label_propt labelboxest handleboxesR(tdescentthandletlabtnpointstxdatat xdata_markertydatatleglinetlegline_markertnewsztptlwtdashestcolortsize_maxtsize_minRt handle_typettextboxt handleboxRtnrowst num_largecolt num_smallcoltlargecoltsmallcolt handle_labelt columnboxti0tdithttt itemBoxesRR((sD/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/legend.pyR~s8           !                    !      ! $     ! $            O        c C s|j}g}g}g}xE|jD]:}|j}|j}|j|}|j|q%Wxs|jD]h}t|tr|j } |j|j j | qm|j} |j|jj | qmW|||gS(s{ Returns list of vertices and extents covered by the plot. Returns a two long list. First element is a list of (x, y) vertices (in display-coordinates) covered by all the lines and line collections, in the legend's handles. Second element is a list of bounding boxes for all the patches in the legend's handles. ( Rvtlinestget_pathRttransform_pathRtpatchesRWR tget_data_transformtget_bboxt transformedt get_extents( R taxtverticestbboxesRRtpathttransttpatht transform((sD/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/legend.pyt_auto_legend_datas       cC s|j|dS(s$b is a boolean. Set draw frame to bN(t set_frame_on(R tb((sD/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/legend.pyt draw_framescC sg}|jr"|j|jn|j|j|j|j|j|j|j|j|jr|j|jn|S(sreturn a list of child artists( RRtextendt get_linest get_patchest get_textst get_frameR^t get_title(R R((sD/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/legend.pyRs  cC s|jS(s6return the Rectangle instance used to frame the legend(R!(R ((sD/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/legend.pyR,scC s)g|jD]}t|tr |^q S(s5return a list of lines.Line2D instances in the legend(R]RWR (R R((sD/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/legend.pyR)scC s2tdg|jD]}t|tr|^qS(s.return a list of patch instances in the legendR (RR]RWR (R R((sD/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/legend.pyR*scC std|jS(s1return a list of text.Text instance in the legendtText(RR\(R ((sD/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/legend.pyR+scC s@|jjj||r,|jjtn|jjtdS(sset the legend titleN(R^Rtset_textt set_visibleRpR4(R R((sD/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/legend.pyRscC s |jjS(s)return Text instance for the legend title(R^R(R ((sD/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/legend.pyR-scC s |jjS(s!return a extent of the the legend(R!R(R ((sD/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/legend.pyRscC s|jS(s; Get whether the legend box patch is drawn (R}(R ((sD/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/legend.pyt get_frame_onscC s ||_dS(sb Set whether the legend box patch is drawn ACCEPTS: [ *True* | *False* ] N(R}(R R&((sD/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/legend.pyR% scC s$|jdkr|jjS|jSdS(sB return the bbox that the legend will be anchored N(t_bbox_to_anchorR*RvR/(R ((sD/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/legend.pyR&(s cC s|dkrd|_dSt|tr4||_nuyt|}Wn'tk rmtdt|nX|dkr|d|dddg}ntj ||_|dkrt |j j }nt |j||_dS(s> set the bbox that the legend will be anchored. *bbox* can be a BboxBase instance, a tuple of [left, bottom, width, height] in the given transform (normalized axes coordinate if None), or a tuple of [left, bottom] where the width and height will be assumed to be zero. NsInvalid argument for bbox : %siii(R*R2RWRRgRuRiRRRRRvR/R(R R/R#tl((sD/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/legend.pyR)2s       c C std\ }}}}} } } } } }}i d|6d|6d|6d| 6d| 6d| 6d| 6d| 6d |6d |6}||}|j|j}|j|j |}|j|d |}|j|jfS( s Place the *bbox* inside the *parentbbox* according to a given location code. Return the (x,y) coordinate of the bbox. - loc: a location code in range(1, 11). This corresponds to the possible values for self._loc, excluding "best". - bbox: bbox to be placed, display coodinate units. - parentbbox: a parent box which will contain the bbox. In display coordinates. i tNEtNWtSWtSEtEtWtStNtCt container(RRR[tpaddedRJtanchoredRR(R RR/t parentbboxRtBESTtURtULtLLtLRtRtCLtCRtLCtUCR<t anchor_coefstcRR=t anchored_box((sD/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/legend.pyRSs -   cC s|j\}}}tjdd||}gtdt|jD]$} |j| ||j|^qF}g} x|D]\} } tj| | ||} d}| j|}|| j |7}x*|D]"}|j | r|d7}qqW| | }}|dkr||fS| j || | ffq}W| d}x+| D]#}|d|dkrG|}qGqGW|d\}}||fS(s Determine the best location to place the legend. `consider` is a list of (x, y) pairs to consider as a potential lower-left corner of the legend. All are display coords. ii( R$RRRRgRwRR&tcount_containstcount_overlapstintersects_bboxR(R R'R(RtconsidertvertsRRR/Rt candidatesR3R&t legendBoxtbadnesstlineRRt minCandidatet candidate((sD/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/legend.pyRvs. @       cC s|jdk }|dkr%| }n|rR|jdkrzt|||_qzn(|jdk rq|jjnd|_|jS(s[ Set the draggable state -- if state is * None : toggle the current state * True : turn draggable on * False : turn draggable off If draggable is on, you can drag the legend on the canvas with the mouse. The DraggableLegend helper instance is returned if draggable is on. N(RR*Rt disconnect(R tstateRt is_draggable((sD/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/legend.pyt draggables   (&R2R3t__doc__RwtzorderR9R*RpRR|RRtpropertyR-RRRRRR~R$R'RR,R)R*R+RR-RR1R%R&R)RRR4R\(((sD/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/legend.pyR5As       $  (           ! # 0(+R]t __future__RRctnumpyRjt matplotlibRtmatplotlib.artistRRtmatplotlib.cbookRRRRtmatplotlib.font_managerRtmatplotlib.linesR tmatplotlib.patchesR R R R tmatplotlib.collectionsRRRtmatplotlib.transformsRRRRRtmatplotlib.offsetboxRRRRRRR5(((sD/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/legend.pyts  ""((