+L iY. ldZddlZddlZddlZddlZddlZddlZddlm Z ddl m Z ddl m Z ddlmZddlmZdZd Zed d d d ddZdZe j*de j,de j.de j0de j2diZd!dZd"dZdZdZdZdZ dZ!dZ"dZ#d#dZ$dZ%d Z&y)$zk Utility Routines for Working with Matplotlib Objects ==================================================== N)colorConverter)Path) MarkerStyle)Affine2D)tickercZ|tj|ddk(rytj|ddk(r+tj|}djd|DStj|}dd j d |ddDzd zt |dzd zS) z8Convert matplotlib color code to hex color or RGBA colorNrnonez#{0:02X}{1:02X}{2:02X}c38K|]}td|zywN)int).0cs k/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/plotly/matplotlylib/mplexporter/utils.py zexport_color..s0K!S1W0Kzrgba(z, c 3pK|].}tttj|dz0ywr )strrnpround)rvals rrzexport_color..!s'G#Cs 345Gs46))rto_rgbato_rgbformatjoinr)colorrgbrs r export_colorr!s }..u5a8A=    &q )Q .##E*.'..0Ks0KLL  " "5 ) iiG2AGG H !A$i    cBtd|jDS)z5Convert a many-to-one mapping to a one-to-one mappingc38K|]\}}|D]}||f ywN)rkeysrkeys rrz_many_to_one..*s$OytS$O3c O Or)dictitems) input_dicts r _many_to_oner,(s OJ,<,<,>O OOr"r z6,6z2,2z4,4,2,4))solid-)NN)dashedz--)dotted:)dashdotz-.) Noner c@|jjdd)djtt|j S|j }tj|d}|dk(r-tjdj|td}|S)apGet an SVG dash array for the given matplotlib linestyle Parameters ---------- obj : matplotlib object The matplotlib line or path object, which must have a get_linestyle() method which returns a valid matplotlib line code Returns ------- dasharray : string The HTML/SVG dasharray code associated with the object. _dashSeqN,z not foundz:line style '{0}' not understood: defaulting to solid line.r-) __dict__getrmaprr7 get_linestyle LINESTYLESwarningswarnr)objls dasharrays r get_dasharrayrC8s || D)5xxC.//    NN2{3  # MMLSSTVW #7+Ir"LMSCZc||j|}|j|Dcgc]%\}}|tjk7r|ngt|f'}}}|st j dgfSt|\}}t jttj|jdd}|t|fScc}}w)aConstruct the vertices and SVG codes for the path Parameters ---------- path : matplotlib.Path object transform : matplotlib transform (optional) if specified, the path will be transformed before computing the output. Returns ------- vertices : array The shape (M, 2) array of vertices of the Path. Note that some Path codes require multiple vertices, so the length of these vertices may be longer than the list of path codes. path_codes : list A length N list of single-character path codes, N <= M. Each code is a single character, in ['L','M','S','C','Z']. See the standard SVG path specification for a description of these. )simplify)rrK) transformed iter_segmentsr CLOSEPOLY PATH_DICTrzerosziparraylist itertoolschainreshape)path transformrJvertices path_code vc_tuplescodess rSVG_pathr^\s* *&*%7%7%7%J !Xy$..0b)I:NOI xx##y/%88D(!;<=EEb!Le$$s*Cc,i}|j|d<|dd|d<t|j|d<|rt|j|d<nd|d<|j |d<t ||d<|j |d<|S) z4Get the style dictionary for matplotlib path objectsalphar edgecolor facecolorr edgewidthrBzorder) get_alphar! get_edgecolor get_facecolor get_linewidthrC get_zorder)rXfillstyles rget_path_stylerls E^^%E'N W~g%d&8&8&:;E+ )$*<*<*>?k#k++-E+&t,E+oo'E(O Lr"c i}|j|d<|dd|d<t|j|d<|j|d<t ||d<|j |d<|j |d<|S)z4Get the style dictionary for matplotlib line objectsr`r r linewidthrBrd drawstyle)rer! get_colorrhrCri get_drawstyle)linerks rget_line_stylerss E^^%E'N W~g!$.."23E'N++-E+&t,E+oo'E(O++-E+ Lr"ci}|j|d<|dd|d<t|j|d<t|j|d<|j |d<|j |d<t |j }|j}|jtj|| z}t|j||d<||d<|j|d <|S) z6Get the style dictionary for matplotlib marker objectsr`r rbrarcmarker markerpath markersizerd)rer!get_markerfacecolorget_markeredgecolorget_markeredgewidth get_markerrget_markersize get_transformrscaler^get_pathri)rrrk markerstylerwmarkertransforms rget_marker_stylers E^^%E'N W~g%d&>&>&@AE+%d&>&>&@AE+113E+oo'E(Odoo/0K$$&J!//1HJ4D4DZK5O#;#7#7#9?KE,$E,oo'E(O Lr"cXi}|j|d<|dd|d<|j|d<t|j|d<|j |d<|j |d<|j |d<|j|d<|j|d <|S) z.Return the text style dict for a text instancer`r fontsizerhalignvalignmalignrotationrd) reget_sizer!rpget_horizontalalignmentget_verticalalignment_multialignment get_rotationri)textrks rget_text_stylers E^^%E'N W~g E*!$.."23E'N224E(O002E(O**E(O))+E*oo'E(O Lr"cfi}|jjdd}t|tjj r|rd|d<nRd|d<nLt|tjj r|rd|d<n d|d<ntdj||j}t||d <t|tjrt||d <nd |d <|j}t|tjrd |d <nt|tj rt|j"|d <nyt|tj$r4t|j&j(dj+|d <n+t-d|j/Dsd |d <nd |d <|j1|d<|j/}|r|dj3|d<nd |d<t5||d<|j7|d<|S)z=Return the property dictionary for a matplotlib.Axis instancelabel1OnTbottompositiontopleftrightz{0} should be an Axis instancenticks tickvaluesNr3 tickformatrc3<K|]}|jywr%) get_visible)rlabels rrz&get_axis_properties..sH""$Hsr~rgridvisible)_major_tick_kwr: isinstance matplotlibaxisXAxisYAxis ValueErrorrget_major_locatorlenr FixedLocatorrTget_major_formatter NullFormatterFixedFormatterseq FuncFormatterfuncargsvaluesanyget_ticklabels get_scale get_fontsizeget_grid_styler)rpropsrlocator formatterlabelss rget_axis_propertiesrs E""&&z48H$ --.  (E*  %E*  D*//// 0  &E*  'E* 9@@FGG$$&G')nE(O'6../"79ol"l((*I)V112 l Iv44 5"9==1l Iv33 4"9>>#6#6q#9#@#@#BCl H$2E2E2GH H l"l^^%E'N "F "1I224j j#4(E&M'')E) Lr"c|j}|jdrZt|dkDrLt|dj }|dj }t |d}td|||SddiS)NgridOnrT)rrrBr`F) get_gridlinesrrr!rprerCr))r gridlinesrr`rBs rrrs|""$I 8$Y!);Yq\3356! &&(!)A,/ 4u OO%  r"cZ|j|j|jdS)N)figwidth figheightdpi) get_figwidth get_figheightr)figs rget_figure_propertiesr s+$$&&&(ww r"c t|jj|jj|j j |j |j|j|jjt|jt|jgd}dD]}t||dz}t|dj|}|}t|j t"j$j&r.d} ddl}ddlm}|t|j r|D cgc](} |j1t3| |j4*} } | D cgc]J} | j6| j8d z | j:| j<| j>| j@dfL}} nt"j$jC|D cgc]W} | j6| j8d z | j:| j<| j>| j@| jDd zfY}} n|jG}|d vr(tId j|jG|||d z<|||dz<|||dz<|S#t.$rd}YwxYwcc} wcc} wcc} w)N)axesbg axesbgalphaboundsdynamicaxisonframe_on patch_visibleaxes)xyrz get_{0}limdater)PeriodConverter)ordinalfreqr gMbP?)rlinearlogzUnknown axis scale: {0}r~limdomain)%r!patchrgre get_positionr get_navigater get_frame_onrrxaxisyaxisgetattrrr converterrdates DateConverterpandaspandas.tseries.converterr ImportErrorPeriodrryearmonthdayhourminutesecondnum2date microsecondrr) axraxnamerrrr~pdrd_datess rget_axes_propertiesrstrxx5578xx))+//#**??$))OO%--/$RXX.0CBHH0MN E'*r6F?+9\0089; dnnj&6&6&D&D EE #D~*T^^_"MMST"))CF)CTT$VVQWWq[!%%188QO(--66v> !  ,  NN$E 1 16==dnn>NOP P"'fw #fun#)fx O'*R LA  U s&, J0-KAK8AK 0 J?>J?c#Kt|drMt|jdkDr1|jD]}|s|t||D]}|y|yw)z Returns an iterator over all childen and nested children using obj's get_children() method if skipContainers is true, only childless objects are returned. get_childrenrN)hasattrrriter_all_children)r@skipContainerschild grandchilds rrrMsjsN#C,<,<,>(?!(C%%' !E! /~F !    !  ! sAA!cT|j\}}|j}|||dS)N)handlesrr)get_legend_handles_labelsr)rlegendrrrs rget_legend_propertiesr_s/224OGV  "G&W EEr"cj|j}tj}|j}|j|j |j ||j||j dtj|jjdS)a$ Convert a matplotlib image to a base64 png representation Parameters ---------- image : matplotlib image object The image to be converted. Returns ------- image_base64 : string The UTF8-encoded base64 string representation of the png image. rzutf-8) rioBytesIOr get_extent write_pngseekbase64 b64encodereaddecode)imager binary_bufferrs rimage_to_base64res BJJLM '')CGGE    OOM"GGCLq   M..0 1 8 8 AAr")NF)T)F)'__doc__rUrrnumpyrr>rmatplotlib.colorsrmatplotlib.pathrmatplotlib.markersrmatplotlib.transformsrrr!r,r=rCLINETOMOVETOCURVE3CURVE4rOrPr^rlrsrrrrrrrrrr&r"rrs  , ** $P &,$#'  8 KKKKKKKKNNC   #%L" .  7t!5p$F Br"