B
    ·ôJdû  ã               @   s¤  d Z ddlZddlZddlZddlZddlZddlmZm	Z	m
Z
mZ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lmZ ddlm Z  e !e"¡Z#dZ$dZ%dZ&e j'j(de )e$d	¡e )e%d	¡e&f d
 ej*G dd„ dƒƒZ+dd„ Z,G dd„ dej-ƒZ.G dd„ dƒZ/G dd„ dƒZ0e0Z1dd„ Z2e  3e$e%¡d%dd„ƒZ4e  3e$e%¡ddddddœdd„ƒZ5ej6ddd G d!d"„ d"e0ƒƒZ7ej6ddd d#d$„ ƒZ8dS )&aë  
Colorbars are a visualization of the mapping from scalar values to colors.
In Matplotlib they are drawn into a dedicated `~.axes.Axes`.

.. note::
   Colorbars are typically created through `.Figure.colorbar` or its pyplot
   wrapper `.pyplot.colorbar`, which internally use `.Colorbar` together with
   `.make_axes_gridspec` (for `.GridSpec`-positioned axes) or `.make_axes` (for
   non-`.GridSpec`-positioned axes).

   End-users most likely won't need to directly use this module's API.
é    N)Ú_apiÚcollectionsÚcmÚcolorsÚcontourÚticker)Ú	docstringaï  
location : None or {'left', 'right', 'top', 'bottom'}
    The location, relative to the parent axes, where the colorbar axes
    is created.  It also determines the *orientation* of the colorbar
    (colorbars on the left and right are vertical, colorbars at the top
    and bottom are horizontal).  If None, the location will come from the
    *orientation* if it is set (vertical colorbars on the right, horizontal
    ones at the bottom), or default to 'right' if *orientation* is unset.
orientation : None or {'vertical', 'horizontal'}
    The orientation of the colorbar.  It is preferable to set the *location*
    of the colorbar, as that also determines the *orientation*; passing
    incompatible values for *location* and *orientation* raises an exception.
fraction : float, default: 0.15
    Fraction of original axes to use for colorbar.
shrink : float, default: 1.0
    Fraction by which to multiply the size of the colorbar.
aspect : float, default: 20
    Ratio of long to short dimensions.
aì  
pad : float, default: 0.05 if vertical, 0.15 if horizontal
    Fraction of original axes between colorbar and new image axes.
anchor : (float, float), optional
    The anchor point of the colorbar axes.
    Defaults to (0.0, 0.5) if vertical; (0.5, 1.0) if horizontal.
panchor : (float, float), or *False*, optional
    The anchor point of the colorbar parent axes. If *False*, the parent
    axes' anchor will be unchanged.
    Defaults to (1.0, 0.5) if vertical; (0.5, 0.0) if horizontal.
aý  

    ============  ====================================================
    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.
    *extendfrac*  {*None*, 'auto', length, lengths}
                  If set to *None*, both the minimum and maximum
                  triangular colorbar extensions with have a length of
                  5% of the interior colorbar length (this is the
                  default setting). If set to 'auto', makes the
                  triangular colorbar extensions the same lengths as
                  the interior boxes (when *spacing* is set to
                  'uniform') or the same lengths as the respective
                  adjacent interior boxes (when *spacing* is set to
                  'proportional'). If a scalar, indicates the length
                  of both the minimum and maximum triangular colorbar
                  extensions as a fraction of the interior colorbar
                  length. A two-element sequence of fractions may also
                  be given, indicating the lengths of the minimum and
                  maximum colorbar extensions respectively as a
                  fraction of the interior colorbar length.
    *extendrect*  bool
                  If *False* the minimum and maximum colorbar extensions
                  will be triangular (the default). If *True* the
                  extensions will be rectangular.
    *spacing*     {'uniform', 'proportional'}
                  Uniform spacing gives each discrete color the same
                  space; proportional makes the space proportional to
                  the data interval.
    *ticks*       *None* or list of ticks or Locator
                  If None, ticks are determined automatically from the
                  input.
    *format*      None or str or Formatter
                  If None, `~.ticker.ScalarFormatter` is used.
                  If a format string is given, e.g., '%.3f', that is used.
                  An alternative `~.ticker.Formatter` may be given instead.
    *drawedges*   bool
                  Whether to draw lines at color boundaries.
    *label*       str
                  The label on the colorbar's long axis.
    ============  ====================================================

    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
                   colormapped to the corresponding value in values
                   will be used.
    ============   ===================================================

a	  
Add a colorbar to a plot.

Parameters
----------
mappable
    The `matplotlib.cm.ScalarMappable` (i.e., `~matplotlib.image.AxesImage`,
    `~matplotlib.contour.ContourSet`, etc.) described by this colorbar.
    This argument is mandatory for the `.Figure.colorbar` method but optional
    for the `.pyplot.colorbar` function, which sets the default to the current
    image.

    Note that one can create a `.ScalarMappable` "on-the-fly" to generate
    colorbars not attached to a previously drawn artist, e.g. ::

        fig.colorbar(cm.ScalarMappable(norm=norm, cmap=cmap), ax=ax)

cax : `~matplotlib.axes.Axes`, optional
    Axes into which the colorbar will be drawn.

ax : `~matplotlib.axes.Axes`, list of Axes, optional
    One or more parent axes from which space for a new colorbar axes will be
    stolen, if *cax* is None.  This has no effect if *cax* is set.

use_gridspec : bool, optional
    If *cax* is ``None``, a new *cax* is created as an instance of Axes.  If
    *ax* is an instance of Subplot and *use_gridspec* is ``True``, *cax* is
    created as an instance of Subplot using the :mod:`.gridspec` module.

Returns
-------
colorbar : `~matplotlib.colorbar.Colorbar`

Notes
-----
Additional keyword arguments are of two kinds:

  axes properties:
%s
%s
  colorbar properties:
%s

If *mappable* is a `~.contour.ContourSet`, its *extend* kwarg is included
automatically.

The *shrink* kwarg provides a simple way to scale the colorbar with respect
to the axes. Note that if *cax* is specified, it determines the size of the
colorbar and *shrink* and *aspect* kwargs are ignored.

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.

It is known that some vector graphics viewers (svg and pdf) renders white gaps
between segments of the colorbar.  This is due to bugs in the viewers, not
Matplotlib.  As a workaround, the colorbar can be rendered with overlapping
segments::

    cbar = colorbar()
    cbar.solids.set_edgecolor("face")
    draw()

