rL i~dZddlZddlmZddlmZddlZddlZ ddl m Z m Z ddl mZmZddlmZGd d Zd Zy) a A module for dealing with the polylines used throughout Matplotlib. The primary class for polyline handling in Matplotlib is `Path`. Almost all vector drawing makes use of `Path`\s somewhere in the drawing pipeline. Whilst a `Path` instance itself cannot be drawn, some `.Artist` subclasses, such as `.PathPatch` and `.PathCollection`, can be used for convenient `Path` visualisation. N) lru_cache)WeakValueDictionary)_api_path)_to_unmasked_float_arraysimple_linear_interpolation) BezierSegmentc \eZdZdZej ZedZedZedZ edZ edZ edZ edede de de de diZ d9d Zed:d Zed Zd ZedZej*dZedZej*dZedZej*dZedZej*dZedZdZdZd:dZedZedZdZdZ d;dZ!d Z"d!Z#dd)Z*d>d*Z+d+Z,d?d,Z-dZ.ed-Z/e0Z1ed.Z2e0Z3ed@d/Z4ed0Z5dZ6ed1Z7edAd2Z8dZ9ed3Z:edBd4Z;ed:d5Zd6dCd7Z?d>d8Z@y)DPathu A series of possibly disconnected, possibly closed, line and curve segments. The underlying storage is made up of two parallel numpy arrays: - *vertices*: an (N, 2) float array of vertices - *codes*: an N-length `numpy.uint8` array of path codes, or None These two arrays always have the same length in the first dimension. For example, to represent a cubic curve, you must provide three vertices and three `CURVE4` codes. The code types are: - `STOP` : 1 vertex (ignored) A marker for the end of the entire path (currently not required and ignored) - `MOVETO` : 1 vertex Pick up the pen and move to the given vertex. - `LINETO` : 1 vertex Draw a line from the current position to the given vertex. - `CURVE3` : 1 control point, 1 endpoint Draw a quadratic Bézier curve from the current position, with the given control point, to the given end point. - `CURVE4` : 2 control points, 1 endpoint Draw a cubic Bézier curve from the current position, with the given control points, to the given end point. - `CLOSEPOLY` : 1 vertex (ignored) Draw a line segment to the start point of the current polyline. If *codes* is None, it is interpreted as a `MOVETO` followed by a series of `LINETO`. Users of Path objects should not access the vertices and codes arrays directly. Instead, they should use `iter_segments` or `cleaned` to get the vertex/code pairs. This helps, in particular, to consistently handle the case of *codes* being None. Some behavior of Path objects can be controlled by rcParams. See the rcParams whose keys start with 'path.'. .. note:: The vertices and codes arrays should be treated as immutable -- there are a number of optimizations and assumptions made up front in the constructor that will not change when the data changes. rrONFcft|}tjd||t|rt j ||j }|jdk7st|t|k7r%td|jd|jt|r|d|jk7rtd|jd |d|rbt|rWt jt||j }|j|d<|j|dd |j|d <||_||_||_|j#|rJd |jj$_|jd |jj$_d |_yd |_y)a Create a new path with the given vertices and codes. Parameters ---------- vertices : (N, 2) array-like The path vertices, as an array, masked array or sequence of pairs. Masked values, if any, will be converted to NaNs, which are then handled correctly by the Agg PathIterator and other consumers of path data, such as :meth:`iter_segments`. codes : array-like or None, optional N-length array of integers representing the codes of the path. If not None, codes must be the same length as vertices. If None, *vertices* will be treated as a series of line segments. _interpolation_steps : int, optional Used as a hint to certain projections, such as Polar, that this path should be linearly interpolated immediately before drawing. This attribute is primarily an implementation detail and is not intended for public use. closed : bool, optional If *codes* is None and closed is True, vertices will be treated as line segments of a closed polygon. Note that the last vertex will then be ignored (as the corresponding code will be set to `CLOSEPOLY`). readonly : bool, optional Makes the path behave in an immutable way and sets the vertices and codes as read-only arrays. )Nr )verticesNrz`'codes' must be a 1D list or array with the same length of 'vertices'. Your vertices have shape z but your codes have shape rz7The first element of 'code' must be equal to 'MOVETO' (z). Your first code is dtypeFT)rr check_shapelennpasarray code_typendim ValueErrorshapeMOVETOemptyLINETO CLOSEPOLY _vertices_codes_interpolation_steps_update_valuesflags writeable _readonly)selfrcodesr$closedreadonlys U/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/matplotlib/path.py__init__z Path.__init__cs<,H5 X6  XJJudnn5EzzQ#e*H "= "==E^^>Ckk]"LMM5zeAh$++5 "115 >77>1ae*-d;;r/c>tjd|_|jdkDxrotjdxrZt|jdk\xr@|j duxs0t j|j tjk|_ y)Nr1rz path.simplify) r5r6r4rr"r#rallr r r3r)s r-r%zPath._update_valuess#&<<0I#J  $ $q ( H LL ) H  3 & H[[D FBFF4;;$+++E$F r/c|jS)z.The vertices of the `Path` as an (N, 2) array.)r"rCs r-rz Path.verticess~~r/c`|jr td||_|jy)Nz%Can't set vertices on a readonly Path)r(AttributeErrorr"r%)r)rs r-rz Path.verticess( >> !HI I! r/c|jS)a\ The list of codes in the `Path` as a 1D array. Each code is one of `STOP`, `MOVETO`, `LINETO`, `CURVE3`, `CURVE4` or `CLOSEPOLY`. For codes that correspond to more than one vertex (`CURVE3` and `CURVE4`), that code will be repeated so that the length of `vertices` and `codes` is always the same. )r#rCs r-r*z Path.codess{{r/c`|jr td||_|jy)Nz"Can't set codes on a readonly Path)r(rFr#r%)r)r*s r-r*z Path.codess( >> !EF F  r/c|jS)zi The fraction of a pixel difference below which vertices will be simplified out. r4rCs r-simplify_thresholdzPath.simplify_thresholds '''r/c||_yNrJ)r) thresholds r-rKzPath.simplify_thresholds #, r/c|jS)zD `True` if the vertices array should be simplified. r3rCs r-should_simplifyzPath.should_simplifys $$$r/c||_yrMrP)r)rQs r-rQzPath.should_simplifys /r/c|jS)z4 `True` if the `Path` is read-only. )r(rCs r-r,z Path.readonly s ~~r/c,tj|S)z~ Return a shallow copy of the `Path`, which will share the vertices and codes with the source `Path`. )copyrCs r-rUz Path.copys yyr/c t|}|j|x|t|<}|jj D]&\}}t ||t j||(d|_|S)zz Return a deepcopy of the `Path`. The `Path` will not be readonly, even if the source `Path` is. F) typer2id__dict__itemssetattrrUdeepcopyr()r)memor7pkr>s r- __deepcopy__zPath.__deepcopy__sm 4j [[--RXMM'') 2DAq Aq$--40 1 2 r/c.tj||S)aq Return a deep copy of the `Path`. The `Path` will not be readonly, even if the source `Path` is. Parameters ---------- memo : dict, optional A dictionary to use for memoizing, passed to `copy.deepcopy`. Returns ------- Path A deep copy of the `Path`, but not readonly. )rUr\)r)r]s r-r\z Path.deepcopy&s}}T4((r/ct|j\}}}|dk7r td|dz}||z}tj|df}tj||j |j }|j|dd|<|j||d|<t|D]} |dd| f|| d|<|||S)z Make a compound `Path` object to draw a number of polygons with equal numbers of sides. .. plot:: gallery/misc/histogram_path.py Parameters ---------- XY : (numpolys, numsides, 2) array r z%The third dimension of 'XY' must be 2rrrN) rrrzerosfullr rrr!range) r7XYnumpolysnumsidestwostridenvertsr8r*is r-make_compound_path_from_polysz"Path.make_compound_path_from_polys7s#%(((C !8DE EAF"&!% #--@::aii"%--hx (A!!Q$xE!)V)  (5%  r/c*|s0ttjddgtjStj|Dcgc]}|j c}}tjt ||j}d}|D]a}t |j }|j'|r7|j||<|j||dz||zn|j||||z||z }c||jk7}|||||Scc}w)z] Concatenate a list of `Path`\s into a single `Path`, removing all `STOP`\s. rr rr) r rrfloat32r=rrrr*rr STOP)r7argspathrr*rlsize not_stop_masks r-make_compound_pathzPath.make_compound_pathSs !Qrzz:; ;>>T"BT4=="BCXcmm<  Dt}}%Dzz!"zzE!H(+ E!A#af%"&**a$ IA ) 8M*E-,@AA#CsDc<d|jd|jdS)NzPath(z, ))rr*rCs r-__repr__z Path.__repr__is t}}'r$**q99r/c,t|jSrM)rrrCs r-__len__z Path.__len__ls4==!!r/?c #Kt|sy|j||||||||} |j} |j} t | j } t | j } t| | D]V\}}|| k(ry| |dz }|r:t|D],}t| tj|t| }.||fXyw)aN Iterate over all curve segments in the path. Each iteration returns a pair ``(vertices, code)``, where ``vertices`` is a sequence of 1-3 coordinate pairs, and ``code`` is a `Path` code. Additionally, this method can provide a number of standard cleanups and conversions to the path. Parameters ---------- transform : None or :class:`~matplotlib.transforms.Transform` If not None, the given affine transformation will be applied to the path. remove_nans : bool, optional Whether to remove all NaNs from the path and skip over them using MOVETO commands. clip : None or (float, float, float, float), optional If not None, must be a four-tuple (x1, y1, x2, y2) defining a rectangle in which to clip the path. snap : None or bool, optional If True, snap all nodes to pixels; if False, don't snap them. If None, snap if the path contains only segments parallel to the x or y axes, and no more than 1024 of them. stroke_width : float, optional The width of the stroke being drawn (used for path snapping). simplify : None or bool, optional Whether to simplify the path by removing vertices that do not affect its appearance. If None, use the :attr:`should_simplify` attribute. See also :rc:`path.simplify` and :rc:`path.simplify_threshold`. curves : bool, optional If True, curve segments will be returned as curve segments. If False, all curves will be converted to line segments. sketch : None or sequence, optional If not None, must be a 3-tuple of the form (scale, length, randomness), representing the sketch parameters. N) transform remove_nansclipsnap stroke_widthsimplifycurvessketchr) rcleanedNUM_VERTICES_FOR_CODErpiterrr*ziprenextrappend)r)r}r~rrrrrrrrrprr* curr_verticescodeextra_verticesrls r- iter_segmentszPath.iter_segmentsosR4y ,,+6T$(|(0&, .!% : :yy(()W]]##&x#7 & M4t|2481N  !((*I%%ffdIF}}V$$r/cV||j}tj|d||S)z Return whether this (closed) path completely contains the given path. If *transform* is not ``None``, the path will be transformed before checking for containment. N)rr path_in_path)r)rrr}s r- contains_pathzPath.contains_pathhs/  !((*I!!$dI>>r/c ddlm}||j|}|j |j}nt t j|jtjtjgdk(rL|jt j|jtjtjg}n`g}|jdi|D]4\}}|j\}}|j!|dg|d6t j"|}t |r*||j%d|j'dgS|j)S)a Get Bbox of the path. Parameters ---------- transform : `~matplotlib.transforms.Transform`, optional Transform to apply to path before computing extents, if any. **kwargs Forwarded to `.iter_bezier`. Returns ------- matplotlib.transforms.Bbox The extents of the path Bbox([[xmin, ymin], [xmax, ymax]]) rBboxr)axisr) transformsrrr*rrr intersect1dr rrisinrr raxis_aligned_extremarr=minmaxnull) r)r}rrxyscurver_dzeross r- get_extentszPath.get_extentsss* %  ++D1D :: --C  T[[$++,FG HA M -- )-dkk(B!DECC/t//9&9 3 t!668 6 5!fa12  3 ..%C s8a#''q'/:; ;99; r/c0tj|||S)z Return whether if this path intersects another given path. If *filled* is True, then this also returns True if one path completely encloses the other (i.e., the paths are treated as filled). )rpath_intersects_path)r)otherfilleds r-intersects_pathzPath.intersects_paths))$v>>r/ctj||j|j|j|j |S)a Return whether this path intersects a given `~.transforms.Bbox`. If *filled* is True, then this also returns True if the path completely encloses the `.Bbox` (i.e., the path is treated as filled). The bounding box is always considered filled. )rpath_intersects_rectanglex0y0x1y1)r)bboxrs r-intersects_bboxzPath.intersects_bboxs4.. $''477DGGTWWf> >r/cdk(st|dk(r|S|jA|j|jddvr&|jfd|j DS|j|j |jvrt j|j|j|j k(|jdk(s:|jj}|d||j|j k(<n |j}t|}|j}|Kt jt|dz zdztj|j}||dd<nd}t||S)a Return a new path with each segment divided into *steps* parts. Codes other than `LINETO`, `MOVETO`, and `CLOSEPOLY` are not handled correctly. Parameters ---------- steps : int The number of segments in the new path for each in the original. Returns ------- Path The interpolated path. rrNc3@K|]}|jywrM) interpolated).0r^stepss r- z$Path.interpolated..sSA!..'Ssr)rr*rrurr!rrBrrUr rdr r r)r)rrr* new_codess ` r-rzPath.interpolatedsS A:TaK :: !dkkTZZ^&C*4**S1P1P1RSU U :: !dnn &B266 djjDNN:;t}}Q?OOLQ}}))+H5=a[HTZZ4>>1 2}}H.x?   Ua5 81 DD <"%%i+-;?1KKuuqy!EOORVVE]BFF5M$BCEuTD9Db :>**;7 r/c|dkr|jj||f}nd}||dz}dtjz|z tj|dzz}|tjdz z }tj |dz}||ddd<|tj tj|tj|fzj}||dd}|dkr||j||f<|S)z Return a :class:`Path` for a unit regular star with the given numVertices and radius of 1.0, centered at (0, 0). rNr rg@Tr) _unit_regular_starsrrrronesvstackrrT)r7r innerCirclerrns2rrr8s r-unit_regular_starzPath.unit_regular_star.s " **.. [/IJDD </CruuWS[299S1W#55E RUUS[ Ea A!AaddGBFF5M266%=#ABBEEEuTD9Db FJ''k(BC r/c&|j|dS)z Return a :class:`Path` for a unit regular asterisk with the given numVertices and radius of 1.0, centered at (0, 0). )r)r7rs r-unit_regular_asteriskzPath.unit_regular_asteriskFs $$[#66r/cd|j|jddd|_|jS)z Return the readonly :class:`Path` of the unit circle. For most cases, :func:`Path.circle` will be what you want. )rrrT)centerrr,) _unit_circlecirclers r- unit_circlezPath.unit_circlePs9    #"zz37 * 9C r/cd}tjd}||z}tjddg|dg||z | |z g|| g||z| |zgd| gddgd|g||z||z g||g||z ||zg|dgddg| dg| |z||zg| |g| |z ||z gd|gddgd| g| |z | |zg| | g| |z| |z g| dgddgddggt}|jgdz}|j |d<|j |d <t||z|z|| S) u Return a `Path` representing a circle of a given radius and center. Parameters ---------- center : (float, float), default: (0, 0) The center of the circle. radius : float, default: 1 The radius of the circle. readonly : bool Whether the created path should have the "readonly" argument set when creating the Path instance. Notes ----- The circle is approximated using 8 cubic Bézier curves, as described in Lancaster, Don. `Approximating a Circle or an Ellipse Using Four Bezier Cubic Splines `_. rSl??rr{rrrr,)rsqrtrfloatrrr!r ) r7rrr,MAGICSQRTHALFMAGIC45rr*s r-rz Path.circle\s,773<U"88c4[#T]&w. '0AB& 2&w. '0AB!E6]!3Z!5\&w.0@A&1&w.0@A#S\!3Z$fc]'i/'1AB'i2'i/'1AB"E]"C["UF^'i/(71BC'i(3'i/(71BC$fd^!4[!4[E"*F#(G#)J r!::aMMb Hv%.IIr/c|jd}tjd}||z}tjddg|dg||z | |z g|| g||z| |zgd| gddgd|g||z||z g||g||z ||zg|dgddgddggt}tj d|j |j}|j|d<|j|d <|||d |_|jS) z Return a `Path` of the right half of a unit circle. See `Path.circle` for the reference on the approximation used. rrrrr{rrrTr) _unit_circle_righthalfrr rr rdrrrr!)r7r r r rr*s r-unit_circle_righthalfzPath.unit_circle_righthalfs/  % % -Ewws|H&Gxxt7"XIg$56XI&7"XIg$56vsu7"HW$45H%7"HW$45st%(+H.GGB #--@EzzE!H E"I),Xut)LC &)))r/ctjdz}|}|dtj||z dz zz }||k7r ||kr|dz }tj||g\}}|'t dtj ||z |z z}|dkr t d||z |z }tjd|z} tj|tjdd| z| zzdz zdz } tj|||dzd } tj| } tj| } | dd }| dd }| }|}| dd}| dd}| }|}|r|d zd z}tj|dft}tj||j|j }|d|dg|d<|j"|j$g|dd|j$|j&g|ddd}|dz }np|d zdz}tj(|dft}tj||j|j }|d|dg|d<|j"|d<d}|}|| |zz|||d df<|| |zz|||d df<|| |zz ||dz|d df<|| |zz ||dz|d df<|||dz|d df<|||dz|d df<|||d S)a Return a `Path` for the unit circle arc from angles *theta1* to *theta2* (in degrees). *theta2* is unwrapped to produce the shortest arc within 360 degrees. That is, if *theta2* > *theta1* + 360, the arc will be from *theta1* to *theta2* - 360 and not a full circle plus some extra overlap. If *n* is provided, it is the number of spline segments to make. If *n* is not provided, the number of spline segments is determined based on the delta between *theta1* and *theta2*. Masionobe, L. 2003. `Drawing an elliptical arc using polylines, quadratic or cubic Bezier curves `_. rihNr rzn must be >= 1 or Noneg@g@Trrrrrrr)rrfloordeg2radintceilrtanrr linspacerrcr rdrrrr r!r)r7theta1theta2nis_wedgehalfpieta1eta2detatalpharcos_etasin_etaxAyAxA_dotyA_dotxByBxB_dotyB_dotlengthrr* vertex_offsetends r-arczPath.arcs($bhh3'>??? V  CKDZZt - d 9A$+!7889A q556 6t q  FF3: t cAgk(9 :Q >?#E D$At4&&-&&- Sb\ Sb\ QR[ QR[ UQYFxx U3HGGFCJJcmmDEa5"Q%.HQK**cjj1E!AJ**cmm4E"#JM1*CUQYFxx U3HGGFCJJcmmDEa5"Q%.HQKzzE!HMC+-+>s1$a'(+-+>s1$a'(-/%&.-@qQ&)*-/%&.-@qQ&)*-/qQ&)*-/qQ&)*8UT22r/c*|j|||dS)ap Return a `Path` for the unit circle wedge from angles *theta1* to *theta2* (in degrees). *theta2* is unwrapped to produce the shortest wedge within 360 degrees. That is, if *theta2* > *theta1* + 360, the wedge will be from *theta1* to *theta2* - 360 and not a full circle plus some extra overlap. If *n* is provided, it is the number of spline segments to make. If *n* is not provided, the number of spline segments is determined based on the delta between *theta1* and *theta2*. See `Path.arc` for the reference on the approximation used. T)r0)r7rrrs r-wedgez Path.wedges wwvvq$//r/c(ddlm}| |||SdS)z Given a hatch specifier, *hatchpattern*, generates a `Path` that can be used in a repeated hatching pattern. *density* is the number of lines per unit square. r)get_pathN)matplotlib.hatchr5) hatchpatterndensityr5s r-hatchz Path.hatch-s& .+w/ 715 7r/ctj|||}|Dcgc] }t|}}|j|Scc}w)a. Clip the path to the given bounding box. The path must be made up of one or more closed polygons. This algorithm will not behave correctly for unclosed paths. If *inside* is `True`, clip to the inside of the box, otherwise to the outside of the box. )rclip_path_to_rectr ru)r)rinsider8polypathss r- clip_to_bboxzPath.clip_to_bbox9sG''dF;(-.d..&t&&../s?)NrFFrM)NTNFr{NTN)NFN)Nr)T)NrrT)r))rrr{F)NF))A__name__ __module__ __qualname____doc__ruint8rrprr rrr!rr. classmethodr;r?r%propertyrsetterr*rKrQr,rUr`r\rmrurxrzrrrrrrrrrrrrrrrrrrrrrrrrrrr0r2 staticmethodrr9r?rr/r-r r s'5nI Q&)P-9^O##12*./.77L    AJAJF"'*'*RL3L3\00"q\77 /r/r cddlm}t|dk(r tdt|dk(r tdt j ||t j|||\}}|j|d|iS)u  Get bounding box of a `.PathCollection`\s internal objects. That is, given a sequence of `Path`\s, `.Transform`\s objects, and offsets, as found in a `.PathCollection`, return the bounding box that encapsulates all of them. Parameters ---------- master_transform : `~matplotlib.transforms.Transform` Global transformation applied to all paths. paths : list of `Path` transforms : list of `~matplotlib.transforms.Affine2DBase` If non-empty, this overrides *master_transform*. offsets : (N, 2) array-like offset_transform : `~matplotlib.transforms.Affine2DBase` Transform applied to the offsets before offsetting the path. Notes ----- The way that *paths*, *transforms* and *offsets* are combined follows the same method as for collections: each is iterated over independently, so if you have 3 paths (A, B, C), 2 transforms (α, β) and 1 offset (O), their combinations are as follows: - (A, α, O) - (B, β, O) - (C, α, O) rrrzNo paths providedzNo offsets providedminpos) rrrrrget_path_collection_extentsr atleast_3d from_extents)master_transformr>roffsetsoffset_transformrextentsrKs r-rLrLHsz<! 5zQ,-- 7|q.//77%z!:!#OGV 4  g 5f 55r/)rDrU functoolsrweakrefrnumpyr matplotlibr5rrcbookrr bezierr r rLrr/r-rZs6  'H!m/m/`!&6r/