
    h'                       S r SSKJr  SSKrSSKrSSKJr  SSKrSSKJ	r	  SSK
rSSK
JrJr  SSKJr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  SSK J!r!  SSK"J#r#  SSK$J%r&  SSK'J(r)  S r* " S S5      r+S r,\RZ                  R]                  SS9  \RZ                   " S S\+\R^                  5      5       r0\RZ                   " S S\05      5       r1\RZ                  R]                  S\RZ                  Rd                  -  S9  g)zG
Classes to support contour plotting and labelling for the Axes class.
    )	ExitStackN)Integral)ma)_api
_docstring)MouseButton)Line2D)Path)Textc                    U R                   R                  SS9R                  nUR                  S:H  nUR                  S:H  nU(       a  UR                  [
        R                  :X  d  U(       a!  UR                  S;   a  UR                  5         g U(       a  UR                  [
        R                  :X  d  U(       a9  UR                  S;   a)  U(       d!  U R                  5         UR                  5         g g U(       a  UR                  [
        R                  :X  d  U(       ai  UR                  b[  U R                   R                  U5      S   (       a7  U R                  UR                  UR                   SXS	9  UR                  5         g g g g )
NTrootbutton_press_eventkey_press_event)escapeenter)	backspacedeleter   F)	transforminlineinline_spacing)axes
get_figurecanvasnamebuttonr   MIDDLEkeystop_event_loopRIGHT	pop_labeldrawLEFTcontainsadd_label_nearxy)csr   r   eventr   	is_buttonis_keys          D/var/www/html/env/lib/python3.13/site-packages/matplotlib/contour.py_contour_labeler_event_handlerr-      s    WWT*11F

22IZZ,,F 	ellk&8&88%))':: 
(9(99		%<< LLNKKM  (8(88		-77E"1%egguww%%+  LKKM & .V    c                      ^  \ rS rSrSrSSSSSSSSSSS.	S jjrS	 rS
 rS rS r	S r
SS jrS r  SS jrSS jrS rU 4S jrSrU =r$ )ContourLabeler:   z7Mixin to provide labelling capability to `.ContourSet`.NT   F)	fontsizer   r   fmtcolorsuse_clabeltextmanualrightside_upzorderc       	            Uc$  [         R                  " SS9nUR                  5         XPl        Xpl        Xl        Xl        U
c  SU R                  5       -   OU
U l        Uc4  U R                  n[        [        [        U R                  5      5      5      nO[        U5      n/ / p[        U R                  5       H.  u  pX;   d  M  UR                  U5        UR                  U5        M0     [        U5      [        U5      :  a  [!        SU SU R                   35      eXl        Xl        [&        R(                  " US9U l        Uc7  X l        [.        R0                  " U R                  U R$                  5      U l        O[4        R6                  " U[        U R"                  5      S9n[        [        [        U R"                  5      5      5      U l        [8        R:                  " U[4        R<                  " 5       S9U l        / U l        [.        R@                  " U5      (       a   U H  u  nnU RC                  UUX45        M     OU(       a|  [E        S	5        [E        S
5        U(       d  [E        S5        [F        RH                  RK                  U RL                  RO                  SS9SS/S[P        RR                  " [T        XU5      S9  OU RW                  X45        [X        RZ                  " SU R\                  5      $ )a  
Label a contour plot.

Adds labels to line contours in this `.ContourSet` (which inherits from
this mixin class).

Parameters
----------
levels : array-like, optional
    A list of level values, that should be labeled. The list must be
    a subset of ``cs.levels``. If not given, all levels are labeled.

fontsize : str or float, default: :rc:`font.size`
    Size in points or relative size e.g., 'smaller', 'x-large'.
    See `.Text.set_size` for accepted string values.

colors : :mpltype:`color` or colors or None, default: None
    The label colors:

    - If *None*, the color of each label matches the color of
      the corresponding contour.

    - If one string color, e.g., *colors* = 'r' or *colors* =
      'red', all labels will be plotted in this color.

    - If a tuple of colors (string, float, RGB, etc), different labels
      will be plotted in different colors in the order specified.

inline : bool, default: True
    If ``True`` the underlying contour is removed where the label is
    placed.

inline_spacing : float, default: 5
    Space in pixels to leave on each side of label when placing inline.

    This spacing will be exact for labels at locations where the
    contour is straight, less so for labels on curved contours.

fmt : `.Formatter` or str or callable or dict, optional
    How the levels are formatted:

    - If a `.Formatter`, it is used to format all levels at once, using
      its `.Formatter.format_ticks` method.
    - If a str, it is interpreted as a %-style format string.
    - If a callable, it is called with one level at a time and should
      return the corresponding label.
    - If a dict, it should directly map levels to labels.

    The default is to use a standard `.ScalarFormatter`.

manual : bool or iterable, default: False
    If ``True``, contour labels will be placed manually using
    mouse clicks. Click the first button near a contour to
    add a label, click the second button (or potentially both
    mouse buttons at once) to finish adding labels. The third
    button can be used to remove the last label added, but
    only if labels are not inline. Alternatively, the keyboard
    can be used to select label locations (enter to end label
    placement, delete or backspace act like the third mouse button,
    and any other key will select a label location).

    *manual* can also be an iterable object of (x, y) tuples.
    Contour labels will be created as if mouse is clicked at each
    (x, y) position.

rightside_up : bool, default: True
    If ``True``, label rotations will always be plus
    or minus 90 degrees from level.

use_clabeltext : bool, default: False
    If ``True``, use `.Text.set_transform_rotates_text` to ensure that
    label rotation is updated whenever the Axes aspect changes.

zorder : float or None, default: ``(2 + contour.get_zorder())``
    zorder of the contour labels.

Returns
-------
labels
    A list of `.Text` instances for the labels.
F)	useOffset   zSpecified levels z don't match available levels )sizeN)cmapnormz9Select label locations manually using first mouse button.z.End manual selection with second mouse button.z1Remove last label by clicking third mouse button.Tr   r   r   )timeouthandlerz	text.Text)/tickerScalarFormattercreate_dummy_axislabelFmt_use_clabeltextlabelManualr8   
get_zorder_clabel_zorderlevelslistrangelencvalues	enumerateappend
ValueErrorlabelLevelListlabelIndiceListfont_managerFontProperties_label_font_propslabelMappablenptakelabelCValueListmcolorsListedColormapcmScalarMappableNoNormlabelXYsiterabler%   printmpl_blocking_inputblocking_input_loopr   r   	functoolspartialr-   labelscbooksilent_list
labelTexts)selfrM   r3   r   r   r4   r5   r6   r7   r8   r9   indiceslevlabsilevr@   r&   r'   s                     r,   clabelContourLabeler.clabel=   si   | ;((59C!!#-!(7=~a$//"336>[[F5T\\!234G6lG "V#DKK0>NN1%MM#& 1 6{S\) #4WI >559[[M"C D D$&!-!<!<(!K>!%#%774<<9M9M#ND ))&C8K8K4LMD#'c$2E2E.F(G#HD !#!2!28?8H"JD ;;v1##Aq&A MNBCIJ33		$$$$/%'89I$5$52.%2 4 3 KK/  doo>>r.   c                     [        U5      SU-  :  =(       d;    [        U5      =(       a)    [        R                  " USS9SU-  :  R                  5       $ )z8Return whether a contour is long enough to hold a label.
   r   axis333333?)rP   r[   ptpany)ro   linecontour
labelwidths      r,   print_labelContourLabeler.print_label   sN    K 2
?2 P$ O!4sZ7GGLLN	Qr.   c                 Z   ^^^ SU-  S-  m[        UUU4S jU R                   5       5      $ )z5Return whether a label is already near this location.rz   r<   c              3   X   >#    U  H  nTUS    -
  S-  TUS   -
  S-  -   T:  v   M!     g7f)r   r<      N ).0locthreshr&   r'   s     r,   	<genexpr>+ContourLabeler.too_close.<locals>.<genexpr>   s<      -+s AJ1$CF
q'886A+s   '*)r|   rc   )ro   r&   r'   lwr   s    `` @r,   	too_closeContourLabeler.too_close   s.    (q -"mm- - 	-r.   c                    U R                   R                  SS9nUR                  SS9R                  5       n[        SSU R	                  U R
                  U   U R                  5      X R                  S9R                  U5      R                  $ )z/Return the width of the *nth* label, in pixels.Fr   Tr   )figurefontproperties)
r   r   _get_rendererr   get_textrU   rH   rY   get_window_extentwidth)ro   nthfigrenderers       r,   _get_nth_label_width#ContourLabeler._get_nth_label_width   s{    ii""".>>t>,::<Q]]4#6#6s#;T]]K0F0FH #"8,UU	4r.   c                 0   [        U[        5      (       a  U$ [        U[        5      (       a  UR                  US5      $ [	        [        USS5      5      (       a"  UR                  / U R                  QUP5      S   $ [	        U5      (       a  U" U5      $ X!-  $ )zGet the text of the label.z%1.3fformat_ticksNrB   )
isinstancestrdictgetcallablegetattrr   rU   )ro   rs   r4   s      r,   r   ContourLabeler.get_text   s    c3JT""773((gc>4899##$?d&9&9$?3$?@DDc]]s8O9r.   c                 8   [        U5      nUS:  a!  [        [        R                  " X2-  5      5      OSnUS:X  a  UO
[        U5      n[        R                  " USS2S4   XE45      n[        R                  " USS2S4   XE45      nUSS2SS24   nUSS2SS24   n	USS2SS24   n
USS2SS24   nX-
  X-
  -  X-
  X-
  -  -
  n[        R
                  " X-
  X-
  5      n[        R                  " SSS9   [        U5      U-  R                  SS9nSSS5        US-  n[        R                  " W5      n[        R                  " UUS   5       H+  nUUU4   UUU4   nnU R                  UUU5      (       a  M+    O   WWWU-  U-   U-  4$ ! , (       d  f       N= f)	zH
Find good place to draw a label (relatively flat part of the contour).
r   Nr   rB   ignore)divideinvalidrx   r<   )rP   intr[   ceilresizehypoterrstateabssumargsortrS   r   )ro   r}   r~   ctr_sizen_blocks
block_sizexxyyyfirstylastxfirstxlastsl	distanceshbsizeadistidxr&   r'   s                       r,   locate_labelContourLabeler.locate_label   s    {#:Dq.3rwwx456a!)QXC
O
 YY{1a4(8*@AYY{1a4(8*@AArrE1bc6
ArrE1bc6
[U^,/OOHHU^U^4[[(;Q!((b(1I <
 q

9% 99UE!H-Cc6k?BsF{OqA>>!Q
33 . !cJ&/8;;; <;s   5F
Fc                    UR                   nUR                  nU R                  5       R                  5       R	                  U5      n[
        R                  " XU   5      (       d;  [
        R                  " XbUSS9n[
        R                  " Xr[        R                  5      nU[        R                  :H  R                  5       S   n	XU:*     S   n
 XU:     S   nXjU nX*-  nX{S-
     [        R                  :H  nU(       a"  [
        R                  " XS USUS-    /5      nSnS nU R                  5       R	                  U5      n[
        R                  " [
        R                   " [
        R"                  " [
        R$                  " USS9R&                  6 5      SS5      nUUU   -  n[
        R(                  " U* S-  US-  /5      nU(       a  US==   US   US   -
  -  ss'   U" UUU5      u  u  nnu  nn[
        R*                  " [
        R,                  " UU-
  UU-
  5      5      nU R.                  (       a  US-   S	-  S-
  nUU* U7/-  n[
        R0                  " UU[3        [        U5      5      SSS
9u  nn[4        R6                  " U5      n[4        R8                  " U5      nU" UUU5      u  u  nnu  nn/ n/ nU(       aq  US:w  aj  US:w  ad  UUUS-    nUR;                  UU4/UUU4//5        [        U5      S-   n UR;                  [        R                  /[        R                  /U -  /5        OUS:w  aS  UR;                  USUS-    UU4//5        UR;                  [        R                  /[        R                  /US-   -  /5        US:w  aY  UR;                  UU4/UUS /5        UR;                  [        R                  /[        R                  /[        U5      U-
  -  /5        [
        R                  " USU
 /UQXkS P5      n[
        R                  " USU
 /UQX{S P5      nU[        Xg5      4$ ! [         a    [        U5      n GNwf = f)a  
Prepare for insertion of a label at index *idx* of *path*.

Parameters
----------
path : Path
    The path where the label will be inserted, in data space.
idx : int
    The vertex index after which the label will be inserted.
screen_pos : (float, float)
    The position where the label will be inserted, in screen space.
lw : float
    The label width, in screen space.
spacing : float
    Extra spacing around the label, in screen space.

Returns
-------
path : Path
    The path, broken so that the label can be drawn over it.
angle : float
    The rotation of the label.

Notes
-----
Both tasks are done together to avoid calculating path lengths multiple times,
which is relatively costly.

The method used here involves computing the path length along the contour in
pixel coordinates and then looking (label width / 2) away from central point to
determine rotation and then to break contour if desired.  The extra spacing is
taken into account when breaking the path, but not when computing the angle.
r   rx   rB   r   Nc                 p    UR                    Vs/ s H  n[        R                  " XU5      PM     sn$ s  snf N)Tr[   interp)r&   xpfpcols       r,   
interp_vecEContourLabeler._split_path_and_get_label_rotation.<locals>.interp_vec]  s(    BDD*QDS299QC+@D*Q#Q*Qs   !3r<   Z      )leftright)verticescodesget_transforminvertedr   r[   allcloseinsertr
   LINETOMOVETOnonzero
IndexErrorrP   	CLOSEPOLYconcatenatecumsumr   diffr   arrayrad2degarctan2r8   r   rO   mathfloorr   extend)!ro   pathr   
screen_posr   spacingxysr   posmovetosstartstopcc_xysis_closed_pathr   
screen_xys	path_cplstarget_cplssx0sx1sy0sy1anglei0i1x0x1y0y1new_xy_blocksnew_code_blockspointsnliness!                                    r,   "_split_path_and_get_label_rotation1ContourLabeler._split_path_and_get_label_rotation  s   D mm

   "++-77
C{{3C))))Cc2CIIe$++6E
 DKK'002153'+	S=)!,D
 4 axDNN:^^V^VFSU^$DEFC 	R '')33F;
IIIIbhh
 ; = =>?AG	Ys^#	 hhAr!t}-Ny}y|;<N!+KJ!O
cJS#

2::cCis;<RZ3&+E7(++ ;	5Y3H "".BZZ^YYr]'YGR(2r RxB"H  2a4$$Bxj&B8*%EFVq&&}v7M'NORx$$fWb1foRz%BC&&}Q7O'PQRx$$Bxj&+%>?&&[[MDKK=CK"4D#E(G H nnc&5kFMF3u:FGfuNNuNOd3&&&C  	u:D	s   
P7 7QQc                    U R                   R                  R                  5       R                  X45      u  pg[	        XgU R                  X@R                  5      USSU R                  U R                  R                  XPR                  5       S9U R                  U R                   R                  S9
nU R                  (       aI  U R                   R                  R                  5       R                  U/X//5      u  n	UR                  U	SS9  U R                   R#                  U5        U R$                  R#                  U5        U R&                  R#                  X45        U R                   R)                  U5        g)zAAdd a contour label, respecting whether *use_clabeltext* was set.center)alpha)textrotationhorizontalalignmentverticalalignmentr9   colorr   clip_boxT)r  transform_rotates_textN)r   	transDatar   r   r   r   rH   rL   rZ   to_rgba	get_alpharY   bboxrI   transform_anglessetrn   rS   labelCValuesrc   
add_artist)
ro   r&   r'   r  rs   cvaluedata_xdata_ytdata_rotations
             r,   	add_labelContourLabeler.add_label  s    ,,557AA1&IsMM2 (H&&$$,,V>>;K,L11YY^^% !YY0099;LL
aVH&NMEE=EFq!  (aV$		Qr.   c                    Uc  U R                   R                  nU(       a  UR                  X45      u  pU R                  X4U R                  5      u  pgnU R
                  U   n	U R                  R                  U5      n
U R                  U
5      nU R                  XXU5      u  pU R                  " / UQUPU R                  U   PU R                  U   P76   U(       a  XR
                  U'   gg)a  
Add a label near the point ``(x, y)``.

Parameters
----------
x, y : float
    The approximate location of the label.
inline : bool, default: True
    If *True* remove the segment of the contour beneath the label.
inline_spacing : int, default: 5
    Space in pixels to leave on each side of label when placing
    inline. This spacing will be exact for labels at locations where
    the contour is straight, less so for labels on curved contours.
transform : `.Transform` or `False`, default: ``self.axes.transData``
    A transform applied to ``(x, y)`` before labeling.  The default
    causes ``(x, y)`` to be interpreted as data coordinates.  `False`
    is a synonym for `.IdentityTransform`; i.e. ``(x, y)`` should be
    interpreted as display coordinates.
N)r   r	  r   _find_nearest_contourrV   _pathsindexr   r   r  rU   r]   )ro   r&   r'   r   r   r   idx_level_minidx_vtx_minprojr   levellabel_widthr  s                r,   r%   ContourLabeler.add_label_near  s    , 		++I&&v.DA+/+E+EFD((,*(D{{=)$$**=9//6@@t.B 	< 	<h 	<(;(;M(J 	<++M:	< )-KK& r.   c                     U R                   R                  U5        U R                  R                  U5      nUR                  5         g)z>Defaults to removing last label, but any index can be suppliedN)r  poprn   remove)ro   r  r  s      r,   r!   ContourLabeler.pop_label  s3    e$OO&	
r.   c           	         [        [        U R                  U R                  U R                  5      5       GH  u  nu  pEnU R                  5       nU R                  U5      n/ n	U R                  U   R                  5        H  n
UR                  U
R                  5      nU R                  X5      (       aY  U R                  X5      u  pnU R                  XX4X5      u  pU R                  XXU5        U(       a  U	R                  U5        M  M  U	R                  U
5        M     U(       d  M  [         R"                  " U	6 U R                  U'   GM     g r   )rR   ziprV   rU   r]   r   r   r  _iter_connected_componentsr   r   r   r   r   r  rS   r
   make_compound_path)ro   r   r   r   iconrs   r  transr   	additionssubpathr   r&   r'   r  r   s                   r,   rk   ContourLabeler.labels  s,   (1#$$##$$3
 )$C$$V
 &&(E33C8KI;;t,GGI"__W-=-=>
##J<< $ 1 1* JIA#%)%L%Lqf#&5NH NN1?!((.  $$W- J v$($;$;Y$GD!1)r.   c                 h   > [         TU ]  5         U R                   H  nUR                  5         M     g r   )superr$  rn   )ro   r  	__class__s     r,   r$  ContourLabeler.remove  s$    OODKKM $r.   )rL   rY   rI   r]   rH   rV   rU   rJ   rZ   rc   r8   r   )r2   )Tr2   N)rB   )__name__
__module____qualname____firstlineno____doc__rt   r   r   r   r   r   r   r  r%   r!   rk   r$  __static_attributes____classcell__r1  s   @r,   r0   r0   :   st    AU?T!5 U?nQ-4 <Dx't , @A!%&.PH6 r.   r0   c                    [        U 5      S:X  a  XS   -
  S-  R                  5       U S   S4$ U SS U SS -
  nUS-  R                  SS9nSX3S:H  '   [        R                  " XSS -
  U-  R                  SS9U-  SS5      SS2S4   nU SS XB-  -   nXQ-
  S-  R                  SS9n[        R                  " U5      nXg   XW   XwS-   44$ )aQ  
Parameters
----------
xys : (N, 2) array-like
    Coordinates of vertices.
p : (float, float)
    Coordinates of point.

Returns
-------
d2min : float
    Minimum square distance of *p* to *xys*.
proj : (float, float)
    Projection of *p* onto *xys*.
imin : (int, int)
    Consecutive indices of vertices of segment in *xys* where *proj* is.
    Segments are considered as including their end-points; i.e. if the
    closest point on the path is a node in *xys* with index *i*, this
    returns ``(i-1, i)``.  For the special case where *xys* is a single
    point, this returns ``(0, 0)``.
r   r   r<   r   r   NrB   rx   )rP   r   r[   clipargmin)r   pdxysnorms	rel_projsprojsd2simins           r,   _find_closest_point_on_pathrF    s    , 3x1}!f*"'')3q66::qr7S"XDQYOOO#EE1*
#2h,$	###+e3	1gI Hy''EI!
 
 a
 
(C99S>DIu{T6N33r.   z
Attributes
----------
levels : array
    The values of the contour levels.

layers : array
    Same as levels for line contours; half-way between
    levels for filled contours.  See ``ContourSet._process_colors``.
)contour_set_attributesc                      ^  \ rS rSrSrSSSSSSSSSSSSSSSSSSSSSS.U 4S	 jjr\" S
 5      r\" S 5      r\" S 5      r	\" S 5      r
S rS rS\4S jrS rS rS rU 4S jrS rS rS rS rS rS rSS jrS S jrU 4S jrSrU =r$ )!
ContourSeti'  aA  
Store a set of contour lines or filled regions.

User-callable method: `~.Axes.clabel`

Parameters
----------
ax : `~matplotlib.axes.Axes`

levels : [level0, level1, ..., leveln]
    A list of floating point numbers indicating the contour levels.

allsegs : [level0segs, level1segs, ...]
    List of all the polygon segments for all the *levels*.
    For contour lines ``len(allsegs) == len(levels)``, and for
    filled contour regions ``len(allsegs) = len(levels)-1``. The lists
    should look like ::

        level0segs = [polygon0, polygon1, ...]
        polygon0 = [[x0, y0], [x1, y1], ...]

allkinds : ``None`` or [level0kinds, level1kinds, ...]
    Optional list of all the polygon vertex kinds (code types), as
    described and used in Path. This is used to allow multiply-
    connected paths such as holes within filled polygons.
    If not ``None``, ``len(allkinds) == len(allsegs)``. The lists
    should look like ::

        level0kinds = [polygon0kinds, ...]
        polygon0kinds = [vertexcode0, vertexcode1, ...]

    If *allkinds* is not ``None``, usually all polygons for a
    particular contour level are grouped together so that
    ``level0segs = [polygon0]`` and ``level0kinds = [polygon0kinds]``.

**kwargs
    Keyword arguments are as described in the docstring of
    `~.Axes.contour`.

%(contour_set_attributes)s
NFr   neitherr   )rM   filled
linewidths
linestyleshatchesr  originextentr@   r5   rA   vminvmax	colorizerr   antialiasednchunklocatorr   negative_linestyles	clip_pathc          	        > Uc	  U(       a  Sn[         T U ]  UUUUUS9  Xl        X l        X0l        X`l        Xl        Xl        Xl        UU l	        UU l
        UU l        U(       a)  U R                  XXXS9  UR                  nUR                  n
[        U[         R"                  5      (       d)  [        U R                  [$        R&                  5      (       a   SU l        Uc  [         R"                  " 5       nOSU l        [*        R,                  " / SQUS9  U R                  b$  [/        U R                  5      S:w  a  [1        S	5      eU R                  b  U
b  [1        S
5      eU R                  S:X  a  [2        R4                  S   U l        XPl        UU l        U R8                  c  [2        R4                  S   U l        U R:                  " U0 UD6nU R=                  5         U R                  S;   U l        U R                  S;   U l         U R                  GbK  [         RB                  " U R                  5      (       a  U R                  /nOU R                  n[/        U R                  5      nU R                  (       a  US-  nSnSnU[E        U R>                  5      -   [E        U R@                  5      -   n[/        U5      U:X  a7  U R>                  (       d  U R@                  (       a  SnU R>                  (       a  Sn[         RF                  " UUS US9n
U(       aJ  U R>                  (       a  U
RI                  US   5        U R@                  (       a  U
RK                  US   5        / U l&        / U l'        U RQ                  U
5        Ub  U RS                  U5        U R                  RT                  RW                  SS9   Ub  XR                  l,        Ub  XR                  l-        SSS5        U R                  R]                  5         U R_                  5         U R`                  c  U Rc                  5       U l0        U R                  (       aM  Ub  [*        Rd                  " S5        U Rg                  5       u  nnU Ri                  SURk                  SS5      S9  OAU Ri                  SU Rm                  U5      U Ro                  U5      URk                  SS5      SS9  U R                  Rq                  U SS9  U Rr                  S   U Rt                  S   /U Rv                  Rx                  SS& U Rr                  S   U Rt                  S   /U Rv                  Rz                  SS& U R                  R}                  U Rr                  U Rt                  /5        U R                  R                  SS9  U R                  5         U(       a7  [*        Rd                  " SS R                  [        [        U5      5      -   5        gg! , (       d  f       GN= f)!a  
Draw contour lines or filled regions, depending on
whether keyword arg *filled* is ``False`` (default) or ``True``.

Call signature::

    ContourSet(ax, levels, allsegs, [allkinds], **kwargs)

Parameters
----------
ax : `~matplotlib.axes.Axes`
    The `~.axes.Axes` object to draw on.

levels : [level0, level1, ..., leveln]
    A list of floating point numbers indicating the contour
    levels.

allsegs : [level0segs, level1segs, ...]
    List of all the polygon segments for all the *levels*.
    For contour lines ``len(allsegs) == len(levels)``, and for
    filled contour regions ``len(allsegs) = len(levels)-1``. The lists
    should look like ::

        level0segs = [polygon0, polygon1, ...]
        polygon0 = [[x0, y0], [x1, y1], ...]

allkinds : [level0kinds, level1kinds, ...], optional
    Optional list of all the polygon vertex kinds (code types), as
    described and used in Path. This is used to allow multiply-
    connected paths such as holes within filled polygons.
    If not ``None``, ``len(allkinds) == len(allsegs)``. The lists
    should look like ::

        level0kinds = [polygon0kinds, ...]
        polygon0kinds = [vertexcode0, vertexcode1, ...]

    If *allkinds* is not ``None``, usually all polygons for a
    particular contour level are grouped together so that
    ``level0segs = [polygon0]`` and ``level0kinds = [polygon0kinds]``.

**kwargs
    Keyword arguments are as described in the docstring of
    `~.Axes.contour`.
NF)antialiasedsr  rX  r   rS  )r@   rA   rQ  rR  r5   T)Nlowerupperimage)rO     z3If given, 'extent' must be None or (x0, x1, y0, y1)z"Either colors or cmap must be Noner]  zimage.originzcontour.negative_linestyleminbothmaxra  r   r   r>   rB   changed)signalz!linewidths is ignored by contourfnoner9   )	edgecolorr9   r<   
_nolegend_)	facecolorrL  	linestyler9   label)autolim)tightz/The following kwargs were not used by contour: z, )Dr0  __init__r   rM   rK  rN  rO  rP  r5   r   rU  rV  _set_colorizer_check_keywordsrA   r@   r   r^   LogNormrE   
LogLocatorlogscaler   check_in_listrP   rT   rf   rcParams_orig_linestylesrW  _process_args_process_levels_extend_min_extend_maxis_color_liker   r_   	set_underset_overrn   r  set_cmapset_norm	callbacksblockedrQ  rR  _changed_process_colorsr  "_make_paths_from_contour_generatorwarn_external_get_lowers_and_uppersr  r#  _process_linewidths_process_linestylesadd_collection_mins_maxssticky_edgesr&   r'   update_datalimautoscale_viewrd  joinmaprepr)!ro   axrM   rK  rL  rM  rN  r  rO  rP  r@   r5   rA   rQ  rR  rS  r   rT  rU  rV  r   rW  rX  argskwargscolor_sequencencolorsr   use_set_under_overtotal_levelslowersuppersr1  s!                                   r,   rn  ContourSet.__init__S  s   f 6K 	$ 	 	
 	..y4848 / I >>D>>DtW__--dllF,=,=>> DM|(!DM<VL;;"s4;;'71'<EG G;;"t'7ABB;;'!,,~6DK *#6  ##+9: $ ##T4V4;;/9;;/9;;"$$T[[11"&++!%$++&G{{1B
 "'
 $ 0 012 0 012L N#|3%%)9)9%)"##B)).D*AWMD!##NN>!#45##MM."45 dMM$YY  ((	(:!%		!%			 ;
 			;;AACDK;;%""#FG!88:NFFHH zz(A.   HH 33J?22:> zz(A."   			  u 5"&**Q-A!?A"&**Q-A!?A		  $**djj!9:		  t ,A		#dF+,- S ;:s   3'W**
W9c                     U R                  5        VVs/ s H-  nUR                  5        Vs/ s H  o"R                  PM     snPM/     snn$ s  snf s  snnf r   )	get_pathsr(  r   ro   r?  subps      r,   <lambda>ContourSet.<lambda>  sH    !%#!A $%#?#?#AB#A4#AB!%#B%#   AAAAc                     U R                  5        VVs/ s H-  nUR                  5        Vs/ s H  o"R                  PM     snPM/     snn$ s  snf s  snnf r   )r  r(  r   r  s      r,   r  r    sH    !&#!A !" < < >? > >?!&#?&#r  c                 "    U R                  5       $ r   )r  ro   s    r,   r  r  "  s    $.."2r.   c                     U R                   $ r   )ru  r  s    r,   r  r  #  s
    t'<'<r.   c                 ^   U R                   c'  U R                  R                  U l         U R                   $ [        U R                   [        R
                  5      (       dE  [        U R                   S5      (       a*  U R                   R                  U R                  5      U l         U R                   $ )z9Return the `.Transform` instance used by this ContourSet._as_mpl_transform)
_transformr   r	  r   mtransforms	Transformhasattrr  r  s    r,   r   ContourSet.get_transform%  sx    ??""ii11DO  T__k.C.CDD$//+>??"oo??		JDOr.   c                 D    U R                   R                  5       nS US'   U$ )N_contour_generator)__dict__copy)ro   states     r,   __getstate__ContourSet.__getstate__.  s&    ""$ '+"#r.   r&   c                    / n/ nU R                   (       Ga(  U R                  5       u  pV[        U R                  5      n[	        U5       H  nUR                  [        R                  " SSSU R                  5       U   U R                  U[        U R                  5      -     S95        U" XX   5      n	U" Xh   5      n
US:X  a*  U R                  S;   a  UR                  SU SU	 S35        M  XS-
  :X  a*  U R                  S	;   a  UR                  SU S
U
 S35        M  UR                  SU	 SU SU
 S35        M     X44$ [        U R                  5       Hr  u  pUR                  [        / / U R                  5       U   U R                  5       U   U R!                  5       U   S95        UR                  SU SU" U5       S35        Mt     X44$ )a	  
Return a list of artists and labels suitable for passing through
to `~.Axes.legend` which represent this ContourSet.

The labels have the form "0 < x <= 1" stating the data ranges which
the artists represent.

Parameters
----------
variable_name : str
    The string used inside the inequality used on the labels.
str_format : function: float -> str
    Function used to format the numbers in the labels.

Returns
-------
artists : list[`.Artist`]
    A list of the artists.
labels : list[str]
    A list of the labels.
r<  r   )ri  hatchr   r_  $z \leq zs$rb  z > z < )r  	linewidthrj  z = )rK  r  rP   r  rO   rS   mpatches	Rectangleget_facecolorrN  r   rR   rM   r	   get_edgecolorget_linewidthsget_linestyles)ro   variable_name
str_formatartistsrk   r  r  n_levelsr   r[  r\  r  s               r,   legend_elementsContourSet.legend_elements6  s   , ;;;!88:NF4;;'HXx11Aq"00237,,sS->'>?  
 #6;/"6;/!8 >MMQ}oVE7""EFqL(T[[O-KMMQ}oSr"BCMMQugSveWA"NO '0  (4
v,,.s3"113C8"113C8	   =/Z5F4GqIJ 5 r.   c                    US   U l         US   n[        U5      S:  a  US   OSn[        R                  " U R                   5      U l        [        R
                  " U R                   5      U l        Uc  U Vs/ s H  nS/[        U5      -  PM     nnU R                  (       a1  [        U5      [        U R                   5      S-
  :w  a  [        S5      eO-[        U5      [        U R                   5      :w  a  [        S5      e[        U5      [        U5      :w  a  [        S5      eU VVs/ s H  of  H  owPM     M     nnn[        R                  " USS9n	U	R                  SS9U l
        U	R                  SS9U l        [        X45       VV
s/ s H&  u  pZ[        R                  " [        [        XZ5      6 PM(     sn
nU l        U$ s  snf s  snnf s  sn
nf )	z
Process *args* and *kwargs*; override in derived classes.

Must set self.levels, self.zmin and self.zmax, and update Axes limits.
r   r   r<   Nz-must be one less number of segments as levelsz)must be same number of segments as levelsz(allkinds has different length to allsegsrx   )rM   rP   r[   rc  zmaxr`  zminrK  rT   r   r  r  r'  r
   r)  r  r  )ro   r  r  allsegsallkindssegssegr   flatseglistr   kindss              r,   rv  ContourSet._process_argsl  s    1gq'!$i!m47FF4;;'	FF4;;'	7>?wtT*wH? ;;7|s4;;/!33  "* + + 4 7|s4;;// !LMM x=CL(GHH %,9GSSqSqG9!4ZZQZ'
ZZQZ'
 +.g*@B*@;4 ..D$0FG*@B ; @  :Bs   7G)G-Gc           
         U R                   b  U R                   $ U R                  n[        [        R                  " S5      5      nU R
                  (       a$  [        UR                  /U R                  5       Q76 O[        UR                  U R                  5      nU VVs/ s HK  u  pE[        U5      (       a4  [        [        R                  " U5      [        R                  " U5      5      OUPMM     snn$ s  snnf )z$Compute ``paths`` using C extension.)r   r<   )r  r  r
   r[   emptyrK  r  create_filled_contourr  create_contourrM   rP   r   )ro   cg
empty_pathvertices_and_codesvsr(   s         r,   r  -ContourSet._make_paths_from_contour_generator  s    ;;";;$$"((6*+
 {{ ((I4+F+F+HI!!4;;/ 	
 120FB ADBR^^B');<ZW02 	2 2s   AC5c                     U R                   SS nU R                  US   :X  aA  UR                  5       nU R                  (       a  SU R                  -  US'   OUS==   S-  ss'   U R                   SS nX4$ )z2
Return ``(lowers, uppers)`` for filled contours.
NrB   r   gGz?r   )_levelsr  r  rr  )ro   r  r  s      r,   r  !ContourSet._get_lowers_and_uppers  sn     cr"99q	![[]F}} 499,q	q	Q	ab!r.   c                 @  > [        U S5      (       d  U R                  5         U R                  R                  U R                  5        U R                  U R                  5        U R                  5         [        R                  " U R                  5       [        U R                  5      5      n[        U R                  U R                  U5       HA  u  p#nUR                  U5        UR!                  U R"                  R%                  U5      5        MC     [&        TU ]Q  5         g )NrQ   )r  r  rA   autoscale_NonerM   	set_arrayrQ   update_scalarmappabler[   broadcast_tor  rP   r'  rn   r  	set_alpha	set_colorrZ   r
  r0  rd  )ro   alphasrk  cvr  r1  s        r,   rd  ContourSet.changed  s    tY''  "
 			  -t||$""$!13t||3DE #DOOT5F5F OEuOOE"OOD..66r:; !P 	r.   c                    U R                   cI  U R                  (       a  [        R                  " 5       U l         O[        R                  " US-   SS9U l         U R                   R                  U R                  U R                  5      n U R                   R                  (       a  U$  [        R                  " X R                  :  5      S   n[        U5      (       a  US   OSn[        R                  " X R                  :  5      S   n[        U5      (       a  US   S-   O
[        U5      nU R                  S;   a  US-  nU R                  S;   a  US-  nXd-
  S:  a  S[        U5      pdX$U $ ! [         a     Nf = f)a  
Select contour levels to span the data.

The target number of levels, *N*, is used only when the
scale is not log and default locator is used.

We need two more levels for filled contours than for
line contours, because for the latter we need to specify
the lower and upper boundary of each range. For example,
a single contour boundary, say at z = 0, requires only
one contour line, but two filled regions, and therefore
three levels to provide boundaries for both regions.
r   )min_n_ticksr   rB   r_  rb     )rV  rr  rE   rq  MaxNLocatortick_valuesr  r  
_symmetricAttributeErrorr[   r   rP   r   )ro   r?   rs   underr   overr   s          r,   _autolevContourSet._autolev  s5    <<}}%002%11!a%QGll&&tyy$))<	||&&
 ' 

3?+A.e**U2Y!zz#		/*1-IIT!Wq[3s8;;/)!GB;;/)!GB7Q;Cbz!  		s   E, ,
E98E9c                    U R                   cJ  U(       a  US   nOI[        R                  " U[        5      (       a  U R                  (       a  / SQnOS/nOSnOU R                   n[        U[        5      (       a  U R                  U5      U l         O*[        R                  " U[        R                  5      U l         U R                  (       a$  [        U R                   5      S:  a  [        S5      e[        U R                   5      S:  aD  [        R                  " [        R                  " U R                   5      5      S	::  a  [        S
5      egg)z8
Determine the contour levels and store in self.levels.
Nr   )r         ?r   r     r<   z*Filled contours require at least 2 levels.r   g        z!Contour levels must be increasing)rM   r[   
issubdtypeboolrK  r   r   r  asarrayfloat64rP   rT   r`  r   )ro   r  z_dtype
levels_args       r,   _process_contour_level_args&ContourSet._process_contour_level_args  s     ;;!!W
w--;;!+J"$J
Jj(++--
3DK**Z<DK;;3t{{+a/IJJt{{aBFF2774;;+?$@C$G@AA %Hr.   c                    [        U R                  5      U l        U R                  (       a  Su  pOSu  pU R                  S;   a  U R                  R                  SU5        U R                  S;   a  U R                  R                  U5        [        R                  " U R                  5      U l        U R                  (       d  U R                  U l
        gU R                  (       aM  [        R                  " U R                  SS 5      [        R                  " U R                  SS 5      -  U l
        gS	U R                  SS U R                  SS -   -  U l
        g)
z
Assign values to :attr:`layers` based on :attr:`levels`,
adding extended layers as needed if contours are filled.

For line contours, layers simply coincide with levels;
a line is a thin layer.  No extended levels are needed
with line contours.
)gL]?RyXs)gRyXr  ra  r`  r   ra  rc  NrB   r   r  )rN   rM   r  rr  r   r   rS   r[   r  rK  layerssqrt)ro   r[  r\  s      r,   rw  ContourSet._process_levels  s     DKK(==(LE5(LE;;/)LL5);;/)LL&zz$,,/{{++DK ==774<<#45WWT\\!"%567DK cr!2T\\!"5E!EFDKr.   c                    U R                   R                  U l        U R                  b  S[        U R                  5      p!U R
                  (       a/  US-  nU R                  S;   a  US-  nU R                  S;   a  US-  n[        [        X5      5      U l	        U R                  [        R                  " 5       5        OU R                  U l	        U R                  R                  U R                  5        U R!                  U R                  5        U R#                  5         U R                  S;   a  SU R                  l        gg)aq  
Color argument processing for contouring.

Note that we base the colormapping on the contour levels
and layers, not on the actual range of the Z values.  This
means we don't have to worry about bad values in Z, and we
always have the full dynamic range available for the selected
levels.

The color is based on the midpoint of the layer, except for
extended end layers.  By default, the norm vmin and vmax
are the extreme values of the non-extended levels.  Hence,
the layer color extremes are not the extreme values of
the colormap itself, but approach those values as the number
of levels increases.  An advantage of this scheme is that
line contours, when added to filled contours, take on
colors that are consistent with those of the filled regions;
for example, a contour line on the boundary between two
regions will have a color intermediate between those
of the regions.

Nr   r   r  r  )ra  rc  r`  F)r@   
monochromer5   rP   rM   rK  r   rN   rO   rQ   r~  r^   rb   r  rA   r  r  r  r=  )ro   r   r   s      r,   r  ContourSet._process_colors-  s    . ))..;;"DKK({{a;;/1!GB;;/1!GBb.DLMM'..*+;;DL		  -t||$""$;;00"DIIN 1r.   c                 8   [        U R                  5      nUc/  [        R                  S   nUc  [        R                  S   nU/U-  $ [        R
                  " U5      (       d  U/U-  $ [        U5      nU[        R                  " U[        U5      -  5      -  S U $ )Nzcontour.linewidthzlines.linewidth)	rP   rM   rf   rt  r[   rd   rN   r   r   )ro   rL  Nlevdefault_linewidths       r,   r  ContourSet._process_linewidthsY  s    4;; #-@ A ($'LL1B$C!%&--Z((<$&&j)J4#j/+A!BBETJJr.   c                 H   [        U R                  5      nUci  S/U-  nU R                  (       aP  U R                  U R                  -
  * S-  n[        U R                  5       H  u  pVXd:  d  M  U R                  X5'   M     U$ [        U[        5      (       a  U/U-  nU$ [        R                  " U5      (       a_  [        U5      n[        U5      U:  a/  [        [        R                  " U[        U5      -  5      5      nX7-  n[        U5      U:  a  US U nU$ [        S5      e)NsolidgV瞯<z&Unrecognized type for linestyles kwarg)rP   rM   r  r  r  rR   rW  r   r   r[   rd   rN   r   r   rT   )ro   rM  r  tlinestylesepsrr   rs   nrepss           r,   r  ContourSet._process_linestylesf  s   4;;")d*KTYY./%7'4FAy)-)A)A 5  *c**)lT1  Z((":.{#d*s:(> ?@E"-"5K{#d*"-et"4K  !!IJJr.   c                    U R                   (       a  [        S5      eUc  [        [        U R                  5      5      n[
        R                  nS=n=pVU H  nU R                  U   nSn	UR                  5        Hw  n
[        U
R                  5      (       d  M  U R                  5       R                  U
R                  5      n[        X5      u  pnX:  a  UnUnUS   U	-   nUnU	[        U
5      -  n	My     M     XEU4$ )aB  
Find the point in the unfilled contour plot that is closest (in screen
space) to point *xy*.

Parameters
----------
xy : tuple[float, float]
    The reference point (in screen space).
indices : list of int or None, default: None
    Indices of contour levels to consider.  If None (the default), all levels
    are considered.

Returns
-------
idx_level_min : int
    The index of the contour level closest to *xy*.
idx_vtx_min : int
    The index of the `.Path` segment closest to *xy* (at that level).
proj : (float, float)
    The point in the contour plot closest to *xy*.
z'Method does not support filled contoursNr   r   )rK  rT   rO   rP   r  r[   infr(  r   r   r   rF  )ro   xyrp   d2minr  r  proj_min	idx_levelr   idx_vtx_startr-  lcd2r  legs                  r,   r   ContourSet._find_nearest_contour}  s    6 ;;FGG?C,-G1555 I;;y)DM::<7++,,'')33G4D4DE ;B C#:E$-M"%a&="8K#HW- = ! 833r.   c                    S=n=pg[        5        nU(       d1  UR                  U R                  [        R                  " 5       S95        U R                  X4U5      u  pu  pSSS5        W	bv  [        R                  " / [        [        U R                  U	   R                  5       5      Q5      nUR                  W
S5      nUS:X  a  U
O	XUS-
     -
  nWU-
  S-  WU-
  S-  -   nXUWWU4$ ! , (       d  f       N= f)a  
Find the point in the contour plot that is closest to ``(x, y)``.

This method does not support filled contours.

Parameters
----------
x, y : float
    The reference point.
indices : list of int or None, default: None
    Indices of contour levels to consider.  If None (the default), all
    levels are considered.
pixel : bool, default: True
    If *True*, measure distance in pixel (screen) space, which is
    useful for manual contour labeling; else, measure distance in axes
    space.

Returns
-------
path : int
    The index of the path that is closest to ``(x, y)``.  Each path corresponds
    to one contour level.
subpath : int
    The index within that closest path of the subpath that is closest to
    ``(x, y)``.  Each subpath corresponds to one unbroken contour line.
index : int
    The index of the vertices within that subpath that are closest to
    ``(x, y)``.
xmin, ymin : float
    The point in the contour plot that is closest to ``(x, y)``.
d2 : float
    The squared distance from ``(xmin, ymin)`` to ``(x, y)``.
N)r   r   r   r   r<   )r   enter_context_cm_setr  IdentityTransformr  r[   r   r  rP   r  r(  searchsorted)ro   r&   r'   rp   pixelsegmentr  r  stacki_leveli_vtxxminymin
cc_cumlenss                 r,   find_nearest_contourContourSet.find_nearest_contour  s   D  $##%[E ##DLL);;= %1 %? @ ,0+E+Eqfg+V(GLT  N#c4;;w/JJLMNPJ --eW=G$\Eu'A+7N/NEq&1Q{*B%tR88! [s   AC))
C7c                 6  > U R                   n[        U5      nU R                  (       a!  [        S U R                   5       5      (       a  [
        TU ]  U5        g U R                  5       nUR                  S:X  a  Sn[        U5       H  n[        R                  " XU   /S9   U R                  U R                  U[        U R                  5      -     U R                  5       U   /U R                  5       U[        U R                  5       5      -     /U R                  5       U[        U R                  5       5      -     /XE[        U5      -     S9   [
        TU ]  U5        S S S 5        S S S 5        M     g ! , (       d  f       N= f! , (       d  f       GM  = f)Nc              3   (   #    U  H  oS L v   M
     g 7fr   r   )r   r  s     r,   r   "ContourSet.draw.<locals>.<genexpr>  s     !J\E4-\s   r   )rf  )r  )r  r   rL  rM  
edgecolors)r  rP   rK  allrN  r0  r"   get_edgecolorsr=   rO   rl   _setattr_cmr  	get_arrayr  r  )ro   r   pathsn_pathsr+  r   r1  s         r,   r"   ContourSet.draw  sJ   e*{{c!JT\\!JJJGL"((*
??a"J>C""4s=t||ll3T\\):#:;~~',- //1#D<O<O<Q8R2RST //1#D<O<O<Q8R2RST%C
O&;< @L @ X&@== "@ @==s%   #B/FE7"F7
FF
F	)ry  rx  r  r  r  ru  r  r  r   r5   rQ   r   rP  rK  rN  r  rn   r  rM   rV  rr  r  rU  rW  rO  r  r  )NT)r3  r4  r5  r6  r7  rn  propertyr  r  r  rM  r   r  r   r  rv  r  r  rd  r  r  rw  r  r  r  r  r&  r"   r8  r9  r:  s   @r,   rI  rI  '  s    (V Ut T$4dD	tA4SWG GR  # $G  # $H 23E<=J -0C 4l*X2  )VB2#GJ*#XK.34j49l' 'r.   rI  c                   :    \ rS rSrSrSSS.S jrS rS rS rS	r	g)
QuadContourSeti  z
Create and store a set of contour lines or filled regions.

This class is typically not instantiated directly by the user but by
`~.Axes.contour` and `~.Axes.contourf`.

%(contour_set_attributes)s
N)corner_mask	algorithmc                   U(       a  [        US   [        5      (       a  U R                  c  US   R                  U l        US   R                  U l        US   R                  U l        US   R
                  U l        US   R                  nUS   R                  U l        US   R                  U l        US   R                  U l	        GOSSK
nUc  [        R                  S   n[        R                  R                  S   " U5        X l	        Uc&  U R                  S:X  a  SnO[        R                  S   nXl        U R                  X45      u  pxn	UR                  XxXR                  U R
                  UR                   R"                  UR$                  R&                  U R(                  S9nU R+                  5       n
XR,                  R.                  :w  a  [1        U
R3                  U R,                  R.                  5      5      (       ai  XR,                  R.                  -
  n[4        R6                  " UR8                  UR8                  /5      R:                  nUR=                  U5      nUS   nUS	   n[>        R@                  " U5      [>        R@                  " U5      /U l        [>        RB                  " U5      [>        RB                  " U5      /U l        XPl        U$ )
z
Process args and kwargs.
r   Nzcontour.algorithmmpl2005Fzcontour.corner_mask)r   r6  	line_type	fill_type
chunk_size).r   ).r   )"r   r5  rM   r  r  _corner_maskr  r  r  
_algorithm	contourpyrf   rt  validate_contour_argscontour_generatorLineTypeSeparateCodeFillType	OuterCoderU  r   r   r	  r|   contains_branch_seperatelyr[   vstackflatr   r   r   r`  rc  )ro   r6  r7  r  r  rB  r?  r&   r'   zr  trans_to_dataptstransformed_ptss                 r,   rv  QuadContourSet._process_args  s>    JtAw77{{""1gnnQDIQDI $Q 4 4D $Q : :aDJaDJ"1g00DO LL)<=	LL!!"56yA'O"??i/ #(K"%,,/D"EK +((6GA! ) ; ;aoo4;L;L#,,99#,,66;;	 !< !( ""$A YY(((44TYY5H5HIJJ !II$7$7 7ii 0133"/"9"9#">#F+#F+&&)RVVAY/DJ&&)RVVAY/DJ"3r.   c                 8   U R                   (       a  SnOSn[        U5      nSUs=:  a  S::  a0  O  O-UtpQ[        R                  " U5      nU R	                  U5      u  pgO@SUs=:  a  S::  a  O  OUtpgpU R                  XgX5      u  pgnO[        R                  " USUS9e[        R                  " USS	9nUR                  5       R                  [        5      U l        UR                  5       R                  [        5      U l        U R                  (       ah  U R                  S::  aX  [        R                   " US:*  U5      n[        R"                  " S
5        UR                  5       R                  [        5      U l        U R%                  XR&                  5        XgU4$ )Ncontourfcontourr   r<   r^  zfrom 1 to 4)takesgivenF)r  z,Log scale: values of z <= 0 have been masked)rK  rP   r   r  _initialize_x_y
_check_xyzr   nargs_errormasked_invalidrc  astypefloatr  r`  r  rr  masked_wherer  r  dtype)	ro   r  r  fnnargsrJ  r&   r'   z_origs	            r,   rA  QuadContourSet._contour_argsB  s3   ;;BBD	u>>HA

1A''*DAq^!^"&A&ooaF;GA! ""2]%HHae,EEGNN5)	EEGNN5)	==TYY!^Q*AMNu-DI((ww7ayr.   c                    U R                   R                  SU4SU4/U5      u  p[        R                  " U[        R                  S9n[        R                  " U[        R                  S9n[
        R                  " U5      nUR                  S:w  a  [        SUR                   S35      eUR                  S   S:  d  UR                  S   S:  a  [        S	UR                   35      eUR                  u  pVUR                  UR                  :w  a&  [        S
UR                   SUR                   S35      eUR                  S:X  ac  UR                  u  nUR                  u  nXv:w  a  [        SU SU S35      eX:w  a  [        SU SU S35      e[        R                  " X5      u  pOUR                  S:X  a  UR                  UR                  :w  a&  [        SUR                   SUR                   S35      eUR                  UR                  :w  a&  [        SUR                   SUR                   S35      eO[        SUR                   S35      eXU4$ )zh
Check that the shapes of the input arrays match; if x and y are 1D,
convert them to 2D using meshgrid.
r&   r'   )r[  r<   Input z must be 2D, not Dr   r   >Input z must be at least a (2, 2) shaped array, but has shape zNumber of dimensions of x (z	) and y (z) do not matchzLength of x (z%) must match number of columns in z ()zLength of y (z") must match number of rows in z (zShapes of x z and z z do not matchzShapes of y z%Inputs x and y must be 1D or 2D, not )
r   _process_unit_infor[   r  r  r   ndim	TypeErrorshapemeshgrid)	ro   r&   r'   rJ  r  NyNxnxnys	            r,   rU  QuadContourSet._check_xyz]  s3   
 yy++c1XQx,@&IJJq

+JJq

+JJqM66Q;6qvvha@AA771:>QWWQZ!^ --.WWI7 8 866QVV9!&& B  !x~7 8 866Q;''CB''CBx-t 4113A!7 8 8x-t 4..0T!4 5 5;;q$DAqVVq[ww!''!"177)7177)=IK Kww!''!"177)7177)=IK K " CAFF81MNNQwr.   c                    UR                   S:w  a  [        SUR                    S35      eUR                  S   S:  d  UR                  S   S:  a  [        SUR                   35      eUR                  u  p#U R                  c  U R                  c?  [
        R                  " [
        R                  " U5      [
        R                  " U5      5      $ U R                  u  pEpg[
        R                  " XEU5      n[
        R                  " XgU5      n	[
        R                  " X5      $ U R                  c
  SUSU4u  pEpgOU R                  u  pEpgXT-
  U-  n
Xv-
  U-  nU[
        R                  " U5      S-   U
-  -   nU[
        R                  " U5      S-   U-  -   n	U R                  S	:X  a  U	SSS
2   n	[
        R                  " X5      $ )a  
Return X, Y arrays such that contour(Z) will match imshow(Z)
if origin is not None.
The center of pixel Z[i, j] depends on origin:
if origin is None, x = j, y = i;
if origin is 'lower', x = j + 0.5, y = i + 0.5;
if origin is 'upper', x = j + 0.5, y = Nrows - i - 0.5
If extent is not None, x and y will be scaled to match,
as in imshow.
If origin is None and extent is not None, then extent
will give the minimum and maximum values of x and y.
r<   ra  rb  r   r   rc  Nr  r\  rB   )	rf  rg  rh  rO  rP  r[   ri  arangelinspace)ro   rJ  rj  rk  r   r   r   r   r&   r'   dxdys               r,   rT  QuadContourSet._initialize_x_y  s    66Q;6qvvha@AAWWQZ!^qwwqzA~ --.WWI7 8 8 WWFB;;{{"{{299R="))B-@@!%KK+KK+{{1((;;Q^NBB![[NBBg^g^"))B-#%++"))B-#%++;;'!$B$A{{1  r.   )r>  r  r=  r  r  rM   r  r  )
r3  r4  r5  r6  r7  rv  rA  rU  rT  r8  r   r.   r,   r5  r5    s$     04t 8t6)V'!r.   r5  a$  
`.contour` and `.contourf` draw contour lines and filled contours,
respectively.  Except as noted, function signatures and return values
are the same for both versions.

Parameters
----------
X, Y : array-like, optional
    The coordinates of the values in *Z*.

    *X* and *Y* must both be 2D with the same shape as *Z* (e.g.
    created via `numpy.meshgrid`), or they must both be 1-D such
    that ``len(X) == N`` is the number of columns in *Z* and
    ``len(Y) == M`` is the number of rows in *Z*.

    *X* and *Y* must both be ordered monotonically.

    If not given, they are assumed to be integer indices, i.e.
    ``X = range(N)``, ``Y = range(M)``.

Z : (M, N) array-like
    The height values over which the contour is drawn.  Color-mapping is
    controlled by *cmap*, *norm*, *vmin*, and *vmax*.

levels : int or array-like, optional
    Determines the number and positions of the contour lines / regions.

    If an int *n*, use `~matplotlib.ticker.MaxNLocator`, which tries
    to automatically choose no more than *n+1* "nice" contour levels
    between minimum and maximum numeric values of *Z*.

    If array-like, draw contour lines at the specified levels.
    The values must be in increasing order.

Returns
-------
`~.contour.QuadContourSet`

Other Parameters
----------------
corner_mask : bool, default: :rc:`contour.corner_mask`
    Enable/disable corner masking, which only has an effect if *Z* is
    a masked array.  If ``False``, any quad touching a masked point is
    masked out.  If ``True``, only the triangular corners of quads
    nearest those points are always masked out, other triangular
    corners comprising three unmasked points are contoured as usual.

colors : :mpltype:`color` or list of :mpltype:`color`, optional
    The colors of the levels, i.e. the lines for `.contour` and the
    areas for `.contourf`.

    The sequence is cycled for the levels in ascending order. If the
    sequence is shorter than the number of levels, it's repeated.

    As a shortcut, a single color may be used in place of one-element lists, i.e.
    ``'red'`` instead of ``['red']`` to color all levels with the same color.

    .. versionchanged:: 3.10
        Previously a single color had to be expressed as a string, but now any
        valid color format may be passed.

    By default (value *None*), the colormap specified by *cmap*
    will be used.

alpha : float, default: 1
    The alpha blending value, between 0 (transparent) and 1 (opaque).

%(cmap_doc)s

    This parameter is ignored if *colors* is set.

%(norm_doc)s

    This parameter is ignored if *colors* is set.

%(vmin_vmax_doc)s

    If *vmin* or *vmax* are not given, the default color scaling is based on
    *levels*.

    This parameter is ignored if *colors* is set.

%(colorizer_doc)s

    This parameter is ignored if *colors* is set.

origin : {*None*, 'upper', 'lower', 'image'}, default: None
    Determines the orientation and exact position of *Z* by specifying
    the position of ``Z[0, 0]``.  This is only relevant, if *X*, *Y*
    are not given.

    - *None*: ``Z[0, 0]`` is at X=0, Y=0 in the lower left corner.
    - 'lower': ``Z[0, 0]`` is at X=0.5, Y=0.5 in the lower left corner.
    - 'upper': ``Z[0, 0]`` is at X=N+0.5, Y=0.5 in the upper left
      corner.
    - 'image': Use the value from :rc:`image.origin`.

extent : (x0, x1, y0, y1), optional
    If *origin* is not *None*, then *extent* is interpreted as in
    `.imshow`: it gives the outer pixel boundaries. In this case, the
    position of Z[0, 0] is the center of the pixel, not a corner. If
    *origin* is *None*, then (*x0*, *y0*) is the position of Z[0, 0],
    and (*x1*, *y1*) is the position of Z[-1, -1].

    This argument is ignored if *X* and *Y* are specified in the call
    to contour.

locator : ticker.Locator subclass, optional
    The locator is used to determine the contour levels if they
    are not given explicitly via *levels*.
    Defaults to `~.ticker.MaxNLocator`.

extend : {'neither', 'both', 'min', 'max'}, default: 'neither'
    Determines the ``contourf``-coloring of values that are outside the
    *levels* range.

    If 'neither', values outside the *levels* range are not colored.
    If 'min', 'max' or 'both', color the values below, above or below
    and above the *levels* range.

    Values below ``min(levels)`` and above ``max(levels)`` are mapped
    to the under/over values of the `.Colormap`. Note that most
    colormaps do not have dedicated colors for these by default, so
    that the over and under values are the edge values of the colormap.
    You may want to set these values explicitly using
    `.Colormap.set_under` and `.Colormap.set_over`.

    .. note::

        An existing `.QuadContourSet` does not get notified if
        properties of its colormap are changed. Therefore, an explicit
        call `~.ContourSet.changed()` is needed after modifying the
        colormap. The explicit call can be left out, if a colorbar is
        assigned to the `.QuadContourSet` because it internally calls
        `~.ContourSet.changed()`.

    Example::

        x = np.arange(1, 10)
        y = x.reshape(-1, 1)
        h = x * y

        cs = plt.contourf(h, levels=[10, 30, 50],
            colors=['#808080', '#A0A0A0', '#C0C0C0'], extend='both')
        cs.cmap.set_over('red')
        cs.cmap.set_under('blue')
        cs.changed()

xunits, yunits : registered units, optional
    Override axis units by specifying an instance of a
    :class:`matplotlib.units.ConversionInterface`.

antialiased : bool, optional
    Enable antialiasing, overriding the defaults.  For
    filled contours, the default is *False*.  For line contours,
    it is taken from :rc:`lines.antialiased`.

nchunk : int >= 0, optional
    If 0, no subdivision of the domain.  Specify a positive integer to
    divide the domain into subdomains of *nchunk* by *nchunk* quads.
    Chunking reduces the maximum length of polygons generated by the
    contouring algorithm which reduces the rendering workload passed
    on to the backend and also requires slightly less RAM.  It can
    however introduce rendering artifacts at chunk boundaries depending
    on the backend, the *antialiased* flag and value of *alpha*.

linewidths : float or array-like, default: :rc:`contour.linewidth`
    *Only applies to* `.contour`.

    The line width of the contour lines.

    If a number, all levels will be plotted with this linewidth.

    If a sequence, the levels in ascending order will be plotted with
    the linewidths in the order specified.

    If None, this falls back to :rc:`lines.linewidth`.

linestyles : {*None*, 'solid', 'dashed', 'dashdot', 'dotted'}, optional
    *Only applies to* `.contour`.

    If *linestyles* is *None*, the default is 'solid' unless the lines are
    monochrome. In that case, negative contours will instead take their
    linestyle from the *negative_linestyles* argument.

    *linestyles* can also be an iterable of the above strings specifying a set
    of linestyles to be used. If this iterable is shorter than the number of
    contour levels it will be repeated as necessary.

negative_linestyles : {*None*, 'solid', 'dashed', 'dashdot', 'dotted'},                        optional
    *Only applies to* `.contour`.

    If *linestyles* is *None* and the lines are monochrome, this argument
    specifies the line style for negative contours.

    If *negative_linestyles* is *None*, the default is taken from
    :rc:`contour.negative_linestyle`.

    *negative_linestyles* can also be an iterable of the above strings
    specifying a set of linestyles to be used. If this iterable is shorter than
    the number of contour levels it will be repeated as necessary.

hatches : list[str], optional
    *Only applies to* `.contourf`.

    A list of cross hatch patterns to use on the filled areas.
    If None, no hatching will be added to the contour.

algorithm : {'mpl2005', 'mpl2014', 'serial', 'threaded'}, optional
    Which contouring algorithm to use to calculate the contour lines and
    polygons. The algorithms are implemented in
    `ContourPy <https://github.com/contourpy/contourpy>`_, consult the
    `ContourPy documentation <https://contourpy.readthedocs.io>`_ for
    further information.

    The default is taken from :rc:`contour.algorithm`.

clip_path : `~matplotlib.patches.Patch` or `.Path` or `.TransformedPath`
    Set the clip path.  See `~matplotlib.artist.Artist.set_clip_path`.

    .. versionadded:: 3.8

data : indexable object, optional
    DATA_PARAMETER_PLACEHOLDER

Notes
-----
1. `.contourf` differs from the MATLAB version in that it does not draw
   the polygon edges. To draw edges, add line contours with calls to
   `.contour`.

2. `.contourf` fills intervals that are closed at the top; that is, for
   boundaries *z1* and *z2*, the filled region is::

      z1 < Z <= z2

   except for the lowest interval, which is closed on both sides (i.e.
   it includes the lowest value).

3. `.contour` and `.contourf` use a `marching squares
   <https://en.wikipedia.org/wiki/Marching_squares>`_ algorithm to
   compute contour locations.  More information can be found in
   `ContourPy documentation <https://contourpy.readthedocs.io>`_.
)contour_doc)3r7  
contextlibr   ri   r   numbersr   numpyr[   r   
matplotlibrf   r   r   matplotlib.backend_basesr   matplotlib.linesr	   matplotlib.pathr
   matplotlib.textr   matplotlib.tickerrE   matplotlib.cmr`   matplotlib.colorsr5   r^   matplotlib.collectionscollectionsmcollmatplotlib.font_managerrW   matplotlib.cbookrl   matplotlib.patchespatchesr  matplotlib.transforms
transformsr  r-   r0   rF  interpdregister
CollectionrI  r5  paramsr   r.   r,   <module>r     s	   !       ' 0 #     "  # & .   % +:z zz!4H      	4  	 R'!1!1 R' R'j q!Z q! q!h      t)h it)   t!r.   