However this has negative consequences in other circumstances, e.g. with
semi-transparent images (alpha < 1) and colorbar extensions; therefore, this
workaround is not used by default (see issue #1188).
z    )Úcolorbar_docc               @   sZ   e Zd Zejdddedd„ ƒƒZejdddedd„ ƒƒZejdddedd„ ƒƒZdS )	Ú__getattr__z3.4Ú )Úobj_typec             C   s   t jjd S )Nr	   )r   ÚinterpdÚparams)Úself© r   úE/var/www/html/venv/lib/python3.7/site-packages/matplotlib/colorbar.pyÚ<lambda>È   ó    z__getattr__.<lambda>c             C   s   t S )N)Ú_colormap_kw_doc)r   r   r   r   r   Ê   r   c             C   s   t t S )N)Ú_make_axes_param_docÚ_make_axes_other_param_doc)r   r   r   r   r   Ì   r   N)	Ú__name__Ú
__module__Ú__qualname__r   Ú
deprecatedÚpropertyr	   Zcolorbar_kw_docZmake_axes_kw_docr   r   r   r   r
   Å   s   r
   c              O   s   t  d¡ d S )Nz,Use the colorbar set_ticks() method instead.)r   Zwarn_external)ÚargsÚkwr   r   r   Ú_set_ticks_on_axis_warnÏ   s    r   c                   s6   e Zd Z‡ fdd„Zd
dd„Zdd„ Zdd	„ Z‡  ZS )Ú_ColorbarSpinec                s:   || _ tƒ  |dtjt d¡dd¡ tj 	| |j
¡ d S )NÚcolorbar)r   é   T)Úclosed)Z_axÚsuperÚ__init__ÚmpathÚPathÚnpÚemptyÚmpatchesÚPatchZset_transformÚ	transAxes)r   Úaxes)Ú	__class__r   r   r$   Ö   s    
z_ColorbarSpine.__init__Nc             C   s   t jj| |dS )N)Úrenderer)r)   r*   Úget_window_extent)r   r.   r   r   r   r/   Ü   s    z _ColorbarSpine.get_window_extentc             C   s    t j|dd| _|| _d| _d S )NT)r"   )r%   r&   Ú_pathZ_xyÚstale)r   Úxyr   r   r   Úset_xyâ   s    z_ColorbarSpine.set_xyc             C   s   t j | |¡}d| _|S )NF)r)   r*   Údrawr1   )r   r.   Úretr   r   r   r4   ç   s    z_ColorbarSpine.draw)N)r   r   r   r$   r/   r3   r4   Ú__classcell__r   r   )r-   r   r   Õ   s   
r   c               @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	Ú_ColorbarAxesLocatorzI
    Shrink the axes if there are triangular or rectangular extends.
    c             C   s   || _ |jj| _d S )N)Ú_cbarÚaxÚ_axes_locatorÚ_orig_locator)r   Zcbarr   r   r   r$   ñ   s    z_ColorbarAxesLocator.__init__c       
      C   s  | j d k	r|   ||¡}n|jdd}| jjdkr4|S | j ¡ \}}| j ¡ sTd|d< | j ¡ sfd|d< t|ƒd }d| }|d | }t|dƒrœ|j	d }	nd}	| jj
d	krÞ|	rÂ| jj |	| ¡ | d|¡ d||j ¡}n4|	rø| jj d|	|  ¡ | |d¡ ||j d¡}|S )
NT)ÚoriginalÚneitherr   é   Ú_colorbar_infoÚaspectFÚvertical)r;   Úget_positionr8   ÚextendÚ_proportional_yÚ_extend_lowerÚ_extend_upperÚsumÚhasattrr?   Úorientationr9   Úset_box_aspectÚshrunkZ
translatedÚheightÚwidth)
r   r9   r.   ÚposÚyÚ	extendlenÚlenÚshrinkÚoffsetr@   r   r   r   Ú__call__õ   s0    



