rL i' (dZddlmZddlZddlZddlmZddlZddlm Z ddl Z ddl m Z m Z ddlmZddlmZdd lmZdd lmZddlmZddlmZddlmZddlmZddl m!Z!ddl"m#Z#ddl$m%Z&ddl'm(Z)d Z*Gd d Z+dZ,e jZj]de jZGdde+ej^Z0e jZGdde0Z1e jZj]de jZjdzy)zG Classes to support contour plotting and labelling for the Axes class. ) ExitStackN)Integral)ma)_api _docstring) MouseButton)Line2D)Path)Textc|jjdj}|jdk(}|jdk(}|r|jt j k(s|r|jdvr|jy|r|jt jk(s|r2|jdvr$|s!|j|jyy|r|jt jk(s|rg|jZ|jj|dr;|j|j|j d|| |jyyyy) NTrootbutton_press_eventkey_press_event)escapeenter) backspacedeleterF) transforminlineinline_spacing)axes get_figurecanvasnamebuttonrMIDDLEkeystop_event_loopRIGHT pop_labeldrawLEFTcontainsadd_label_nearxy)csrreventr is_buttonis_keys X/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/matplotlib/contour.py_contour_labeler_event_handlerr-s" WW  T  * 1 1F 22I ZZ, ,F ellk&8&88%))'::  (9(99  %<< LLN KKM  (8(88  - 77  E "1 %   egguww%%+N  L KKM &.Vc eZdZdZddddddddddd dZdZd Zd Zd Zd Z dd Z dZ ddZ ddZ dZfdZxZS)ContourLabelerz7Mixin to provide labelling capability to `.ContourSet`.NTF) fontsizerrfmtcolorsuse_clabeltextmanual rightside_upzorderc |&tjd}|j||_||_||_| |_| d|jzn| |_|4|j}ttt|j} nt|} gg}} t|jD],\} }|| vs | j| |j|.t|t| krt!d| d|j||_| |_t'j(||_|7||_t/j0|j|j$|_nt5j6|t|j"}ttt|j"|_t9j:|t5j<|_g|_t/j@|r|D]\}}|jC||||n|r}tEd tEd |s tEd tFjHjK|jLjOd ddgdtQjRtT|||n|jW||tYjZd|j\S)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) useOffsetzSpecified levels z don't match available levels )sizeN)cmapnormz9Select label locations manually using first mouse button.z.End manual selection with second mouse button.z1Remove last label by clicking third mouse button.Tr rr)timeouthandlerz text.Text)/tickerScalarFormattercreate_dummy_axislabelFmt_use_clabeltext labelManualr7 get_zorder_clabel_zorderlevelslistrangelencvalues enumerateappend ValueErrorlabelLevelListlabelIndiceList font_managerFontProperties_label_font_props labelMappablenptakelabelCValueListmcolorsListedColormapcmScalarMappableNoNormlabelXYsiterabler%printmpl_blocking_inputblocking_input_looprr functoolspartialr-labelscbook silent_list labelTexts)selfrLr2rrr3r4r5r6r7r8indiceslevlabsilevr?r&r's r,clabelzContourLabeler.clabel=s| ;((59C  ! ! # -!(7=~a$//"336 >[[F5T\\!234G6lG "VG#DKK0 '3'>NN1%MM#& '6{S\) #4WI>559[[M"CDD$&!-!!%D #%774<<9M9M#ND ))&C8K8K4LMD#'c$2E2E.F(G#HD !#!2!28?8H"JD  ;;v  B1##Aq&.A B  M N B CIJ    3 3 $$$$/%'89I$5$52&.%2 4 3 KK /  doo>>r.ct|d|zkDxs8t|xr+tj|dd|zkDjS)z8Return whether a contour is long enough to hold a label. raxis333333?)rOrZptpany)rn linecontour labelwidths r, print_labelzContourLabeler.print_labelsNK 2 ?2P $O !4sZ7GGLLN Qr.cXd|zdztfd|jDS)z5Return whether a label is already near this location.rxr;c3RK|]}|dz dz|dz dzzk yw)rr;N).0locthreshr&r's r, z+ContourLabeler.too_close..s=-AJ1$CF q'886A-s$')rzrb)rnr&r'lwrs `` @r, too_closezContourLabeler.too_closes.(q-"mm-- -r.c.|jjd}|jdj}tdd|j |j ||j ||jj|jS)z/Return the width of the *nth* label, in pixels.Fr Tr)figurefontproperties) rr _get_rendererr get_textrTrGrXget_window_extentwidth)rnnthfigrenderers r,_get_nth_label_widthz#ContourLabeler._get_nth_label_widths}ii""".>>t>,::<Q]]4#6#6s#;T]]K0F0FH#"8,UU 4r.c t|tr|St|tr|j|dSt t |ddr"|j g|j|dSt |r||S||zS)zGet the text of the label.z%1.3f format_ticksNrA) isinstancestrdictgetcallablegetattrrrT)rnrrr3s r,rzContourLabeler.get_texts~ c3 J T "773( ( gc>48 9##$?d&9&9$?3$?@D D c]s8O9 r.c,t|}|dkDr!ttj||z nd}|dk(r|n t|}tj|dddf||f}tj|dddf||f}|ddddf}|ddddf} |ddddf} |ddddf} ||z | | z z| |z | |z zz } tj | | z | |z } tj dd5t| | z jd}ddd|dz}tj}tj||dD]%}|||f|||f}}|j|||r%n|z|z|zfS#1swYrxYw) zX Find good place to draw a label (relatively flat part of the contour). rNrrAignore)divideinvalidrvr;) rOintrZceilresizehypoterrstateabssumargsortrRr)rnr{r|ctr_sizen_blocks block_sizexxyyyfirstylastxfirstxlastsl distanceshbsizeadistidxr&r's r, locate_labelzContourLabeler.locate_labels{#:Dq.3rwwx*456a!)QXC O YY{1a4(8Z*@ A YY{1a4(8Z*@ AArrE1bc6 ArrE1bc6  b[UV^ , /O O HHUV^UV^ 4 [[( ; 2Q!((b(1I 2 q 9%99UE!H- Cc6k?BsF{OqA>>!Q 3 !cJ&/8;;; 2 2s :F  Fc x|j}|j}|jjj |}t j |||s>t j|||d}t j||tj}|tjk(jd} | | |kd} | | |kDd} || | } || z}|| dz tjk(} | r"t j| |d| d|dzg} d}d}|jj | }t jt j t j"t j$|dj&dd}|||z}t j(| dz |dz g}| r|dxx|d|dz z cc<||||\\}}\}}t j*t j,||z ||z }|j.r |dzd zdz }|| |gz }t j0||t3t|dd \}}t5j6|}t5j8|}|||| \\}}\}}g}g}| rq|dk7r!|dk7r| ||dz}|j;||fg|||fggt|dz} |j;tjgtjg| zgn|dk7rS|j;| d|dz||fgg|j;tjgtjg|dzzg|dk7rY|j;||fg| |dg|j;tjgtjgt| |z zgt j|d| g||| d}t j|d| g||| d}|t||fS#t$rt|} Y`wxYw) 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. rrvrArNcj|jDcgc]}tj|||c}Scc}wN)TrZinterp)r&xpfpcols r, interp_veczEContourLabeler._split_path_and_get_label_rotation..interp_vec]s&BDD*QS299QC+@*Q#Q*Qs0r;Z)leftright)verticescodes get_transforminvertedrrZallcloseinsertr LINETOMOVETOnonzero IndexErrorrO CLOSEPOLY concatenatecumsumrdiffrarrayrad2degarctan2r7rrNmathfloorrextend)!rnpathr screen_posrspacingxysrposmovetosstartstopcc_xysis_closed_pathr screen_xys path_cpls target_cplssx0sx1sy0sy1anglei0i1x0x1y0y1 new_xy_blocksnew_code_blockspointsnliness! r,"_split_path_and_get_label_rotationz1ContourLabeler._split_path_and_get_label_rotations-Dmm   "++-77 C{{3C)))Cc2CIIeS$++6E DKK'002153'+ 7S=)!,D U4 u taxDNN: ^^VC^VFSU^$DEFC R'')33F; II IIbhh  ; = => ?AG Ys^# hhAr!t}-  Ny}y|; ?&&[[MDKK=CK"4D#E(GHnnc&5kFMF3tu:FGfu NNtuNOd3&&&C u:D s P!!P98P9c|jjjj||f\}}t |||j ||j |dd|j|jj||j|j|jj }|jrM|jjjj|g||gg\} |j| d|j j#||j$j#||j&j#||f|jj)|y)zAAdd a contour label, respecting whether *use_clabeltext* was set.center)alpha)textrotationhorizontalalignmentverticalalignmentr8colorrclip_boxT)rtransform_rotates_textN)r transDatarrr rrGrKrYto_rgba get_alpharXbboxrHtransform_anglessetrmrR labelCValuesrb add_artist) rnr&r'rrrcvaluedata_xdata_yt data_rotations r, add_labelzContourLabeler.add_labels.,,557AA1a&I  FsDMM2 (H&&$$,,V4>>;K,L11YY^^ %   !YY0099;LL aVH&NM EE=E F q!   ( aV$ Qr.c||jj}|r|j||f\}}|j||f|j\}}}|j |} |jj |} |j| } |j| ||| |\} } |jg|| |j||j||r| |j |<yy)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) rrr_find_nearest_contourrU_pathsindexrrr rTr\) rnr&r'rrr idx_level_min idx_vtx_minprojrlevel label_widthrs r,r%zContourLabeler.add_label_nears,   ++I &&1v.DAq+/+E+E FD((,*( {D{{=)$$**=9//6 @@ +t[.B$ < Defaults to removing last label, but any index can be suppliedN)rpoprmremove)rnrr s r,r!zContourLabeler.pop_labels3 e$ OO   &  r.c tt|j|j|jD] \}\}}}|j }|j |}g} |j|jD]} |j| j} |j| |rZ|j| |\} } }|j| || | f||\}}|j| | ||||sx| j|| j| |st!j"| |j|< yr)rQziprUrTr\rrr_iter_connected_componentsrrr}rrr rRr make_compound_path)rnrrriconrrrtransr additionssubpathrr&r'rrs r,rjzContourLabeler.labelss?(1#$$##$$3 )  H $C$$V &&(E33C8KI;;t,GGI ."__W-=-=> ##J < $ 1 1*k JIAq#%)%L%Lq!f#^&5NHdNN1a3?!((.$$W- .$($;$;Y$G D!1 Hr.cdt||jD]}|jyr)superrrm)rnr __class__s r,rzContourLabeler.removes) OO D KKM r.r)r1)Tr1N)rA)__name__ __module__ __qualname____doc__rsr}rrrrrr r%r!rjr __classcell__r#s@r,r0r0:stAU?T!5 U?nQ - 4  D IuT{T46N 33r.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 eZdZdZddddddddddddddddddddddfd Zed Zed Zed Zed Z d Z dZ de fdZ dZdZdZfdZdZdZdZdZdZdZddZddZfdZxZS) ContourSeta 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 NFrneitherr)rLfilled linewidths linestyleshatchesroriginextentr?r4r@vminvmax colorizerr antialiasednchunklocatorrnegative_linestyles clip_pathc  ||rd}t ||||||||_||_||_||_||_| |_| |_||_ ||_ ||_ |r/|j|| | | || |j} |j} t| t j"s$t|jt$j&rd|_| t!j"} nd|_t+j,gd||j#t/|jdk7r t1d |j | t1d |j d k(rt2j4d |_||_||_|j8t2j4d |_|j:|i|}|j=|jdv|_|jdv|_ |j#t!jB|jr|jg}n |j}t/|j}|jr|dz}d}d}|tE|j>ztE|j@z}t/||k(r(|j>s |j@rd}|j>rd}t!jF||d|} |r@|j>r| jI|d|j@r| jK|dg|_&g|_'|jQ| | |jS| |jjTjWd5| | |j_,|||j_-ddd|jj]|j_|j`|jc|_0|jrN|t+jdd|jg\}}|jid|jkddnD|jid|jm||jo||jkddd|jjq|d|jrd|jtdg|jvjxdd|jrd|jtdg|jvjzdd|jj}|jr|jtg|jjd|j|r6t+jddd jtt|zyy#1swYxYw)!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) antialiasedsrrGrrB)r?r@r@rAr4T)Nlowerupperimage)r>z3If given, 'extent' must be None or (x0, x1, y0, y1)z"Either colors or cmap must be NonerLz image.originzcontour.negative_linestyleminbothmaxrPrrr=rAchanged)signalz!linewidths is ignored by contourfnoner8) edgecolorr8r; _nolegend_) facecolorr; linestyler8label)autolim)tightz/The following kwargs were not used by contour: z, )Dr"__init__rrLr:r=r>r?r4rrDrE_set_colorizer_check_keywordsr@r?rr]LogNormrD LogLocatorlogscaler check_in_listrOrSrercParams_orig_linestylesrF _process_args_process_levels _extend_min _extend_max is_color_likerr^ set_underset_overrmrset_cmapset_norm callbacksblockedr@rA_changed_process_colorsr"_make_paths_from_contour_generator warn_external_get_lowers_and_uppersrr_process_linewidths_process_linestylesadd_collection_mins_maxs sticky_edgesr&r'update_datalimautoscale_viewrSjoinmaprepr)!rnaxrLr:r;r<r=rr>r?r?r4r@r@rArBrrCrDrErrFrGargskwargscolor_sequencencolorsruse_set_under_over total_levelslowersuppersr#s! r,r]zContourSet.__init__Ssf  6K $              . .yt48t48 / I>>D>>D tW__ -dllF,=,=> DM|(!DM !#45##MM."45 d   MM$  YY ( ( ( : &!% !%   &   ;; AACDK ;;%""#FG!88:NFF HH zz(A.   HH 33J?22:>zz(A."     u 5"&**Q-A!?A"&**Q-A!?A   $**djj!9:   t ,     A #dF+,-  S & &s 'V55V?c|jDcgc]*}|jDcgc]}|jc},c}}Scc}wcc}}wr) get_pathsrrrnr.subps r,zContourSet.sA!%# $%#?#?#AB4B%#B%#A A A A c|jDcgc]*}|jDcgc]}|jc},c}}Scc}wcc}}wr)rrrrs r,rzContourSet.sA!&# !" < < >??&#?&#rc"|jSr)rrns r,rzContourSet."s $.."2r.c|jSr)rdrs r,rzContourSet.#s t'<'<r.cH|j'|jj|_|jSt|jtj s@t |jdr*|jj|j|_|jS)z9Return the `.Transform` instance used by this ContourSet._as_mpl_transform) _transformrrr mtransforms Transformhasattrrrs r,rzContourSet.get_transform%sr ?? ""ii11DOT__k.C.CD$//+>?"oo?? JDOr.cD|jj}d|d<|S)N_contour_generator)__dict__copy)rnstates r, __getstate__zContourSet.__getstate__.s& ""$'+"# r.r&cg}g}|jr%|j\}}t|j}t |D]}|j t jddd|j||j|t|jz|||} |||} |dk(r'|jdvr|j d|d| d||dz k(r'|jd vr|j d|d | d|j d| d |d| d||fSt|jD]u\}} |j tgg|j||j||j!| |j d|d || dw||fS)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)rXhatchrrN$z \leq zs$rQz > z < )r linewidthrYz = )r:rtrOrrNrRmpatches Rectangle get_facecolorr=rrQrLr get_edgecolorget_linewidthsget_linestyles) rn variable_name str_formatartistsrjrrn_levelsrrJrKrs r,legend_elementszContourSet.legend_elements6s, ;;!88:NFF4;;'HX Px11Aq"00237,,sS->'>?  #6#;/"6#;/!8  >MMQ}oVE7""EFHqL(T[[O-KMMQ}oSr"BCMMQugSveWA"NO P0( 4 K Uv,,.s3"113C8"113C8    =/Z5F4GqIJ Kr.c |d|_|d}t|dkDr|dnd}tj|j|_tj |j|_||Dcgc]}dgt|z}}|jr/t|t|jdz k7r7tdt|t|jk7r tdt|t|k7r td|Dcgc] }|D]}| }}}tj|d} | j d|_ | jd|_ t||D cgc]&\}} tjtt|| (c} }|_|Scc}wcc}}wcc} }w) z Process *args* and *kwargs*; override in derived classes. Must set self.levels, self.zmin and self.zmax, and update Axes limits. rrr;Nz-must be one less number of segments as levelsz)must be same number of segments as levelsz(allkinds has different length to allsegsrv)rLrOrZrRzmaxrOzminr:rSrrxryrr rr~r) rnrrallsegsallkindssegssegr flatseglistrkindss r,rezContourSet._process_argsls 1g q'!$i!m47FF4;;' FF4;;'  7>?tT*?H? ;;7|s4;;/!33 "*++7|s4;;// !LMM x=CL (GH H%,9SS9q9q9 9 !4ZZQZ' ZZQZ' +.gx*@B&4..D$0FGB  ;@ :Bs3F6F;+Gc |j |jS|j}ttjd}|j r$t |jg|jnt |j|j}|Dcgc]D\}}t|r2ttj|tj|n|Fc}}Scc}}w)z$Compute ``paths`` using C extension.)rr;) rrr rZemptyr:r~create_filled_contourrtcreate_contourrLrOr)rncg empty_pathvertices_and_codesvsr(s r,rrz-ContourSet._make_paths_from_contour_generators ;; ";;   $ $"((6*+ {{ (( I4+F+F+H I !!4;; /  12BADBR^^B');rrunderroverrs r,_autolevzContourSet._autolevs; << }}%002 %11!a%QG ll&&tyy$))< ||&& '  3?+A.e*U2Y!zz# /*1-IT!Wq[3s8 ;;/ ) !GB ;;/ ) !GB 7Q;CB2bz!   sE E"!E"cX|j:|r|d}n>tj|tr|jrgd}ndg}nd}n |j}t |t r|j||_n)tj|tj|_|jr#t|jdkr tdt|jdkDrAtjtj|jd kr td yy) zH Determine the contour levels and store in self.levels. Nr)r?rrr;z*Filled contours require at least 2 levels.rgz!Contour levels must be increasing)rLrZ issubdtypeboolr:rrrasarrayfloat64rOrSrOr)rnrz_dtype levels_args r,_process_contour_level_argsz&ContourSet._process_contour_level_argss ;; !!W w-;;!+J"$J J j( +-- 3DK**Z ?@E"-"5K{#d*"-et"4K!!IJJr.c|jr td|tt|j}t j }dx}x}}|D]}|j|}d} |jD]r} t| js|jj| j} t| |\} } }| |kr| }|}|d| z}| }| t| z } t|||fS)a 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 contoursNrr) r:rSrNrOrrZinfrrrrr5)rnxyrod2minrrproj_min idx_levelr idx_vtx_startr lcd2rlegs r,rz ContourSet._find_nearest_contour}s6 ;;FG G ?C ,-G155 5 h .I;;y)DM::< .7++,'')33G4D4DE ;B C D#:E$-M"%a&="8K#HW-  . .k833r.cdx}x}}t5}|s3|j|jtj|j ||f|\} } \} } ddd ut jgtt|j| j} | j d}|dk(r| n | | |dz z } |z dz |z dzz}| ||  |fS#1swYxYw)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)rrrrr;) r enter_context_cm_setrIdentityTransformrrZrr~rOrr searchsorted)rnr&r'ropixelsegmentrrstacki_leveli_vtxxminymin cc_cumlenss r,find_nearest_contourzContourSet.find_nearest_contoursD $##%" [ WE##DLL);;=%1%?@,0+E+Eq!fg+V (GULT4 W  N#c4;;w/JJLMNPJ --eW=G$\Euz'A+7N/NEq&1Q{*B%tR88! W Ws AC))C2c |j}t|}|jrtd|jDrt ||y|j}|jdk(rd}t|D]}tj|||g5|j|j|t|jz|j|g|j|t|jzg|j|t|jzg||t|z5t ||ddddddy#1swYxYw#1swY xYw)Nc3$K|]}|du ywrr)rrs r,rz"ContourSet.draw..s!JE%4-!Jsr)rU)r)rrr;r< edgecolors)rrOr:allr=r"r"get_edgecolorsr<rNrk _setattr_cmr get_arrayrr)rnrpathsn_pathsrrr#s r,r"zContourSet.draws_ e*{{c!JT\\!JJ GL " ((* ??a "J> 'C""4s = 't||ll3T\\):#:;~~',- //1#D#F+#F+&&)RVVAY/DJ&&)RVVAY/DJ"3 r.c.|jrd}nd}t|}d|cxkrdkr1nn.|^}}tj|}|j |\}}nEd|cxkrdkr"nn|^}}}}|j ||||\}}}nt j|d|tj|d }|jjt|_ |jjt|_|jre|jdkrVtj |dk|}t j"d |jjt|_|j%||j&|||fS) Ncontourfcontourrr;rMz from 1 to 4)takesgivenF)rz,Log scale: values of z <= 0 have been masked)r:rOrr_initialize_x_y _check_xyzr nargs_errormasked_invalidrRastypefloatrrOrra masked_wherersrdtype) rnrrfnnargsr&r&r'z_origs r,rzQuadContourSet._contour_argsBsC ;;BBD  u>>HA 1 A''*DAq ^!^"& Aq&4ooaFF;GAq!""2]%H H   ae ,EEGNN5) EEGNN5) ==TYY!^Q*A   M Nu-DI ((qww71ayr.c|jjd|fd|fg|\}}tj|tj}tj|tj}t j|}|j dk7rtd|j d|jddks|jddkrtd |j|j\}}|j |j k7r&td |j d |j d |j dk(rd|j\}|j\}||k7rtd |d|d||k7rtd|d|dtj||\}}n|j dk(r~|j|jk7r&td|jd|jd|j|jk7r?td|jd|jdtd|j d|||fS)z Check that the shapes of the input arrays match; if x and y are 1D, convert them to 2D using meshgrid. r&r')r6r;Input z must be 2D, not Drr>Input z must be at least a (2, 2) shaped array, but has shape zNumber 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_inforZrrrndim TypeErrorshapemeshgrid) rnr&r'r&rNyNxnxnys r,r0zQuadContourSet._check_xyz]s: yy++c1XQx,@&I1 JJq + JJq + JJqM 66Q;6qvvha@A A 771:>QWWQZ!^--.WWI78 8B 66QVV 9!&&B !x~78 8 66Q;''CB''CBRx-t4113A!788Rx-t4..0T!455;;q!$DAq VVq[ww!''!"177)7177)=IKKww!''!"177)7177)=IKKCAFF81MN N!Qwr.c~|jdk7rtd|jd|jddks|jddkrtd|j|j\}}|j|jr?rZrCarangelinspace) rnr&rDrErrrrr&r'dxdys r,r/zQuadContourSet._initialize_x_ys 66Q;6qvvha@A A WWQZ!^qwwqzA~--.WWI78 8WWFB ;; {{"{{299R="))B-@@!%BBKKB+KKB+{{1a(( ;; Q^NBB![[NBB2g^2g^ "))B-#%+ + "))B-#%+ + ;;' !$B$A{{1a  r.)r$r%r&r'rerr0r/rr.r,rrs$04t8t6)V'!r.ra$ `.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 `_, consult the `ContourPy documentation `_ 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 `_ algorithm to compute contour locations. More information can be found in `ContourPy documentation `_. ) contour_doc)3r' contextlibrrhrnumbersrnumpyrZr matplotlibrerrmatplotlib.backend_basesrmatplotlib.linesr matplotlib.pathr matplotlib.textr matplotlib.tickerrD matplotlib.cmr_matplotlib.colorsr4r]matplotlib.collections collectionsmcollmatplotlib.font_managerrVmatplotlib.cbookrkmatplotlib.patchespatchesrmatplotlib.transforms transformsrr-r0r5interpdregister Collectionr8rparamsrr.r,rfs ! '0# "#&. %+:zzz !4H  4  R '!1!1R 'R 'j q!Zq!q!h t)hit) t!r.