*L i\ddlmZddlmZddlmZmZmZddl m Z m Z m Z ddl mcmZddlZddlZddlmZ ddlZdZgZdd Zd Zdddidddddddddddddddddd d d dfdej8fdZy#e$rdZY=wxYw)N)ColorscaleValidator)apply_default_cascade init_figureconfigure_animation_controls)rescale_intensity_integer_ranges_integer_types)image_array_to_data_uriTFc"|dk(rdnd}||Stj|r |gdz|gzSt|dk(rt|dz|gzSt|dk(rt||gzSt|dk(r|St dt |z)Nmaxrrz\zmax can be a scalar, or an iterable of length 1, 3 or 4. A value of %s was passed for zmax.)npisscalarlenlist ValueErrorstr)zmodealphas \/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/plotly/express/_imshow.py_vectorize_zvaluers5=CaEy QsQw%  Q1Aw{eW$$ Q1Aw%  Q1 136q6 :  c|jj}d}|tvr t|dS|t j |j }|d|zkry|d|zkry|d|zkryy)Ng?rril)dtypetyper r risfiniter )imgdtrtolim_maxs r_infer_zmax_from_typer%'sx B D ^r"1%%R[[%&**, QX  sTz ! ut| #rautorpngreturnc t}t||j}d}|gt|tr|j j |}|j|}t|}| t| n|}||zr||zdzn||z}nd}d}|Et|tr|j j |}|j|}t|} |du|duz}!d}"d}#d}$trTt|tjr9t|j }%d}$g}&|F|j|j |j}|&j!||j |}"|F|j|j |j} |&j!||j |}#t#|&dD]}'|%j%|'}(|%d|%d}*})|*|)fD]m}+t'j(|j|+j*t&j,s?|j|+j/t|j|+<o||j|*j}||j|)j}|d}|j1dd|*|d<|j1d d|)|d <|j1d d|#|d <|j1d d|"|d <|j1d dytj2j4j7||d <|d j9d d|d <n3t;|drit;|j<drS| |j<}|j1dd3t;|j<dr|j<j>xsd|d<t;|drit;|j drS| |j }|j1d d3t;|j dr|j j>xsd|d <|j1ddd|d<|j1d dd|d <|j1d dd|d <|d}tAjB|d}t|t@jDr|r tGdd},nd},t'jH|}|%t'jJ||d}| ||kr|dz }d}|4t'jJ||d}d}|j1d d n|d |d <d}-||-tfz }-||-t|fz }-||jLd|!zk\xr|, }|j*tNk(r"d|j/t&jPz}| |d}|d}||jLd|!zk(rdnd}|dk(r-||r||jS}||rC|A|jU}n0|(|j*t&jPk7r tW|}||d}|jLd|!zk(rJ|sG|!}.|&|j|.tY|k7r tGd|!dz}/|&|j|/tY|k7r tGdd}0|durd}0n |durd |zd!z}0t[t]j^|-D12cgc],\}1}2tajb||||2d"t |1|0#.}3}1}2|d$k(rdnd%}4tete|4&'}5|dk(rted d()|5d*<d(|5d+d,<tgd-d.}6te|6ji|d/| ||0|5d"<|d rte|d 1|5d"d2<n|jLdk\r|jd3d4vs|!r|s|jLdk(r|rd}7||tk|d56tk|d76}}d8\}8}9}:};d9}<|et'jH|}t'j(|j*t&jlr|d}8|d|dz }:n|$r|d}7n|jLd|!zk(r%to||d|dft&jP<}>nbt'jpt|jd3D?cgc]+}?to|d=|?f||?||?ft&jP<-c}?d3>}>t]j^|-D2cgc]}2ts|>|2|||?}@}2t[|@D1Acgc])\}1}Atajt|At |1|8|9|:|;@+}3}1}AnS|jd3dk(rdAndB}Bt]j^|-D2cgc]"}2tajt||2||B|8|9|:|;C$}3}2i}5|d$k(s|;|;dkrted&|5d+<|:6|:dkr1ted%&|5d*<n!tGdDt |jzg}C|,|j1d d n|d }DD1cgc] }1DdE|1 }C}1tw|dFg||Cg}EdGD]}F||Fs |F|5|F<|dHr |dH|5dI<n*|dJjxjzj|dKdLi|5dM<g}Gt[|3D]5\}'}H|r|'||zks|'dk(sEjH||'|zz |'|zdzN7|Ott D]7\}1}'Gj!te|3||1z||1dzz|5t |'O9|rGE_AEj|5|r17r/t'j|>k(s|dxsddP|d xsd dQ}InfHdRdSk(rd}Jn8|jLdk(rdT}Jn&|jLdk(r|jd3dk(rdU}Jnd}J|dxsddP|d xsd dV|d xsd dWJdX}IEjIY|drEj|ddZ|d rEj|d d[t|t`jtE|Ej|dJd\|EScc}2}1wcc}?wcc}2wcc}A}1wcc}2wcc}1w)]al Display an image, i.e. data on a 2D regular raster. Parameters ---------- img: array-like image, or xarray The image data. Supported array shapes are - (M, N): an image with scalar data. The data is visualized using a colormap. - (M, N, 3): an image with RGB values. - (M, N, 4): an image with RGBA values, i.e. including transparency. zmin, zmax : scalar or iterable, optional zmin and zmax define the scalar range that the colormap covers. By default, zmin and zmax correspond to the min and max values of the datatype for integer datatypes (ie [0-255] for uint8 images, [0, 65535] for uint16 images, etc.). For a multichannel image of floats, the max of the image is computed and zmax is the smallest power of 256 (1, 255, 65535) greater than this max value, with a 5% tolerance. For a single-channel image, the max of the image is used. Overridden by range_color. origin : str, 'upper' or 'lower' (default 'upper') position of the [0, 0] pixel of the image array, in the upper left or lower left corner. The convention 'upper' is typically used for matrices and images. labels : dict with str keys and str values (default `{}`) Sets names used in the figure for axis titles (keys ``x`` and ``y``), colorbar title and hoverlabel (key ``color``). The values should correspond to the desired label to be displayed. If ``img`` is an xarray, dimension names are used for axis titles, and long name for the colorbar title (unless overridden in ``labels``). Possible keys are: x, y, and color. x, y: list-like, optional x and y are used to label the axes of single-channel heatmap visualizations and their lengths must match the lengths of the second and first dimensions of the img argument. They are auto-populated if the input is an xarray. animation_frame: int or str, optional (default None) axis number along which the image array is sliced to create an animation plot. If `img` is an xarray, `animation_frame` can be the name of one the dimensions. facet_col: int or str, optional (default None) axis number along which the image array is sliced to create a facetted plot. If `img` is an xarray, `facet_col` can be the name of one the dimensions. facet_col_wrap: int Maximum number of facet columns. Wraps the column variable at this width, so that the column facets span multiple rows. Ignored if `facet_col` is None. facet_col_spacing: float between 0 and 1 Spacing between facet columns, in paper units. Default is 0.02. facet_row_spacing: float between 0 and 1 Spacing between facet rows created when ``facet_col_wrap`` is used, in paper units. Default is 0.0.7. color_continuous_scale : str or list of str colormap used to map scalar data to colors (for a 2D image). This parameter is not used for RGB or RGBA images. If a string is provided, it should be the name of a known color scale, and if a list is provided, it should be a list of CSS- compatible colors. color_continuous_midpoint : number If set, computes the bounds of the continuous color scale to have the desired midpoint. Overridden by range_color or zmin and zmax. range_color : list of two numbers If provided, overrides auto-scaling on the continuous color scale, including overriding `color_continuous_midpoint`. Also overrides zmin and zmax. Used only for single-channel images. title : str The figure title. template : str or dict or plotly.graph_objects.layout.Template instance The figure template name or definition. width : number The figure width in pixels. height: number The figure height in pixels. aspect: 'equal', 'auto', or None - 'equal': Ensures an aspect ratio of 1 or pixels (square pixels) - 'auto': The axes is kept fixed and the aspect ratio of pixels is adjusted so that the data fit in the axes. In general, this will result in non-square pixels. - if None, 'equal' is used for numpy arrays and 'auto' for xarrays (which have typically heterogeneous coordinates) contrast_rescaling: 'minmax', 'infer', or None how to determine data values corresponding to the bounds of the color range, when zmin or zmax are not passed. If `minmax`, the min and max values of the image are used. If `infer`, a heuristic based on the image data type is used. binary_string: bool, default None if True, the image data are first rescaled and encoded as uint8 and then passed to plotly.js as a b64 PNG string. If False, data are passed unchanged as a numerical array. Setting to True may lead to performance gains, at the cost of a loss of precision depending on the original data type. If None, use_binary_string is set to True for multichannel (eg) RGB arrays, and to False for single-channel (2D) arrays. 2D arrays are represented as grayscale and with no colorbar if use_binary_string is True. binary_backend: str, 'auto' (default), 'pil' or 'pypng' Third-party package for the transformation of numpy arrays to png b64 strings. If 'auto', Pillow is used if installed, otherwise pypng. binary_compression_level: int, between 0 and 9 (default 4) png compression level to be passed to the backend when transforming an array to a png b64 string. Increasing `binary_compression` decreases the size of the png string, but the compression step takes more time. For most images it is not worth using levels greater than 5, but it's possible to test `len(fig.data[0].source)` and to time the execution of `imshow` to tune the level of compression. 0 means no compression (not recommended). binary_format: str, 'png' (default) or 'jpg' compression format used to generate b64 string. 'png' is recommended since it uses lossless compression, but 'jpg' (lossy) compression can result if smaller binary strings for natural images. text_auto: bool or str (default `False`) If `True` or a string, single-channel `img` values will be displayed as text. A string like `'.2f'` will be interpreted as a `texttemplate` numeric formatting directive. Returns ------- fig : graph_objects.Figure containing the displayed image See also -------- plotly.graph_objects.Image : image trace plotly.graph_objects.Heatmap : heatmap trace Notes ----- In order to update and customize the returned figure, use `go.Figure.update_traces` or `go.Figure.update_layout`. If an xarray is passed, dimensions names and coordinates are used for axes labels and ticks. rNFT)reverserr&xyanimation_frame facet_colcolor z
columns__len__nameindexequal) pass_throughz0Binary strings cannot be used with pandas arraysrrminmaxinferzZThe length of the y vector must match the length of the first dimension of the img matrix.z[The length of the x vector must match the length of the second dimension of the img matrix.z%{z}z%{z:} coloraxis1)r+r,r coloraxisr3 texttemplatelowerreversed) autorange)yaxisdomain) scaleanchor constrainxaxisrCrF colorscaleimshowcolor_continuous_scale)rHcmidcmincmax) title_textcolorbar)rrmin)rr )NNNNzNon-numerical coordinates were passed with xarray `img`, but the Image trace cannot handle it. Please use `binary_string=False` for 2D data or pass instead the numpy array `img.values` to `px.imshow`.zUOnly numerical values are accepted for the `x` parameter when an Image trace is used.zUOnly numerical values are accepted for the `y` parameter when an Image trace is used.)in_range out_range.)axis)backend compressionext)sourcer3x0y0dxdyrgbrgba256)rzminzmax colormodelrYrZr[r\zpx.imshow only accepts 2D single-channel, RGB or RGBA images. An image of shape %s was provided. Alternatively, 3- or 4-D single or multichannel datasets can be visualized using the `facet_col` or/and `animation_frame` arguments.=xy)heightwidthtitlerNtemplatet<margin)rowcol)datalayoutr3z : %{x}
z: %{y}rheatmapz%{z[0]}z[%{z[0]}, %{z[1]}, %{z[2]}]z : %{y}
z: z) hovertemplate)rNrk)rNrl)rg overwrite)Hlocalsrcopy isinstancerdimsr5shaperangeintxarray_importedxarray DataArrayrcoordsvaluesappendsortedpopr issubdtyper datetime64astypegetplotutilslabel_from_attrsreplacehasattrr1r3nw from_native DataFramer asanyarraymoveaxisndimbooluint8r rQr%r enumerate itertoolsproductgoHeatmapdictrvalidate_coercernumberrstackr Imagerrnrjrh add_tracezipframes update_layoutall update_traces update_xaxes update_yaxesr)Kr!r_r`originlabelsr+r,r-r.facet_col_wrapfacet_col_spacingfacet_row_spacingrJcolor_continuous_midpoint range_colorrfrgrerdaspectcontrast_rescaling binary_stringbinary_backendbinary_compression_level binary_format text_autoargs nslices_facet facet_slicesncolsnrowsnslices_animationanimation_slicesslice_dimensions facet_labelanimation_label img_is_xarrayru pop_indexesr5_y_labelx_labelax is_dataframe iterablesy_indexx_indexr?i index_tuptracesrBrncolorscale_validator rescale_imagerYrZr[r\error_msg_xarray error_msg img_rescaledchimg_str img_str_slicera col_labels slice_labelfig attr_name frame_listtracerp hover_namesK rrIrI8s f 8D$ [[]FM i %y1I ), ]+ '5'AN#}u$ U "Q &%'  " os +!hhnn_=OIIo6 !23!-t#KOM:c6+;+;<CHH~   ::chhy&9:AAL   y )((9-K  &"zz#((?*CDKK     /!hh7OK6 EA 7DGG$ F ::c4 (!F3K ::c4 (!F3K ::' . 6(7F$ % ::k4 ( 0"-F;  ::gt $ ,$kk//@@EF7O$Wo55dFCF7O 3 "ws{{I'FyKKzz#t$,f1M!kk..4"s 3 WSYY %ByIIzz#t$,F1K!iinn2s ::c4 (F3K ::c4 (F3K ::gt $ , F7O >F ..4 0C#r||$ OP P   -- Ckk#y!,  &?Y+F q O "kk#2zz+,4 )*  I"e-.00 eM*,, Q)9%9:O ( +* 8% G)2'(:$A} CFrbRTVWF #&))B-1"4)J"+!2!2I!> )n)  F  W BF"T2F7O >b1f"Z8F7O S#))n    J!::k2:K{@S 5AAq Qqc*A A dD"eUJ CC(0  ? $YF9 0 G}#G}| j  ' ' ) ) 19xJ!&)T u %%%-/EQJ MM%UUe^%;QRARM ST"E"346FG HAu     1MQU4KL!U   frvvc\6I/J 3K 3  3K 3  =I %J XX]"J XX]syy}16JJ 3K 3  3K 3  7O &w &   M2 c{ F3KQ7 c{ F3KQ7 rxx5tJ/4@ JQ  j BBs$1r?0s*s .s/'s s)r )plotly.graph_objs graph_objsr_plotly_utils.basevalidatorsr_corerrr imshow_utilsrr r narwhals.stable.v1stablev1rnumpyrr plotly.utilsr rzry ImportError _float_typesrr%FigurerIr8rrrs<SSLL0O  &&     "     5e6YY7eUOsA33A=<A=