z_ColorbarAxesLocator.__call__c             C   s6   t | jjdd ƒ}|d kr0t| jdƒs(d S | jj}|ƒ S )NÚget_subplotspec)Úgetattrr8   r9   rH   r;   rU   )r   Ússr   r   r   rU     s    z$_ColorbarAxesLocator.get_subplotspecN)r   r   r   Ú__doc__r$   rT   rU   r   r   r   r   r7   í   s   "r7   c               @   s®  e Zd ZdZdZd_dddddddddddddddd	d
œdd„Zdd„ ZejdddZ	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zd`dd„Zdd„ Zd d!„ Zd"d#„ Ze dd$¡dadd%œd&d'„ƒZdbd(d)„Ze dd$¡dcdd%œd*d+„ƒZd,d-„ Zd.d/„ Zdd0œd1d2„Zd3d4„ Zd5d6„ Zd7d8„ Zd9d:„ Zd;d<„ Zd=d>„ Zd?d@„ Z dAdB„ Z!dCdD„ Z"dEdF„ Z#dGdH„ Z$dIdJ„ Z%dddLdM„Z&dNdO„ Z'dPdQ„ Z(dRdS„ Z)dTdU„ Z*dVdW„ Z+dXdY„ Z,ded[d\„Z-d]d^„ Z.dS )fÚColorbaraÊ  
    Draw a colorbar in an existing axes.

    Typically, colorbars are created using `.Figure.colorbar` or
    `.pyplot.colorbar` and associated with `.ScalarMappable`\s (such as an
    `.AxesImage` generated via `~.axes.Axes.imshow`).

    In order to draw a colorbar not associated with other elements in the
    figure, e.g. when showing a colormap by itself, one can create an empty
    `.ScalarMappable`, or directly pass *cmap* and *norm* instead of *mappable*
    to `Colorbar`.

    Useful public methods are :meth:`set_label` and :meth:`add_lines`.

    Attributes
    ----------
    ax : `~matplotlib.axes.Axes`
        The `~.axes.Axes` instance in which the colorbar is drawn.
    lines : list
        A list of `.LineCollection` (empty if no lines were drawn).
    dividers : `.LineCollection`
        A LineCollection (empty if *drawedges* is ``False``).

    Parameters
    ----------
    ax : `~matplotlib.axes.Axes`
        The `~.axes.Axes` instance in which the colorbar is drawn.

    mappable : `.ScalarMappable`
        The mappable whose colormap and norm will be used.

        To show the under- and over- value colors, the mappable's norm should
        be specified as ::

            norm = colors.Normalize(clip=False)

        To show the colors versus index instead of on a 0-1 scale, use::

            norm=colors.NoNorm()

    cmap : `~matplotlib.colors.Colormap`, default: :rc:`image.cmap`
        The colormap to use.  This parameter is ignored, unless *mappable* is
        None.

    norm : `~matplotlib.colors.Normalize`
        The normalization to use.  This parameter is ignored, unless *mappable*
        is None.

    alpha : float
        The colorbar transparency between 0 (transparent) and 1 (opaque).

    values, boundaries
        If unset, the colormap will be displayed on a 0-1 scale.

    orientation : {'vertical', 'horizontal'}

    ticklocation : {'auto', 'left', 'right', 'top', 'bottom'}

    extend : {'neither', 'both', 'min', 'max'}

    spacing : {'uniform', 'proportional'}

    ticks : `~matplotlib.ticker.Locator` or array-like of float

    format : str or `~matplotlib.ticker.Formatter`

    drawedges : bool

    filled : bool

    extendfrac

    extendrec

    label : str
    é2   NrA   ÚautoÚuniformFTr   )ÚcmapÚnormÚalphaÚvaluesÚ
boundariesrI   ÚticklocationrC   ÚspacingÚticksÚformatÚ	drawedgesÚfilledÚ
extendfracÚ
extendrectÚlabelc            C   sð  |d krt j||d}| ¡ d k	r*| ¡  || _|j}|j}t|tj	ƒr†|}| 
¡ }|j}|j}|j}
|j}|d krštj|jdd}nt|tjƒrš| 
¡ }| |_|j d| j¡|_tjddg|d tjdd	d
ddg|	d tjddg|d || _t| ƒ| j_|
d krJt|tj	ƒs2t|ddƒdk	r2|j}
nt |dƒrF|j}
nd}
d | _!|  "|¡ || _|| _|| _#|| _$|
| _tj%t&dd ƒt&ddƒt&dd ƒt&ddƒdœ|
d| _'|| _(|| _)|| _*|| _|| _+|| _,g | _-d | _.g | _/g | _0x | jj1 #¡ D ]}| 2d¡ qôW t3| jƒ | _4| jj1d< |  5¡  2d¡ t6j7t8 9d¡t:j;d ddd| _<| =| j<¡ t>j?g t:j;d gd t:j;d!  gdd"| _@| j A| j@¡ d | _Bd | _Cd | _Dd | _E|	dkrÄ|dkrÀdnd
}	|	| _F|  G|¡ |  H¡  t8 I|¡rþtj|tJ|ƒd| _Bn|| _Bt|tKƒrt L|¡| _Dn|| _D|  M¡  t|tj	ƒrL|jsL|  N|¡ | | j_Ot| jtPjQtPjRfƒszt| jtj	ƒr†| j Sd¡ d#d$d%d&g| _Tx$| jTD ]}tU| j|t| |ƒƒ qœW | jV| j_W| jj d'| jX¡| _Y| jj d(| jX¡| _Zd S ))N)r^   r]   é
   )ÚnbinsÚchangedrA   Ú
horizontal)rI   r[   ÚleftÚrightÚtopÚbottom)rb   r\   Úproportional)rc   Úcolorbar_extendFrC   r=   r   r>   éÿÿÿÿ)r=   ÚbothÚminÚmax)rC   Úoutline)r   r!   zaxes.facecolorg{®Gáz„?)ÚcolorÚ	linewidthÚzorderzaxes.edgecolorg      à?zaxes.linewidth)r   Ú
linewidthsÚclip_onÚ	_get_viewÚ	_set_viewÚ_set_view_from_bboxÚdrag_panZxlim_changedZylim_changed)[r   ZScalarMappableZ	get_arrayZautoscale_NoneÚmappabler]   r^   Ú
isinstancer   Ú
ContourSetÚ	get_alphaZ_levelsZcvaluesrC   rg   r   ÚFixedLocatorÚlevelsÚmartistZArtistr    Ú	callbacksÚconnectÚupdate_normalÚcolorbar_cidr   Úcheck_in_listr9   r7   r:   rV   rt   rH   r_   Ú	set_alphar`   ra   Úcheck_getitemÚsliceÚ_insiderc   rI   rf   rh   ri   Ú_extend_patchesÚsolidsÚsolids_patchesÚlinesÚspinesZset_visibler   ry   Ú_short_axisr)   ZPolygonr'   r(   ÚmplÚrcParamsZ_patchZ
add_artistr   ÚLineCollectionÚdividersÚadd_collectionÚlocatorÚminorlocatorÚ	formatterÚ_Colorbar__scalerb   Ú	set_labelÚ_reset_locator_formatter_scaleÚiterablerQ   ÚstrZFormatStrFormatterÚdraw_allÚ	add_linesZ	_colorbarr   ÚBoundaryNormÚNoNormZset_navigateÚ_interactive_funcsÚsetattrÚ	_cbar_claÚclaÚ_do_extendsÚ_extend_cid1Ú_extend_cid2)r   r9   rƒ   r]   r^   r_   r`   ra   rI   rb   rC   rc   rd   re   rf   rg   rh   ri   rj   ÚcsZspineÚxr   r   r   r$   q  sÎ    









zColorbar.__init__c             C   s0   x| j D ]}t| j|ƒ qW | j`| j ¡  dS )z1Function to clear the interactive colorbar state.N)rª   Údelattrr9   r­   )r   r²   r   r   r   r¬     s    zColorbar._cbar_claz3.5r9   )Úalternativec             C   s€   t  d|j| j¡ || _|  | ¡ ¡ |j| _|j| jkrJ|j| _|  ¡  |  ¡  t	| jt
jƒrv| j}|jsv|  |¡ d| _dS )a
  
        Update solid patches, lines, etc.

        This is meant to be called when the norm of the image or contour plot
        to which this colorbar belongs changes.

        If the norm on the mappable is different than before, this resets the
        locator and formatter for the axis, so if these have been customized,
        they will need to be customized again.  However, if the norm only
        changes values of *vmin*, *vmax* or *cmap* then the old formatter
        and locator will be preserved.
        zcolorbar update normal %r %rTN)Ú_logÚdebugr^   rƒ   r   r†   r]   r£   r¦   r„   r   r…   rg   r§   r1   )r   rƒ   ÚCSr   r   r   rŒ     s    
zColorbar.update_normalc             C   sp  | j dkrtjd r0|  ¡  ntjd r0|  ¡  |  ¡ j| j| jd |  ¡  g ¡ |  ¡ jg dd |  	¡  | j
| j ddg \| _| _|  ¡ \}}|  ¡  | j| j }}|  ¡  ¡ rÂ|| }}| j dkrê| j dd	¡ | j ||¡ n| j dd	¡ | j ||¡ |  ¡  | jrlt t| jƒ¡}|  ¡ r<|d	d
… }|  ¡ rR|d
d… }|  ||| j|tjf ¡ d
S )zs
        Calculate any free parameters based on the current cmap and norm,
        and do all the drawing.
        rA   zytick.minor.visiblezxtick.minor.visible)Zlabel_positionZticks_positionT)Úminorr   ru   r>   N)rI   r™   rš   Úminorticks_onÚ
