rL i@jdZddlZddlZddlmZddlmZddl m Z ddl m Z ddl mZddlmZmZGd d ZGd d eZGd deZGddeZGddeZGddZGddZGddZGddeZGddej6ZGddeZeZeZy)a Axislines includes modified implementation of the Axes class. The biggest difference is that the artists responsible for drawing the axis spine, ticks, ticklabels and axis labels are separated out from Matplotlib's Axis class. Originally, this change was motivated to support curvilinear grid. Here are a few reasons that I came up with a new axes class: * "top" and "bottom" x-axis (or "left" and "right" y-axis) can have different ticks (tick locations and labels). This is not possible with the current Matplotlib, although some twin axes trick can help. * Curvilinear grid. * angled ticks. In the new axes class, xaxis and yaxis is set to not visible by default, and new set of artist (AxisArtist) are defined to draw axis line, ticks, ticklabels and axis label. Axes.axis attribute serves as a dictionary of these artists, i.e., ax.axis["left"] is a AxisArtist instance responsible to draw left y-axis. The default Axes.axis contains "bottom", "left", "top" and "right". AxisArtist can be considered as a container artist and has the following children artists which will draw ticks, labels, etc. * line * major_ticks, major_ticklabels * minor_ticks, minor_ticklabels * offsetText * label Note that these are separate artists from `matplotlib.axis.Axis`, thus most tick-related functions in Matplotlib won't work. For example, color and markerwidth of the ``ax.axis["bottom"].major_ticks`` will follow those of Axes.xaxis unless explicitly specified. In addition to AxisArtist, the Axes will have *gridlines* attribute, which obviously draws grid lines. The gridlines needs to be separated from the axis as some gridlines can never pass any axis. N)_api)Path)mpl_axes) AxislineStyle) AxisArtistGridlinesCollectionc(eZdZdZdZdZdZdZy)_AxisArtistHelperBaseaf Base class for axis helper. Subclasses should define the methods listed below. The *axes* argument will be the ``.axes`` attribute of the caller artist. :: # Construct the spine. def get_line_transform(self, axes): return transform def get_line(self, axes): return path # Construct the label. def get_axislabel_transform(self, axes): return transform def get_axislabel_pos_angle(self, axes): return (x, y), angle # Construct the ticks. def get_tick_transform(self, axes): return transform def get_tick_iterators(self, axes): # A pair of iterables (one for major ticks, one for minor ticks) # that yield (tick_position, tick_angle, tick_label). return iter_major, iter_minor c||_yN nth_coord)selfrs g/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/mpl_toolkits/axisartist/axislines.py__init__z_AxisArtistHelperBase.__init__Ws "cyr raxess r update_limz _AxisArtistHelperBase.update_limZs rc|jSr rrs r get_nth_coordz#_AxisArtistHelperBase.get_nth_coord] ~~rc|jdk(r+tjtj||dS|jdk(r+tjtj||dSt d)aP Create a (*values.shape, 2)-shape array representing (x, y) pairs. The other coordinate is filled with the constant *const*. Example:: >>> self.nth_coord = 0 >>> self._to_xy([1, 2, 3], const=0) array([[1, 0], [2, 0], [3, 0]]) raxisrzUnexpected nth_coord)rnpstackbroadcast_arrays ValueError)rvaluesconsts r_to_xyz_AxisArtistHelperBase._to_xy`sd >>Q 88B//>RH H ^^q 88B//v>RH H34 4rN)__name__ __module__ __qualname____doc__rrrr'rrrr r 5sB# 5rr cneZdZdZej ddd fd ZdZdZdZ dZ d Z xZ S) _FixedAxisArtistHelperBasez7Helper class for a fixed (in the axes coordinate) axis.3.9rc t|tjddddd|||_ddddd||_t |jd|j |_y)z5``nth_coord = 0``: x-axis; ``nth_coord = 1``: y-axis.rrbottomtopleftright)locrrr&N) superrr check_getitem_loc_posrr'_path)rr5r __class__s rrz#_FixedAxisArtistHelperBase.__init__ysh ++A :E F  AB3G $++fDII+>? rc|jSr )r<rs rget_linez#_FixedAxisArtistHelperBase.get_lines zzrc|jSr  transAxesrs rget_line_transformz-_FixedAxisArtistHelperBase.get_line_transformrrc|jSr rArs rget_axislabel_transformz2_FixedAxisArtistHelperBase.get_axislabel_transformrrc:tdddd|jS) Return the label reference position in transAxes. get_label_transform() returns a transform of (transAxes+offset) ))?Z))?rIrJ))rIrHr))rIrKr)r3r4r1r2)dictr:rs rget_axislabel_pos_anglez2_FixedAxisArtistHelperBase.get_axislabel_pos_angles* ))&()- 3 3rc\|j|jg|jSr )get_xaxis_transformget_yaxis_transformrrs rget_tick_transformz-_FixedAxisArtistHelperBase.get_tick_transforms(((*D,D,D,FGWWrr ) r(r)r*r+rdelete_parameterrr?rCrErMrQ __classcell__r=s@rr-r-vsCAT5+.@/@  3Xrr-c$eZdZfdZdZxZS)_FloatingAxisArtistHelperBasec2||_t| |yr )_valuer8r)rrvaluer=s rrz&_FloatingAxisArtistHelperBase.__init__s  #rctd)Nz6get_line method should be defined by the derived class) RuntimeErrorrs rr?z&_FloatingAxisArtistHelperBase.get_linesSTTr)r(r)r*rr?rSrTs@rrVrVs$UrrVcReZdZejdddfd ZdZxZS) FixedAxisArtistHelperRectilinearr.rcxt|||j|jg|j|_y)z nth_coord = along which coordinate value varies in 2D, nth_coord = 0 -> x axis, nth_coord = 1 -> y axis N)r8rxaxisyaxisrr )rrr5rr=s rrz)FixedAxisArtistHelperRectilinear.__init__s/ ZZ,T^^< rc dddj\ jj}|j}|jj |}jj }|j}|jj |}j||jz fd}||||||fS) tick_loc, tick_angle, tick_labelrJrrrJr6c3Kt||D]i\}}j|j} j|}tj j d|jsb||fkyw)Nr7r6)zipr'r; transformmpl transforms_interval_contains_closer) locslabelsr5labelcc2 angle_normal angle_tangentr tick_to_axess r_fz?FixedAxisArtistHelperRectilinear.get_tick_iterators.._fsu!$/ @ UKK499K5!++A.>>::62dnnCUV\=%??  @s A.A=2 A=) rr majorlocator formatter format_ticksminorrQrB) rrrt major_locs major_labelsrx minor_locs minor_labelsrsrprqrrs ` @@@rget_tick_iteratorsz3FixedAxisArtistHelperRectilinear.get_tick_iteratorss*1g&>t~~&N# m ]]_ 33J?  ]]_ 33J? ..t4t~~E  @*l+R L-IIIrr )r(r)r*rrRrr}rSrTs@rr]r]s*T5+.=/=Jrr]cFeZdZ dfd ZdZdZdZdZdZdZ xZ S) #FloatingAxisArtistHelperRectilinearct|||||_|j|jg|j |_yr )r8r_axis_directionr_r`rr )rrrpassingthrough_pointaxis_directionr=s rrz,FloatingAxisArtistHelperRectilinear.__init__s8 $89-ZZ,T^^< rcd|jz }|j|jz }|j|j|jg}t |j d||S)Nrr6r7)r transDatarBrgrXrr')rr fixed_coord data_to_axesps rr?z,FloatingAxisArtistHelperRectilinear.get_lines[$..( ~~6  " "DKK#= >DKKa nK=>>rc|jSr rArs rrCz6FloatingAxisArtistHelperRectilinear.get_line_transformrrc|jSr rArs rrEz;FloatingAxisArtistHelperRectilinear.get_axislabel_transformrrcddg|j}d|jz }|j|jz }|j|j|jg}|j d||}d||cxkrdkr||fSdS)rGrrJrrIr7)NN)rrrBrgrXr')rranglerrrvertss rrMz;FloatingAxisArtistHelperRectilinear.get_axislabel_pos_angles B'$..( ~~6  " "DKK#= > Cq~ 6!"eK&8!=A!=u~O!=<Orc|jSr )rrs rrQz6FloatingAxisArtistHelperRectilinear.get_tick_transformrrc dddj\ jj}|j}|jj |}jj }|j}|jj |}|j|jz fd}||||||fS)rbrcrdr6c3Kt||D]\\}} j| j} j|\}}d|cxkrdksCnFd|cxkrdksRnU||f^yw)Nr7rr)rfr'rXrg) rkrlr5rmrnc1rorprqrrs rrszBFloatingAxisArtistHelperRectilinear.get_tick_iterators.._fsq!$/ @ UKK4;;K7%//2Bt~~&N# m ]]_ 33J?  ]]_ 33J? ~~6  @*l+R L-IIIrr1) r(r)r*rr?rCrErMrQr}rSrTs@rrrs-7?= ?  PJrrceZdZeZeZy)AxisArtistHelperN)r(r)r*r-FixedrVFloatingrrrrr s &E,HrrceZdZeZeZy)AxisArtistHelperRectlinearN)r(r)r*r]rrrrrrrrs ,E2Hrrc0eZdZfdZdZdZdZxZS)GridHelperBasec0d|_t| yr ) _old_limitsr8r)rr=s rrzGridHelperBase.__init__s rc|j\}}|j\}}|j||||fk7r |j||||||||f|_yyr )get_xlimget_ylimr _update_grid)rrx1x2y1y2s rrzGridHelperBase.update_limsaBB   BB/ /   b"b" - "BB/D  0rcy)z>Cache relevant computations when the axes limits have changed.Nr)rrrrrs rrzGridHelperBase._update_grid#srcgS)z Return list of grid lines as a list of paths (list of points). Parameters ---------- which : {"both", "major", "minor"} axis : {"both", "x", "y"} r)rwhichr s r get_gridlineszGridHelperBase.get_gridlines&s  r)r(r)r*rrrrrSrTs@rrrs0M rrcheZdZfdZej ddd d dZd dZd dZxZ S) GridHelperRectlinearc0t|||_yr )r8rr)rrr=s rrzGridHelperRectlinear.__init__4s  rr.rz''nth_coord' is now inferred from 'loc'.)addendumc|!tjd|j}||}t|t ||||S)Nz6'new_fixed_axis' explicitly requires the axes keyword.)offsetr)r warn_externalrrr])rr5rrrrs rnew_fixed_axisz#GridHelperRectlinear.new_fixed_axis8sO <   H J99D  ! N$ @s K!'H Hrc|!tjd|j}t||||}t |||}|j j d|j j|jj|S)Nz9'new_floating_axis' explicitly requires the axes keyword.)rT) rrrrrline set_clip_on set_clip_boxbbox)rrrYrrhelperaxislines rnew_floating_axisz&GridHelperRectlinear.new_floating_axisEsv <   K M99D4 )UN4dF>J !!$' ""8==#5#56rctjgd|tjgd|g}|dvrg}|jj\|dvr=|j |jj j j|dvr=|j |jj jj|j fd|D|d vr|jj\g}|jjjd r=|j |jjj j|jjjd r=|j |jjjj|j fd |D|S) z Return list of gridline coordinates in data coordinates. Parameters ---------- which : {"both", "major", "minor"} axis : {"both", "x", "y"} )bothrtrx)r)rxyr)rr)rrt)rrxc3.K|] }||gggywr r).0rrrs r z5GridHelperRectlinear.get_gridlines..es>Aq!fr2h/>)rrgridOnc3.K|] }g||ggywr r)rrrrs rrz5GridHelperRectlinear.get_gridlines..ns>Ar2hA/>r) r check_in_listrrextendr_rtrurxrr`_major_tick_kw_minor_tick_kw) rrr gridlinesrkrrrrs @@@@rrz"GridHelperRectlinear.get_gridlinesQsj 5UC -D9 = DYY'')FB)) DIIOO1199;<)) DIIOO1199;<   >> > = YY'')FBDyy--h7 DIIOO1199;<yy--h7 DIIOO1199;<   >> >r)NNNN)r1N)rtr) r(r)r*rrrRrrrrSrTs@rrr2sFT {%NPOS HP H rrcreZdZddfd Zd dZedZfdZdZd fd Z fd Z d d Z dd Z xZ S)AxesN) grid_helperc|d|_|r|n t||_t||i||j dy)NT) _axisline_onr _grid_helperr8rtoggle_axisline)rrargskwargsr=s rrz Axes.__init__us> +6K> 9 ; Cd3G G ; </1IJ 9H NN & &u -  % % 1 1% 8  % % 1 1% 8 9 ;sFc|jSr )rrs rrzAxes.get_grid_helpers   rc t||f||d||jsy||jjj dxsm|jjj dxsH|jjj dxs#|jjj d}|jj||||jjdi|y)zW Toggle the gridlines, and optionally set the properties of the lines. )rr Nr)rr visibler) r8gridrrr_rrr`rset)rrrr rr=s rrz Axes.grids  W?E??   ?yy55h?C))//88BC))//88BC))//88B  T7C$V$rc|jr)g|jj|j}ng}|j t ||Sr )rrr%rrr8 get_children)rchildrenr=s rrzAxes.get_childrensJ   B//1B4>>BHH,./rcF|jj|||S)N)rr)rr)rr5rs rrzAxes.new_fixed_axiss###%44Sd4SSrcH|jj||||S)N)rr)rr)rrrYrs rrzAxes.new_floating_axiss.##%77 u^$8H Hrr )Nrtrr)r(r)r*rrpropertyr rrrrrrrSrTs@rrrssD*.# )98!%$THrrceZdZfdZxZS)AxesZeroc ft||jj}|jj |ddd||ddd|dD]R}|j|j j|j|j|jdTy) NrrHr1)rrYrrrr3)xzeroyzeroF) r8rrrrrrrrr)rrkr=s rrzAxesZero.clears   002DD #2hTK#2f4I  $ 2A OOA  # # 1 1$** = OOA  * *5 1 2r)r(r)r*rrSrTs@rrrs  2 2rr)r+numpyr! matplotlibrhrmatplotlib.axesrmaxesmatplotlib.pathrmpl_toolkits.axes_grid1raxisline_styler axis_artistrr r r-rVr]rrrrrrrSubplot SubplotZerorrrrs'R ,)8>5>5B(X!6(XVU$9U#J'A#JL9J*G9Jx-- 33 8>>>BXH5::XHv 2t 2  r