rL i/ddlZddlmZmZddlmZmZdZ GddZ GddeZ Gd d Z Gd d ejZ Gd dZGddZGddZy)N)ticker_api)Bbox Transformc dg}|dd|ddz }tdtdddfD]}|j|\}}|j|\}}|j|\} } |j|\} } | || kDf| || kffD]\} }g}|dd|ddz j \}|D]r}||| ||z ||z||z z}| |cxkr| ksn+| |f|}t j t j||ddd}|j||ft|j| |S)a Find the points where a polyline crosses a bbox, and the crossing angles. Parameters ---------- xys : (N, 2) array The polyline coordinates. bbox : `.Bbox` The bounding box. Returns ------- list of ((float, float), float) Four separate lists of crossings, for the left, right, bottom, and top sides of the bbox, respectively. For each list, the entries are the ``((x, y), ccw_angle_in_degrees)`` of the crossing, where an angle of 0 means that the polyline is moving to the right at the crossing point. The entries are computed by linearly interpolating at each crossing between the nearest points on either side of the bbox edges. N) sliceTminmaxnonzeronpdegreesarctan2append)xysbbox crossingsdxysslusvsdusdvsuminvminumaxvmaxu0insidecrossidxsidxvcrossingthetas i/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/mpl_toolkits/axisartist/grid_finder.py_find_line_box_crossingsr)st,I qr7S"X DT{E$b12$rB66":SXXb\ dXXb\ d "t),tR$Y.?@ $JBECR[6!":-668ED 0sGrBsG|s3x7#c(BBq(D(72; 2::tCy2#?@ h./  0   U # $ $ c"eZdZdZdZdZdZy)ExtremeFinderSimplezU A helper class to figure out the range of grid lines that need to be drawn. c ||_||_y)zy Parameters ---------- nx, ny : int The number of samples in each direction. Nnxny)selfr/r0s r(__init__zExtremeFinderSimple.__init__7sr*ctjtj|||jtj|||j\}}|tj |tj |\}} |j |j|j| j| jS)ai Compute an approximation of the bounding box obtained by applying *transform_xy* to the box delimited by ``(x1, y1, x2, y2)``. The intended use is to have ``(x1, y1, x2, y2)`` in axes coordinates, and have *transform_xy* be the transform from axes coordinates to data coordinates; this method then returns the range of data coordinates that span the actual axes. The computation is done by sampling ``nx * ny`` equispaced points in the ``(x1, y1, x2, y2)`` box and finding the resulting points with extremal coordinates; then adding some padding to take into account the finite sampling. As each sampling step covers a relative range of *1/nx* or *1/ny*, the padding is computed by expanding the span covered by the extremal coordinates by these fractions. ) rmeshgridlinspacer/r0ravel_add_padr r ) r1 transform_xyx1y1x2y2xyxtyts r(__call__zExtremeFinderSimple.__call__As&{{ KKB ("++b"dgg*FH1bhhqk288A;7B}}RVVXrvvx2668DDr*cn||z |jz }||z |jz }||z ||z||z ||zfS)z,Perform the padding mentioned in `__call__`.r.)r1x_minx_maxy_miny_maxdxdys r(r7zExtremeFinderSimple._add_padYsEemtww &emtww &rz52:urz52:==r*N)__name__ __module__ __qualname____doc__r2rAr7r*r(r,r,2sE0>r*r,c6eZdZdZdxZZfdZdZdZxZ S)_User2DTransformz.A transform defined by two user-set functions.c>t|||_||_y)z Parameters ---------- forward, backward : callable The forward and backward transforms, taking ``x`` and ``y`` as separate arguments and returning ``(tr_x, tr_y)``. N)superr2_forward _backward)r1forwardbackward __class__s r(r2z_User2DTransform.__init__es  !r*cltj|jtj|SN)r transposerS)r1valuess r(transform_non_affinez%_User2DTransform.transform_non_affiness%||MDMM2<<+?@AAr*cNt||j|jSrY)typerTrSr1s r(invertedz_User2DTransform.invertedwstDz$..$--88r*) rIrJrKrL input_dims output_dimsr2r\r` __classcell__rWs@r(rOrO`s 8  J "B9r*rOcVeZdZdZ d dZdZdZdZdZdZ eZ d Z d Z d Z y) GridFinderz Internal helper for `~.grid_helper_curvelinear.GridHelperCurveLinear`, with the same constructor parameters; should not be directly instantiated. Nc| tdd}| t}| t}| t}| t}||_||_||_||_||_|j|y)N) r, MaxNLocatorFormatterPrettyPrintextreme_finder grid_locator1 grid_locator2tick_formatter1tick_formatter2 set_transform)r1 transformrkrlrmrnros r(r2zGridFinder.__init__s  !0R8N  'MM  'MM  "24O  "24O,**.. 9%r*ctj|j|jd|}t |t j r|j|S||||S)a Helper to support both standard formatters (inheriting from `.mticker.Formatter`) and axisartist-specific ones; should be called instead of directly calling ``self.tick_formatter1`` and ``self.tick_formatter2``. This method should be considered as a temporary workaround which will be removed in the future at the same time as axisartist-specific formatters. )rrP)r$)r check_getitemrnro isinstancemticker Formatter format_ticks)r1r$ directionfactorlevelsfmts r( _format_tickszGridFinder._format_tickss^  $$)=)= >CI,6sG T"R!U 8"b9RTV W '*:M(KTOD)$-T7 D)0051RSTT T 7  *24W+d2CD$W DD++CvtD#&r'{4'8&#A*KD%$)DM* * *(.Es 0 G Gc Ftj||d}tj||d}|D cgc](} |jtj|| |*} } |D cgc](} |j|tj|| *} } | | fScc} wcc} w)Nd)rr5r8 full_like) r1rrrrrrlons_ilats_irrrrs r(rzGridFinder._get_raw_grid_linessWgs3Wgs3!+,&&r||FC'@&I, ,!+,&&vr||FC/HI, ,)## ,,s -B&-Bct|tr||_yt|dk(r't t t |rt||_ytd)NrPzF'aux_trans' must be either a Transform instance or a pair of callables) rtr_aux_transformlenallmapcallablerO TypeError)r1 aux_transs r(rpzGridFinder.set_transformsM i +"+D  ^q SXy)A%B"2I">D >? ?r*c|jSrY)rr_s r( get_transformzGridFinder.get_transforms"""r*cv|jjtj||gjSrY)rrqrrr r1r=r>s r(r8zGridFinder.transform_xys,"",,R__aV-DEGGGr*c|jjjtj||gj SrY)rr`rqrrr rs r(rzGridFinder.inv_transform_xys9""++-77 OOQF #%%&Q 'r*c r|jD]$\}}|dvrt|||td|y)N)rkrlrmrnrozUnknown update property )itemssetattr ValueError)r1kwargskr%s r(updatezGridFinder.updatesKLLN CDAq(( a# #;A5!ABB Cr*)NNNNN)rIrJrKrLr2r|rrrprupdate_transformr8rrrMr*r(rfrf|sP!%##!%!% &0 54l $?#%H' Cr*rfc4eZdZ dfd ZfdZxZS)ricNt|||||||jy)N)stepsinteger symmetricprune)rRr2create_dummy_axis)r1nbinsrtrimrrrrWs r(r2zMaxNLocator.__init__ s. eW#,E  ;  r*cft|||}tj|t |dfSNr)rR tick_valuesrarrayr)r1v1v2locsrWs r(rAzMaxNLocator.__call__s-w"2r*xx~s4y!++r*) NTFFNrIrJrKr2rArcrds@r(riri s!'+  !,,r*riceZdZdZdZy) FixedLocatorc||_yrY)_locs)r1rs r(r2zFixedLocator.__init__s  r*ct||g\}}tj|jDcgc]}||cxkr|ksnn|c}}|t |dfScc}wr)sortedrrrr)r1rrrrs r(rAzFixedLocator.__call__ sRR!BxxDJJ@q"-R-@ASY!!As AANrIrJrKr2rArMr*r(rrs "r*rceZdZddZdZy)rjcptj|d|_|jjy)NF) useMathText useOffset)ruScalarFormatter_fmtr)r1rs r(r2zFormatterPrettyPrint.__init__)s)++#u6  ##%r*c8|jj|SrY)rrw)r1rxryr[s r(rAzFormatterPrettyPrint.__call__.syy%%f--r*N)TrrMr*r(rjrj(s & .r*rjc&eZdZdfd ZdZxZS) DictFormatterc>t|||_||_y)zq format_dict : dictionary for format strings to be used. formatter : fall-back formatter N)rRr2 _format_dict_fallback_formatter)r1 format_dict formatterrWs r(r2zDictFormatter.__init__3s '#, r*c|jr|j|||}ndgt|z}t||Dcgc]!\}}|jj ||#c}}Scc}}w)zG factor is ignored if value is found in the dictionary )rrrrget)r1rxryr[fallback_stringsrr%s r(rAzDictFormatter.__call__<sw  # ##7766 + !#tc&k1 (89;Aq!!%%a+; ;;s&A)rYrrds@r(rr2s - ;r*r)numpyr matplotlibrrurmatplotlib.transformsrrr)r,rOrfrirrjrrMr*r(rsj.1(V+>+>\9y98MCMC` ,'%% , ""..;;r*