_long_axisÚsetrb   r˜   Ú	set_ticksÚ_process_valuesÚ_boundariesr’   ÚvminÚvmaxÚ_meshr®   Úget_invertedr9   Zset_xlimZset_ylimÚupdate_ticksrg   r'   ÚarangerQ   Ú_valuesrE   rF   Ú_add_solidsZnewaxis)r   ÚXÚYÚlowerÚupperÚindr   r   r   r¦   /  s:    








zColorbar.draw_allc          
   C   s¼   | j dk	r| j  ¡  x| jD ]}| ¡  qW t| ddƒ}t|tjƒrjtdd„ |jD ƒƒrj|  	||||¡ nF| j
j|||| j| j| jddd| _ | js°t| jƒ| jkr°| j  d¡ |  ¡  dS )	z+Draw the colors; optionally add separators.Nrƒ   c             s   s   | ]}|d k	V  qd S )Nr   )Ú.0Úhatchr   r   r   ú	<genexpr>n  s    z'Colorbar._add_solids.<locals>.<genexpr>ÚnoneÚflat)r]   r^   r_   Z
edgecolorsZshadingT)r”   Úremover•   rV   r„   r   r…   ÚanyÚhatchesÚ_add_solids_patchesr9   Z
pcolormeshr]   r^   r_   rf   rQ   Ú_yÚn_rasterizeZset_rasterizedÚ_update_dividers)r   rÇ   rÈ   ÚCZsolidrƒ   r   r   r   rÆ   c  s    

zColorbar._add_solidsc             C   sö   | j s| j g ¡ d S | jdkrH| j ¡ }|d | jk | j|d k @ }n&| j ¡ }|d | jk | j|d k @ }| j| }|  ¡ r’t	 
|d|d ¡}|  ¡ rªt	 ||d ¡}t	 ddg|¡\}}| jdkrØt	 ||g¡}nt	 ||g¡}| j |¡ d S )NrA   r   r>   )rf   rœ   Zset_segmentsrI   r9   Zget_ylimrÕ   Zget_xlimrE   r'   ÚinsertrF   ÚappendÚmeshgridZdstack)r   ZlimsZboundsrO   rÇ   rÈ   Úsegmentsr   r   r   r×   y  s$    




zColorbar._update_dividersc       
   
   C   sô   |j t|ƒ }g }xÖtt|ƒd ƒD ]Â}t ||df ||df g||df ||df g||d df ||d df g||d df ||d df gg¡}tjt |¡|  	|  
|| d ¡¡|| dd| jd}	| j |	¡ | |	¡ q$W || _d S )Nr>   r   F)Ú	facecolorrÍ   r{   Úantialiasedr_   )rÓ   rQ   Úranger'   Úarrayr)   Ú	PathPatchr%   r&   r]   r^   r_   r9   Ú	add_patchrÚ   r•   )
r   rÇ   rÈ   rØ   rƒ   rÓ   ÚpatchesÚir2   Úpatchr   r   r   rÔ   ‘  s    $zColorbar._add_solids_patchesc             C   sD  x| j D ]}| ¡  qW g | _ |  ¡ \}}d|  ¡ r<|d nd }d|  ¡ rT|d nd }| js–t ddgd|gddgddgd|gddgddgg¡}n@t ddgd|gd|gddgddgd|gd|gddgddgg	¡}| jdkrö|dd…ddd…f }| j	 
|¡ | jsdS t| ddƒ}t|tjƒrFtdd	„ |jD ƒƒrF|j}	ndg}	|  ¡ rB| js|t ddgd|gddgg¡}
n"t ddgd|gd
|gddgg¡}
| jdkrÀ|
dd…ddd…f }
|  ¡  ¡ rÒdnd}|  |  | j| ¡¡}tjt |
¡|| jdd| jj|	d dt | jjj tj! ¡d	}| j "|¡ | j  #|¡ |  ¡ r8| jsrt ddgd|gddgg¡}
n"t ddgd|gd|gddgg¡}
| jdkr¶|
dd…ddd…f }
|  ¡  ¡ rÈdnd}|  |  | j| ¡¡}tjt |
¡|| jdd| jj|	d dt | jjj tj! ¡d	}| j "|¡ | j  #|¡ |  $¡  dS )z™
        Add the extend tri/rectangles on the outside of the axes.

        ax is unused, but required due to the callbacks on xlim/ylim changed
        r   r>   g      à?rn   Nru   rƒ   c             s   s   | ]}|d k	V  qd S )Nr   )rÌ   rÍ   r   r   r   rÎ   È  s    z'Colorbar._do_extends.<locals>.<genexpr>g      ð?F)rÝ   r_   r{   rÞ   Ú	transformrÍ   r~   r|   )%r“   rÑ   rD   rE   rF   ri   r'   rà   rI   ry   r3   rg   rV   r„   r   r…   rÒ   rÓ   rº   rÂ   r]   r^   rÅ   r)   rá   r%   r&   r_   r9   r+   Z	nextafterrå   r|   Úinfrâ   rÚ   r×   )r   r9   rå   Ú_rP   Zbotrq   Zxyoutrƒ   rÓ   r2   Úvalrz   r   r   r   r®   ¡  sl     

"
"zColorbar._do_extendsc             O   sv  t jddd„ddd„g| f|ž|Ž}d|kr€| ¡ \} }}t|tjƒrL|jrTtdƒ‚| j|j	dd„ |j
D ƒd	d„ |jD ƒ|d
S | ¡ \} }}}}|  |¡}	| jd | jd  d }
|	| jd |
 k |	| jd |
 k@ }|	| }	t |¡røt |¡| }t |¡rt |¡| }t ddg|	¡\}}| jdkrFtj||gdd}ntj||gdd}tj|||d}|r–| jr–x| jD ]}| ¡  q~W g | _| j |¡ t |¡d }t ddgddgddgddgddgg¡}| j ¡ j}| ¡  | jj  |¡¡}|dddgdf  |8  < |ddgdf  |7  < | jj  ¡  | |¡¡}| !t"j#|dd| jj ¡ | j $|¡ d| _%dS )aI  
        Draw lines on the colorbar.

        The lines are appended to the list :attr:`lines`.

        Parameters
        ----------
        levels : array-like
            The positions of the lines.
        colors : color or list of colors
            Either a single color applying to all lines or one color value for
            each line.
        linewidths : float or array-like
            Either a single linewidth applying to all lines or one linewidth
            for each line.
        erase : bool, default: True
            Whether to remove any previously added lines.

        Notes
        -----
        Alternatively, this method can also be called with the signature
        ``colorbar.add_lines(contour_set, erase=True)``, in which case
        *levels*, *colors*, and *linewidths* are taken from *contour_set*.
        Tc             S   s   t ƒ S )N)Úlocals)r   r·   Úeraser   r   r   r     r   z$Colorbar.add_lines.<locals>.<lambda>c             S   s   t ƒ S )N)rê   )r   rˆ   r   r}   rë   r   r   r   r     r   r·   zKIf a single artist is passed to add_lines, it must be a ContourSet of linesc             S   s   g | ]}|d  ‘qS )r   r   )rÌ   Úcr   r   r   ú
