ó ù)°Uc@s;dZddlZddlZddlZddljZddlj Z ddlm Z ddl j Z ddl jZddljZddljZddljZddljZddljZdZdZdeefZe jjdeƒde jfd „ƒYZ d e fd „ƒYZ!e j"eƒd „ƒZ#dS( sµ Colorbar toolkit with two classes and a function: :class:`ColorbarBase` the base class with full colorbar drawing functionality. It can be used as-is to make a colorbar for a given colormap; a mappable object (e.g., image) is not needed. :class:`Colorbar` the derived class for use with images or contour plots. :func:`make_axes` a function for resizing an axes and adding a second axes suitable for a colorbar The :meth:`~matplotlib.figure.Figure.colorbar` method uses :func:`make_axes` and :class:`Colorbar`; the :func:`~matplotlib.pyplot.colorbar` function is a thin wrapper over :meth:`~matplotlib.figure.Figure.colorbar`. iÿÿÿÿN(t docstringse ============= ==================================================== Property Description ============= ==================================================== *orientation* vertical or horizontal *fraction* 0.15; fraction of original axes to use for colorbar *pad* 0.05 if vertical, 0.15 if horizontal; fraction of original axes between colorbar and new image axes *shrink* 1.0; fraction by which to shrink the colorbar *aspect* 20; ratio of long to short dimensions ============= ==================================================== sH =========== ==================================================== Property Description =========== ==================================================== *extend* [ 'neither' | 'both' | 'min' | 'max' ] If not 'neither', make pointed end(s) for out-of- range values. These are set for a given colormap using the colormap set_under and set_over methods. *spacing* [ 'uniform' | 'proportional' ] Uniform spacing gives each discrete color the same space; proportional makes the space proportional to the data interval. *ticks* [ None | list of ticks | Locator object ] If None, ticks are determined automatically from the input. *format* [ None | format string | Formatter object ] If None, the :class:`~matplotlib.ticker.ScalarFormatter` is used. If a format string is given, e.g. '%.3f', that is used. An alternative :class:`~matplotlib.ticker.Formatter` object may be given instead. *drawedges* [ False | True ] If true, draw lines at color boundaries. =========== ==================================================== The following will probably be useful only in the context of indexed colors (that is, when the mappable has norm=NoNorm()), or other unusual circumstances. ============ =================================================== Property Description ============ =================================================== *boundaries* None or a sequence *values* None or a sequence which must be of length 1 less than the sequence of *boundaries*. For each region delimited by adjacent entries in *boundaries*, the color mapped to the corresponding value in values will be used. ============ =================================================== s> Add a colorbar to a plot. Function signatures for the :mod:`~matplotlib.pyplot` interface; all but the first are also method signatures for the :meth:`~matplotlib.figure.Figure.colorbar` method:: colorbar(**kwargs) colorbar(mappable, **kwargs) colorbar(mappable, cax=cax, **kwargs) colorbar(mappable, ax=ax, **kwargs) arguments: *mappable* the :class:`~matplotlib.image.Image`, :class:`~matplotlib.contour.ContourSet`, etc. to which the colorbar applies; this argument is mandatory for the :meth:`~matplotlib.figure.Figure.colorbar` method but optional for the :func:`~matplotlib.pyplot.colorbar` function, which sets the default to the current image. keyword arguments: *cax* None | axes object into which the colorbar will be drawn *ax* None | parent axes object from which space for a new colorbar axes will be stolen Additional keyword arguments are of two kinds: axes properties: %s colorbar properties: %s If *mappable* is a :class:`~matplotlib.contours.ContourSet`, its *extend* kwarg is included automatically. Note that the *shrink* kwarg provides a simple way to keep a vertical colorbar, for example, from being taller than the axes of the mappable to which the colorbar is attached; but it is a manual method requiring some trial and error. If the colorbar is too tall (or a horizontal colorbar is too wide) use a smaller value of *shrink*. For more precise control, you can manually specify the positions of the axes objects in which the mappable and the colorbar are drawn. In this case, do not use any of the axes properties kwargs. returns: :class:`~matplotlib.colorbar.Colorbar` instance; see also its base class, :class:`~matplotlib.colorbar.ColorbarBase`. Call the :meth:`~matplotlib.colorbar.ColorbarBase.set_label` method to label the colorbar. t colorbar_doct ColorbarBasec BsYeZdZieddƒd6eddƒd6eddƒd6eddƒd6Zd#d#d#d#d#d dd d#d#eed „ Zd „Z d „Z d„Z d„Z ed„Z ed„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd#d„Zd„Zd„Zd„Zd„Zd„Zd „Zd!„Zd"„ZRS($s) Draw a colorbar in an existing axes. This is a base class for the :class:`Colorbar` class, which is the basis for the :func:`~matplotlib.pyplot.colorbar` function and the :meth:`~matplotlib.figure.Figure.colorbar` method, which are the usual ways of creating a colorbar. It is also useful by itself for showing a colormap. If the *cmap* kwarg is given but *boundaries* and *values* are left as None, then the colormap will be displayed on a 0-1 scale. To show the under- and over-value colors, specify the *norm* as:: colors.Normalize(clip=False) To show the colors versus index instead of on the 0-1 scale, use:: norm=colors.NoNorm. Useful attributes: :attr:`ax` the Axes instance in which the colorbar is drawn :attr:`lines` a LineCollection if lines were drawn, otherwise None :attr:`dividers` a LineCollection if *drawedges* is True, otherwise None Useful public methods are :meth:`set_label` and :meth:`add_lines`. ii@BtneitheriiÿÿÿÿtbothtmintmaxtverticaltuniformcCsº||_|jƒ|dkr.tjƒ}n|dkrItjƒ}n||_tjj |d|d|ƒ||_ ||_ ||_ |j ||_| |_||_| |_| |_d|_d|_d|_d|_d|_|jdƒtj| ƒr'tj| dt| ƒƒ|_n | |_| dkrut|j tj!ƒrctj"ƒ|_#q¢tj$ƒ|_#n-tj%| ƒr™tj&| ƒ|_#n | |_#|j'ƒ|j(ƒdS(Ntcmaptnormttnbins()taxt _patch_axtNonetcmtget_cmaptcolorst NormalizetalphatScalarMappablet__init__tvaluest boundariestextendt _slice_dictt_insidetspacingt orientationt drawedgestfilledtsolidstlinestoutlinetpatchtdividerst set_labeltcbooktiterablettickert FixedLocatortlentlocatort isinstanceR tLogNormt LogFormattert formattertScalarFormattertis_string_liketFormatStrFormattert config_axistdraw_all(tselfR R R RRRRRRttickstformatRR((sF/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/colorbar.pyRÆsD                  !    cCs%d„}||j_||j_dS(Nc_stjdƒdS(Ns,Use the colorbar set_ticks() method instead.(twarningstwarn(targstkw((sF/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/colorbar.pyt_warnùs(R t set_xtickst set_yticks(R5R<((sF/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/colorbar.pyRøs  cCsu|jƒ|jƒ|jƒ\}}|jdd…tjf}|j||ƒ|jrq|j|||ƒndS(ss Calculate any free parameters based on the current cmap and norm, and do all the drawing. N( t_process_valuest _find_ranget_mesht_valuestnptnewaxist _config_axesRt _add_solids(R5tXtYtC((sF/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/colorbar.pyR4ÿs   cCsy|j}|jdkrK|jjgƒ|jjdƒ|jjdƒn |jjgƒ|jjdƒ|jƒdS(NRtrighttbottom(R Rtxaxist set_tickstyaxistset_label_positiontset_ticks_positiont _set_label(R5R ((sF/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/colorbar.pyR3 s cCsš|j}|jƒ\}}}|jdkrc|jj|ƒ|j|ƒ|jjƒj|ƒn3|jj|ƒ|j |ƒ|jjƒj|ƒdS(s” Force the update of the ticks and ticklabels. This must be called whenever the tick locator and/or tick formatter changes. RN( R t_tickerRRNRMtset_yticklabelstget_major_formattertset_offset_stringRLtset_xticklabels(R5R R6t ticklabelst offset_string((sF/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/colorbar.pyt update_tickss   cCsPtj|ƒr0tj|dt|ƒƒ|_n ||_|rL|jƒndS(s¹ set tick locations. Tick locations are updated immediately unless update_ticks is *False*. To manually update the ticks, call *update_ticks* method explicitly. R N(R&R'R(R)R*R+RY(R5R6RY((sF/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/colorbar.pyRM)s ! cCsNt|jtjƒr=tj|ƒ|_|rJ|jƒqJn tjdƒdS(s³ set tick labels. Tick labels are updated immediately unless update_ticks is *False*. To manually update the ticks, call *update_ticks* method explicitly. s"set_ticks() must have been called.N( R,R+R(R)tFixedFormatterR/RYR8R9(R5RWRY((sF/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/colorbar.pytset_ticklabels6s c Csz|j}|jtƒ|jtƒ|j||ƒ}|j|ƒ|j|jjŒ|j |jj Œ|j dk r‡|j j ƒntj|dd…df|dd…dfdtjddtjdƒ|_ |j|j ƒ|j jdƒ|j jdƒtjd}|jdk r2|jj ƒntj|d |d |dd d d ƒ|_|j|jƒ|jƒdS(s1 Make an axes patch and outline. Niitcolorsaxes.edgecolort linewidthsaxes.linewidthsaxes.facecolort edgecolort facecolorg{®Gáz„?tzorderiÿÿÿÿ(R t set_frame_ontFalset set_navigatet_outlinetupdate_datalimtset_xlimtdataLimt intervalxtset_ylimt intervalyR"RtremoveR!tLine2DtmpltrcParamst add_artistt set_clip_boxt set_clip_pathR#tpatchestPolygonRY(R5RGRHR txytc((sF/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/colorbar.pyRECs.    <  cCsH|jdkr+|jj|j|jn|jj|j|jdS(NR(RR t set_ylabelt_labelt_labelkwt set_xlabel(R5((sF/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/colorbar.pyRQascKs ||_||_|jƒdS(s5 Label the long axis of the colorbar N(RwRxRQ(R5tlabelR;((sF/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/colorbar.pyR%gs  c Csý|jd}dd|d|dd|dd|d|d|dg }tjtjtj|ƒƒ|ƒ}tjtjtj|ƒƒ|ƒ}|jt|ƒdfƒ}|jt|ƒdfƒ}|jdkrêtj||fƒStj||fƒS(so Return *x*, *y* arrays of colorbar bounding polygon, taking orientation into account. iiit horizontal( tshapeRCttaketravelt transposetreshapeR*Rthstack(R5RGRHtNtiitxty((sF/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/colorbar.pyRdps =$$cCsŠ|jd}|jdkrQgtd|dƒD]}t||||ƒ^q0Sgtd|dƒD]}t||||ƒ^qeSdS(sM Return the separator line segments; helper for _add_solids. iRiN(R|Rtrangetzip(R5RGRHR‚ti((sF/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/colorbar.pyt_edgess 5cCsh|jdkr!|||f}n*tj|ƒtj|ƒtj|ƒf}i|jd6|jd6|jd6}|jjƒ}|jjt ƒ|jj ||Ž}|jj|ƒ|j d k rÒ|j j ƒn||_ |jd k r|jj ƒd |_n|jrdtj|j||ƒdtjdfddtjd fƒ|_|jj|jƒnd S( sp Draw the colors using :meth:`~matplotlib.axes.Axes.pcolor`; optionally add separators. RR R RRsaxes.edgecolort linewidthsgà?saxes.linewidthN(RRCRR R RR tisholdtholdtTruet pcolormeshR RRkR$Rt collectionstLineCollectionR‰RmRntadd_collection(R5RGRHRIR:R;t_holdtcol((sF/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/colorbar.pyRF‹s(*     c Cs9t|ƒ}|j|ƒ\}}t|ƒ|krBtdƒ‚ntjddgƒ}tj||ƒ\}} |jdkr±gt|ƒD]} t|| | | ƒ^q‹} n0gt|ƒD]} t| | || ƒ^q¾} t j | d|ƒ} |j r|j j ƒn| |_ | j |ƒ|jj| ƒdS(s- Draw lines on the colorbar. s!levels are outside colorbar rangeggð?RRŠN(R*t_locatet ValueErrorRCtarraytmeshgridRR†R‡RRR!Rkt set_colorR R‘( R5tlevelsRRŠR‚tdummyR…R„RGRHRˆRtR“((sF/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/colorbar.pyt add_lines¬s 30   c sE|j}|j}|d kr|jd krìt|jtjƒr€t|j ƒ}dt |dƒ}t j d|ddƒ}qt|jtj ƒr¹|jj}t j|ddƒ}qt|jtjƒrÝt jƒ}qt jƒ}q|j|j}t j|ddƒ}nt|jtjƒrF|j d|j df‰n|j|jf‰|jƒ|jƒ|jˆŒ|jˆŒ|jˆŒ|jˆŒ‡fd†|j_‡fd †|j_tj|ƒƒ}|j|ƒ\}}|j|ƒgt|ƒD]\}}|||ƒ^q } |j ƒ} || | fS( si Return two sequences: ticks (colorbar data locations) and ticklabels (strings). ii tbasetoffsetiR iÿÿÿÿcsˆdS(Ni(((tintv(sF/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/colorbar.pytæscsˆdS(Ni(((Rž(sF/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/colorbar.pyRŸçsN(!R+R/RRR,R RtNoNormR*RBtintR(t IndexLocatort BoundaryNormR)R-t LogLocatort MaxNLocatort _boundariesRtvmintvmaxtcreate_dummy_axistset_view_intervaltset_data_intervaltaxist get_minposRCR–R”tset_locst enumeratet get_offset( R5R+R/tnvRœtbR6RˆttRWRX((RžsF/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/colorbar.pyRRÃsB           . cCs9|dkr|j}n|dk r»tj|dtƒ|_|jdkr¢d|jd |jd|_t|j t j ƒrž|jdj tj ƒ|_ndStj|jƒ|_dS|jdk rŠtj|jƒ|_|jdkrqtjt|jƒddƒ}d|jd |jd|dd+d|d|d |d Ntdg@iiiþÿÿÿiýÿÿÿRRR(Rsmin(Rsmax(Rsmin(Rsmax(Rsmin(Rsmax(Rsmin(Rsmax(RRRCtasarraytfloatR¦RRBR,R RR tastypetint16R–tzerosR*t _uniform_yR R‚tarangeRRR£tlisttscaledR§R¨tinverseR?(R5R²tvtbi((sF/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/colorbar.pyR?ïsx    # '%%   "    %cCs.|j|j}|d|_|d|_dS(sˆ Set :attr:`vmin` and :attr:`vmax` attributes to the first and last boundary excluding extended end boundaries. iiÿÿÿÿN(R¦RR§R¨(R5R²((sF/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/colorbar.pyR@5s cCsKt|jƒ}|jdkr+|d8}n|jdkrG|d8}n|S(s1number of boundaries **before** extension of endsRiRRi(sminsmax(R*R¦R(R5tnb((sF/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/colorbar.pyt _central_N>s   cCsL|jjd}|jdkr,|d7}n|jdkrH|d7}n|S(se Based on the colormap and extend variable, return the number of boundaries. iRiRR(sminsmax(R R‚R(R5R‚((sF/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/colorbar.pyt _extended_NGs   cCsÕ|jdkr'tjdd|ƒ}nª|jdkrctj|ddƒ}d|ds,   ,<ÿÿn