<listcomp>   s    z&Colorbar.add_lines.<locals>.<listcomp>c             S   s   g | ]}|d  ‘qS )r   r   )rÌ   Útr   r   r   rí   !  s    )rë   ru   r   g»½×Ùß|Û=r>   rA   )Úaxis)r}   r   éH   é   r!   é   )r"   N)T)T)&r   Zselect_matching_signaturer`   r„   r   r…   rg   Ú
ValueErrorr§   rˆ   ZtcolorsZtlinewidthsÚ_locaterÕ   r'   r¤   ÚasarrayrÛ   rI   Ústackr   r›   r–   rÑ   rÚ   rx   rà   r9   Ú
get_figureZdpi_scale_transÚinvertedræ   r+   Zset_clip_pathr%   r&   r   r1   )r   r   Úkwargsr   r·   rë   rˆ   r   r}   rO   ZrtolZigoodrÇ   rÈ   r2   ÚcolÚlcZfacZinchesr   r   r   r§   û  sX    

$
(
zColorbar.add_linesc             C   s<   |   ¡  |  ¡  | j¡ |  ¡  | j¡ |  ¡  | j¡ dS )zU
        Setup the ticks and ticklabels. This should not be needed by users.
        N)Ú_get_ticker_locator_formatterrº   Úset_major_locatorrž   Úset_minor_locatorrŸ   Zset_major_formatterr    )r   r   r   r   rÃ   K  s    zColorbar.update_ticksc             C   s  | j }| j}| j}t| jtjƒr@| jj}|dkrÖtj	|dd}n–t| jtj
ƒr€|dkrÖt| jƒ}dt|d ƒ }tj|dd}nV| jdk	r®| j| j }|dkrÖtj	|dd}n(|dkrÂ|  ¡  ¡ }|dkrÖ|  ¡  ¡ }|dkræt ¡ }|dkrú|  ¡  ¡ }|| _ || _|| _t d|¡ dS )a(  
        Return the ``locator`` and ``formatter`` of the colorbar.

        If they have not been defined (i.e. are *None*), the formatter and
        locator are retrieved from the axis, or from the value of the
        boundaries for a boundary norm.

        Called by update_ticks...
        Nrk   )rl   r>   g      à?)ÚbaserS   zlocator: %r)rž   r    rŸ   r„   r^   r   r¨   ra   r   r‡   r©   rQ   rÅ   ÚintZIndexLocatorr¾   r’   rº   Úget_major_locatorÚget_minor_locatorÚNullLocatorZget_major_formatterrµ   r¶   )r   rž   r    rŸ   ÚbÚnvrÿ   r   r   r   rü   U  s8    


z&Colorbar._get_ticker_locator_formatterrÃ   )r¸   c            K   sV   t  |¡r6|  ¡ j|f||dœ|—Ž |  ¡  ¡ | _n|| _|  ¡  | j¡ d| _dS )a  
        Set tick locations.

        Parameters
        ----------
        ticks : list of floats
            List of tick locations.
        labels : list of str, optional
            List of tick labels. If not set, the labels show the data value.
        minor : bool, default: False
            If ``False``, set the major ticks; if ``True``, the minor ticks.
        **kwargs
            `.Text` properties for the labels. These take effect only if you
            pass *labels*. In other cases, please use `~.Axes.tick_params`.
        )Úlabelsr¸   TN)r'   r¤   rº   r¼   r  rž   rý   r1   )r   rd   rÃ   r  r¸   rù   r   r   r   r¼   ƒ  s    
zColorbar.set_ticksc             C   s    |r|   ¡  ¡ S |   ¡  ¡ S dS )zµ
        Return the ticks as a list of locations.

        Parameters
        ----------
        minor : boolean, default: False
            if True return the minor ticks.
        N)rº   Zget_minorticklocsZget_majorticklocs)r   r¸   r   r   r   Ú	get_ticksž  s    	zColorbar.get_ticksc            K   s   |   ¡ j|fd|i|—Ž dS )a•  
        Set tick labels.

        .. admonition:: Discouraged

            The use of this method is discouraged, because of the dependency
            on tick positions. In most cases, you'll want to use
            ``set_ticks(positions, labels=labels)`` instead.

            If you are using this method, you should always fix the tick
            positions before, e.g. by using `.Colorbar.set_ticks` or by
            explicitly setting a `~.ticker.FixedLocator` on the long axis
            of the colorbar. Otherwise, ticks are free to move and the
            labels may end up in unexpected positions.

        Parameters
        ----------
        ticklabels : sequence of str or of `.Text`
            Texts for labeling each tick location in the sequence set by
            `.Colorbar.set_ticks`; the number of labels must match the number
            of locations.

        update_ticks : bool, default: True
            This keyword argument is ignored and will be be removed.
            Deprecated

         minor : bool
            If True, set minor ticks instead of major ticks.

        **kwargs
            `.Text` properties for the labels.
        r¸   N)rº   Úset_ticklabels)r   Ú
ticklabelsrÃ   r¸   rù   r   r   r   r  ¬  s    #zColorbar.set_ticklabelsc             C   s.   | j  ¡  |  ¡  ¡ | _|  ¡  t ¡ ¡ dS )z/
        Turn on colorbar minor ticks.
        N)	r9   r¹   rº   r  rŸ   r˜   rþ   r   r  )r   r   r   r   r¹   Ñ  s    
zColorbar.minorticks_onc             C   s   t  ¡ | _|  ¡  | j¡ dS )z)Turn the minor ticks of the colorbar off.N)r   r  rŸ   rº   rþ   )r   r   r   r   Úminorticks_offÙ  s    
zColorbar.minorticks_off)Úlocc            K   sF   | j dkr$| jj|fd|i|—Ž n| jj|fd|i|—Ž d| _dS )a¤  
        Add a label to the long axis of the colorbar.

        Parameters
        ----------
        label : str
            The label text.
        loc : str, optional
            The location of the label.

            - For horizontal orientation one of {'left', 'center', 'right'}
            - For vertical orientation one of {'bottom', 'center', 'top'}

            Defaults to :rc:`xaxis.labellocation` or :rc:`yaxis.labellocation`
            depending on the orientation.
        **kwargs
            Keyword arguments are passed to `~.Axes.set_xlabel` /
            `~.Axes.set_ylabel`.
            Supported keywords are *labelpad* and `.Text` properties.
        rA   r  TN)rI   r9   Z
set_ylabelZ
set_xlabelr1   )r   rj   r  rù   r   r   r   r¢   Þ  s    
zColorbar.set_labelc             C   s   t |tjƒrdn|| _dS )zÑ
        Set the transparency between 0 (transparent) and 1 (opaque).

        If an array is provided, *alpha* will be set to None to use the
        transparency values associated with the colormap.
        N)r„   r'   Úndarrayr_   )r   r_   r   r   r   r   ù  s    zColorbar.set_alphac             K   sL   | j dkr| jj|f|Ž n| jj|f|Ž t|tjƒrB|j| _n|| _dS )aC  
        Set the colorbar long axis scale.

        Parameters
        ----------
        value : {"linear", "log", "symlog", "logit", ...} or `.ScaleBase`
            The axis scale type to apply.

        **kwargs
            Different keyword arguments are accepted, depending on the scale.
            See the respective class keyword arguments:

            - `matplotlib.scale.LinearScale`
            - `matplotlib.scale.LogScale`
            - `matplotlib.scale.SymmetricalLogScale`
            - `matplotlib.scale.LogitScale`
            - `matplotlib.scale.FuncScale`

        Notes
        -----
        By default, Matplotlib supports the above mentioned scales.
        Additionally, custom scales may be registered using
        `matplotlib.scale.register_scale`. These scales can then also
        be used here.
        rA   N)	rI   r9   Z
set_yscaleZ
set_xscaler„   ÚmscaleZ	ScaleBaseÚnamer¡   )r   Úscalerù   r   r   r   Ú
_set_scale  s    

zColorbar._set_scalec             C   s   t | jdƒr@| jjd }x&|D ]}| j|jkr|j | j¡ qW | j ¡  | jj | jj¡ d| j_	d| j_| jj | j
¡ | jj | j¡ y| jj}W n tk
r¬   dS X y| ¡  ¡ }| ¡ }W n* tk
rð   |jdd}| |¡ Y nX | |¡ dS )z¢
        Remove this colorbar from the figure.

        If the colorbar was created with ``use_gridspec=True`` the previous
        gridspec is restored.
        r?   ÚparentsNT)r<   )rH   r9   r?   Ú
_colorbarsrÑ   rƒ   rŠ   Z
disconnectr   r    r¯   r°   r,   ÚAttributeErrorrU   Zget_gridspecZget_topmost_subplotspecrB   Ú_set_positionÚset_subplotspec)r   r  Úar9   ÚgsZsubplotspecrN   r   r   r   rÑ   %  s,    

zColorbar.removec       	      C   s  t | jtjƒr.| jdkr.| jd | jd f}n| j| jf}|j|d d |j	j
|Ž  |j	j|Ž  | |j	¡ t |ƒ ¡}t |tjƒr¸d}|||d d|  k||d d|  k@  }n8|d |d  d }|||d | k||d | k@  }|  |¡}| |¡}| ¡ }|||fS )zŒ
        Return the sequence of ticks (colorbar data locations),
        ticklabels (strings), and the corresponding offset string.
        Nr   ru   )Zminposg»½×Ùß|Û=r>   )r„   r^   r   r©   ra   rÅ   r¿   rÀ   Zcreate_dummy_axisrï   Zset_view_intervalZset_data_intervalZset_axisr'   rà   r   Z
LogLocatorrô   Zformat_ticksZ
get_offset)	r   rž   r    Zintvr  Úepsrd   r	  Zoffset_stringr   r   r   Ú_tickerJ  s"    .$

zColorbar._tickerc             C   s  | j dk	rªt | j ¡| _| jdkr˜t t| j ƒd ¡}d| jdd… | jdd…   |dd…< d|d  |d  |d< d|d  |d	  |d< || _dS t | j¡| _dS t| j	t
jƒrÂ| j	j}nRt| j	t
jƒrèt | jjd ¡d }n,| jdk	rú| j}n| jjd }|  |¡\}}|  ¡ r4t |d d |f¡}|  ¡ rTt ||d d f¡}| j	 ¡ spd| j	_d| j	_tj| j	j| j	jd
d\| j	_| j	_t| j	t
jƒs¼| jdkr¼| j	 |¡}tj|td| _d| jdd… | jdd…   | _t| j	t
jƒr| jd  tj¡| _dS )z¿
        Set `_boundaries` and `_values` based on the self.boundaries and
        self.values if not None, or based on the size of the colormap and
        the vmin/vmax of the norm.
        Nr>   g      à?ru   g       @r!   r   éþÿÿÿéýÿÿÿgš™™™™™¹?)Zexpander)Zdtypegñhãˆµøä>)r`   r'   rà   rÅ   ra   ZzerosrQ   r¾   r„   r^   r   r¨   r©   rÄ   r]   ÚNÚ
_uniform_yrE   ZhstackrF   Zscaledr¿   rÀ   ÚmtransformsZnonsingularÚinverserõ   ÚfloatZastypeZint16)r   r  r  rè   r   r   r   r½   d  sF    

(



 "zColorbar._process_valuesc             C   sž   t  | j¡}| j|_| j|_|  ¡ \}}t|tjtj	fƒsD| j
dk	r\|| j| j  | j }n
| |¡}|| _t ddg|¡\}}| jdkr’||fS ||fS dS )zµ
        Return the coordinate arrays for the colorbar pcolormesh/patches.

        These are scaled between vmin and vmax, and already handle colorbar
        orientation.
        Ng        g      ð?rA   )ÚcopyÚdeepcopyr^   r¿   rÀ   rD   r„   r   r¨   r©   ra   r  rÕ   r'   rÛ   rI   )r   r^   rO   rè   rÇ   rÈ   r   r   r   rÁ   ™  s    


zColorbar._meshc          
   C   sb   | j }t ||t ddt|ƒ¡¡}|d |d  d }d|||d | k < d|||d | k< |S )Nr   r>   ru   gíµ ÷Æ°>r!   )r¾   r'   ÚinterpÚlinspacerQ   )r   r²   r  rO   r  r   r   r   Ú_forward_boundaries¹  s    zColorbar._forward_boundariesc          	   C   s"   | j }t |t ddt|ƒ¡|¡S )Nr   r>   )r¾   r'   r#  r$  rQ   )r   r²   r  r   r   r   Ú_inverse_boundariesÅ  s    zColorbar._inverse_boundariesc             C   sÈ   |   ¡  d| _d| _d| _| jdk	s2t| jtjƒrn| j	dkrX| j
| jf}| jd|d qÄ| j	dkrÄ|  d¡ nVt| jddƒrŒ|  | jj¡ n8t| jƒtjkr¨|  d¡ n| j| jjf}| jd|d dS )zß
        Reset the locator et al to defaults.  Any user-hardcoded changes
        need to be re-entered if this gets called (either at init, or when
        the mappable normal gets changed: Colorbar.update_normal)
        Nr\   Úfunction)Z	functionsrs   ZlinearÚ_scale)r½   rž   rŸ   r    ra   r„   r^   r   r¨   rc   r%  r&  r  rV   r(  ÚtypeÚ	Normalizer  )r   Úfuncsr   r   r   r£   Ê  s"    


z'Colorbar._reset_locator_formatter_scalec             C   sh   t | jtjtjfƒr | j}|}n&| j| jdd ¡ }| j|dd ¡ }|| j }| j}t	 
|||¡}|S )zq
        Given a set of color data values, return their
        corresponding colorbar data coordinates.
        F)Zclip)r„   r^   r   r©   r¨   r¾   rg   r’   rÕ   r'   r#  )r   r²   r  ZxnZbuniqueZyuniqueÚzr   r   r   rô   ç  s    
zColorbar._locatec             C   s:   d|d   }}| j | j||dd}t dd|¡}||fS )zƒ
        Return colorbar data coordinates for *N* uniformly
        spaced boundaries, plus extension lengths if required.
        g      ð?gš™™™™™©?)Údefaultr   r>   )Ú_get_extension_lengthsrh   r'   r$  )r   r  ÚautominÚautomaxÚextendlengthrO   r   r   r   r  ý  s    zColorbar._uniform_yc             C   sP  t | jtjƒs| jdk	rp| j| j| j d  }|| j| j d | j| j d   }| jdkrj|  | j¡}q”|}n$|  | j 	¡ ¡}t
j |t
j¡}|}|| j }|| j }t |d |d ¡}t
j ||ƒt
j¡}t |d |d ¡}t
j ||ƒt
j¡}|d |d  }|d |d  }ddg}|  ¡ s4|  ¡ rH| j| j||dd}||fS )	z
        Return colorbar data coordinates for the boundaries of
        a proportional colorbar, plus extension lengths if required:
        Nr   ru   r\   r>   r  gš™™™™™©?)r-  )r„   r^   r   r¨   ra   r¾   r’   rc   r%  r!  r'   Úmarg   Únanr*  rE   rF   r.  rh   )r   rO   Zyscaledr^   r/  r0  r1  r   r   r   rD   	  s0    



zColorbar._proportional_yçš™™™™™©?c          
   C   s    t  ||g¡}t|tƒr>tjdg| ¡ d ||g|dd…< n^|dk	rœy$||dd…< t  |¡ ¡ rht	ƒ ‚W n0 t
t	fk
rš } zt	dƒ|‚W dd}~X Y nX |S )z
        Return the lengths of colorbar extensions.

        This is a helper method for _uniform_y and _proportional_y.
        r[   )rh   Nzinvalid value for extendfrac)r'   rà   r„   r¥   r   rŽ   rÉ   ÚisnanrÒ   ró   Ú	TypeError)r   Úfracr/  r0  r-  r1  Úerrr   r   r   r.  /  s    

zColorbar._get_extension_lengthsc             C   s"   |   ¡  ¡ rdnd}| jd|fkS )z-Return whether the lower limit is open ended.rx   rw   rv   )rº   rÂ   rC   )r   Úminmaxr   r   r   rE   H  s    zColorbar._extend_lowerc             C   s"   |   ¡  ¡ rdnd}| jd|fkS )z-Return whether the upper limit is open ended.rw   rx   rv   )rº   rÂ   rC   )r   r9  r   r   r   rF   M  s    zColorbar._extend_upperc             C   s   | j dkr| jjS | jjS )zReturn the long axisrA   )rI   r9   ÚyaxisÚxaxis)r   r   r   r   rº   R  s    
zColorbar._long_axisc             C   s   | j dkr| jjS | jjS )zReturn the short axisrA   )rI   r9   r;  r:  )r   r   r   r   r˜   X  s    
zColorbar._short_axisc             C   s   | j j| j jfS )N)r^   r¿   rÀ   )r   r   r   r   r   ^  s    zColorbar._get_viewc             C   s   |\| j _| j _d S )N)r^   r¿   rÀ   )r   Úviewr   r   r   r€   c  s    zColorbar._set_viewÚinc             C   sT   | j j|||||d\}}| jdkr6|\| j_| j_n| jdkrP|\| j_| j_d S )N)Ú	directionÚmodeÚtwinxÚtwinyrn   rA   )r9   Z_prepare_view_from_bboxrI   r^   r¿   rÀ   )r   Zbboxr>  r?  r@  rA  Z
new_xboundZ
new_yboundr   r   r   r   h  s    

zColorbar._set_view_from_bboxc             C   sl   | j  ||||¡}|d k	rh| jdkrB|d d …df \| j_| j_n&| jdkrh|d d …df \| j_| j_d S )Nrn   r   rA   r>   )r9   Z_get_pan_pointsrI   r^   r¿   rÀ   )r   ZbuttonÚkeyr²   rO   Zpointsr   r   r   r‚   s  s    

zColorbar.drag_pan)N)N)TN)F)T)r4  )r=  NFF)/r   r   r   rX   rÖ   r$   r¬   r   Zdeprecate_privatize_attributerå   rŒ   r¦   rÆ   r×   rÔ   r®   r§   rÃ   rü   Zdelete_parameterr¼   r  r  r¹   r
  r¢   r   r  rÑ   r  r½   rÁ   r%  r&  r£   rô   r  rD   r.  rE   rF   rº   r˜   r   r€   r   r‚   r   r   r   r   rY   !  sz   L 		4
ZP
.


$	#%5 &
 

rY   c          
   C   s†   | d krt jddddœ|d} t jddddd	d
œdddddd
œdddddd
œdddddd
œdœ| d}|d k	r‚||d kr‚tdƒ‚|S )Nrp   rr   )NrA   rn   )rI   ro   rA   )g      ð?g      à?)g        g      à?gš™™™™™¹?)ÚlocationrI   ÚanchorÚpanchorÚpadgš™™™™™©?rq   rn   )g      à?g        )g      à?g      ð?g333333Ã?)ro   rp   rq   rr   )rC  rI   z/location and orientation are mutually exclusive)r   r   r6  )rC  rI   Úloc_settingsr   r   r   Ú_normalize_location_orientation€  s"    



rH  ç333333Ã?ç      ð?é   c          
      sV  t ||ƒ}|d |d< |d  }|d< | d|d ¡}| d|d ¡}	|}
t| tjƒrbt| jƒ} nt| tƒsr| g} | d  ¡ ‰ ˆ  ¡ rŠdn|d }| d|¡}t	‡ fd	d
„| D ƒƒs¼t
dƒ‚tj dd„ | D ƒ¡}|}|dkr6|dkr| ||| ¡\}}}n| d| | d| ¡\}}}| d|¡ ||¡}n\|dkrX| ||| ¡\}}}n| d| | d| ¡\}}}| |d¡ ||¡}d| }t ||¡}xH| D ]@}| |jdd¡}t |¡}| |¡ |	dk	r¤| |	¡ q¤W ˆ j|dd}x| D ]}| j|g7  _qüW t| ||||	||
|d|_| |¡ | |¡ | d¡ ||fS )a&  
    Create an `~.axes.Axes` suitable for a colorbar.

    The axes is placed in the figure of the *parents* axes, by resizing and
    repositioning *parents*.

    Parameters
    ----------
    parents : `~.axes.Axes` or list of `~.axes.Axes`
        The Axes to use as parents for placing the colorbar.
    %s

    Returns
    -------
    cax : `~.axes.Axes`
        The child axes.
    kw : dict
        The reduced keyword dictionary to be passed when creating the colorbar
        instance.

    Other Parameters
    ----------------
    %s
    rI   rC  rb   rD  rE  r   gš™™™™™©?rF  c             3   s   | ]}ˆ |  ¡ kV  qd S )N)r÷   )rÌ   r9   )Úfigr   r   rÎ   Å  s    zmake_axes.<locals>.<genexpr>zJUnable to create a colorbar axes as not all parents share the same figure.c             S   s   g | ]}|j d d ¡ ‘qS )T)r<   )rB   Úfrozen)rÌ   r9   r   r   r   rí   Ë  s    zmake_axes.<locals>.<listcomp>)ro   rp   ro   r>   g      ð?rr   T)r<   Fz
<colorbar>)rj   )r  rC  rR   rD  rE  Úfractionr@   rF  r[   )rH  Úpopr„   r'   r  ÚlistrÐ   r÷   Zget_constrained_layoutÚallró   r  ZBboxÚunionZsplitxrK   ZanchoredZsplityZBboxTransformræ   rB   r  Ú
set_anchorZadd_axesr  Údictr?   rJ   Ú
set_aspect)r  rC  rI   rN  rR   r@   r   rG  rD  rE  Úaspect0Zpad0rF  Zparents_bboxZpbZpbcbrè   Zpb1Zshrinking_transr9   Znew_posnÚcaxr  r   )rL  r   Ú	make_axes•  sf    













rX  )rC  rI   rN  rR   r@   c         
   K   sn  t ||ƒ}|d |d< |d  }|d< |}| d|d ¡}	| d|d ¡}
| d|d ¡}d| d|  }|d	kr.d|	d  d|  ||	d d|  g}|d
krè|  ¡ jdd||d| | gd}|d }|d jddd|dd }nD|  ¡ jdd|d| | |gd}|d }|d jddd|dd }nÊ|	d d|  |d|	d  d|  g}|dkr¬|  ¡ jdd|d| | |gd}|d }|d jddd|dd }d| }nL|  ¡ jdd||d| | gd}|d }|d jddd|dd }d| }|  |¡ |
dk	r|  |
¡ |  ¡ }|j|dd}| |	¡ | |¡ | 	d¡ t
|| g||	|
|||d|_||fS )a  
    Create a `.SubplotBase` suitable for a colorbar.

    The axes is placed in the figure of the *parent* axes, by resizing and
    repositioning *parent*.

    This function is similar to `.make_axes`. Primary differences are

    - `.make_axes_gridspec` should only be used with a `.SubplotBase` parent.

    - `.make_axes` creates an `~.axes.Axes`; `.make_axes_gridspec` creates a
      `.SubplotBase`.

    - `.make_axes` updates the position of the parent.  `.make_axes_gridspec`
      replaces the ``grid_spec`` attribute of the parent with a new one.

    While this function is meant to be compatible with `.make_axes`,
    there could be some minor differences.

    Parameters
    ----------
    parent : `~.axes.Axes`
        The Axes to use as parent for placing the colorbar.
    %s

    Returns
    -------
    cax : `~.axes.SubplotBase`
        The child axes.
    kw : dict
        The reduced keyword dictionary to be passed when creating the colorbar
        instance.

    Other Parameters
    ----------------
    %s
    rI   rC  rb   rD  rE  rF  r!   r>   )ro   rp   ro   )ZwspaceÚwidth_ratiosr   rò   )ZhspaceÚheight_ratiosrr   Fz
<colorbar>)rj   r[   )rC  r  rR   rD  rE  rN  r@   rF  )rH  rO  rU   Zsubgridspecr  rS  r÷   Zadd_subplotrJ   rU  rT  r?   )ÚparentrC  rI   rN  rR   r@   r   rG  rV  rD  rE  rF  Zwh_spacerZ  r  Zss_mainZss_cbrY  rL  rW  r   r   r   Úmake_axes_gridspecÿ  sr    )

&&








r\  z3.4)r´   c               @   s   e Zd ZdS )ÚColorbarPatchN)r   r   r   r   r   r   r   r]  p  s   r]  c             K   s   t | |f|ŽS )aÈ  
    Create a colorbar on the given axes for the given mappable.

    .. note::
        This is a low-level function to turn an existing axes into a colorbar
        axes.  Typically, you'll want to use `~.Figure.colorbar` instead, which
        automatically handles creation and placement of a suitable axes as
        well.

    Parameters
    ----------
    cax : `~matplotlib.axes.Axes`
        The `~.axes.Axes` to turn into a colorbar.
    mappable : `~matplotlib.cm.ScalarMappable`
        The mappable to be described by the colorbar.
    **kwargs
        Keyword arguments are passed to the respective colorbar class.

    Returns
    -------
    `.Colorbar`
        The created colorbar instance.
    )rY   )rW  rƒ   rù   r   r   r   Úcolorbar_factoryu  s    r^  )NNrI  rJ  rK  )9rX   r!  ÚloggingÚtextwrapÚnumpyr'   Z
matplotlibr™   r   r   r   r   r   r   Zmatplotlib.artistZartistr‰   Zmatplotlib.patchesrã   r)   Zmatplotlib.pathÚpathr%   Zmatplotlib.scaler  r  Zmatplotlib.spinesr—   ZmspinesZmatplotlib.transformsZ
transformsr  r   Ú	getLoggerr   rµ   r   r   r   r   ÚupdateÚindentZcaching_module_getattrr
   r   ZSpiner   r7   rY   ZColorbarBaserH  ZSubstitutionrX  r\  r   r]  r^  r   r   r   r   Ú<module>   sZ    
?B

4        d
 h
o