*L iSadZddlZddlZddlZddlmZmZddlmZgdZ gdZ iddd gd d d gd ddgdddgdddgdddgdddgdddgdddgdddgdd d!gd"d#d$gd%dd gd&dd'gd(d)d gd*dd+gd,d-d.gZ d/Z d0Z d1ZdCd2Zee_dDd3ZdEd4Z dFd5Zej(d6d7edGd8Zd9Zd:Zd;Zdd?gZGd@dAeZdBZy)HzB tools ===== Functions that USERS will possibly want access to. N) exceptionsoptional_imports) PLOTLY_DIR) zrgb(31, 119, 180)zrgb(255, 127, 14)zrgb(44, 160, 44)zrgb(214, 39, 40)zrgb(148, 103, 189)zrgb(140, 86, 75)zrgb(227, 119, 194)zrgb(127, 127, 127)zrgb(188, 189, 34)zrgb(23, 190, 207))TaskStartFinishGreysz rgb(0,0,0)zrgb(255,255,255)YlGnBuz rgb(8,29,88)zrgb(255,255,217)Greensz rgb(0,68,27)zrgb(247,252,245)YlOrRdz rgb(128,0,38)zrgb(255,255,204)Blueredz rgb(0,0,255)z rgb(255,0,0)RdBuz rgb(5,10,172)zrgb(178,10,28)Redszrgb(220,220,220)BluesPicnicRainbowz rgb(150,0,90)Portlandzrgb(12,51,131)zrgb(217,30,30)Jetz rgb(0,0,131)z rgb(128,0,0)Hot Blackbodyzrgb(160,200,255)Earthz rgb(0,0,130)Electriczrgb(255,250,220)Viridisz rgb(68,1,84)zrgb(253,231,37)z#1f77b4zprobability density probabilityc2|d|d|jd|dS)N:z: z: z )__name__)messagecategoryfilenamelinenofilelines R/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/plotly/tools.pywarning_on_one_liner%;s%-vx7H7H' RRcJtjd}|rw|j}|j|j ||r|j |r|j |rt|j|jStjdy)aConvert a matplotlib figure to plotly dictionary and send. All available information about matplotlib visualizations are stored within a matplotlib.figure.Figure object. You can create a plot in python using matplotlib, store the figure object, and then pass this object to the fig_to_plotly function. In the background, mplexporter is used to crawl through the mpl figure object for appropriate information. This information is then systematically sent to the PlotlyRenderer which creates the JSON structure used to make plotly visualizations. Finally, these dictionaries are sent to plotly and your browser should open up a new tab for viewing! Optionally, if you're working in IPython, you can set notebook=True and the PlotlyRenderer will call plotly.iplot instead of plotly.plot to have the graph appear directly in the IPython notebook. Note, this function gives the user access to a simple, one-line way to render an mpl figure in plotly. If you need to trouble shoot, you can do this step manually by NOT running this fuction and entereing the following: =========================================================================== from plotly.matplotlylib import mplexporter, PlotlyRenderer # create an mpl figure and store it under a varialble 'fig' renderer = PlotlyRenderer() exporter = mplexporter.Exporter(renderer) exporter.run(fig) =========================================================================== You can then inspect the JSON structures by accessing these: renderer.layout -- a plotly layout dictionary renderer.data -- a list of plotly data dictionaries zplotly.matplotlylibzTo use Plotly's matplotlylib functionality, you'll need to have matplotlib successfully installed with all of its dependencies. You're getting this error because matplotlib or one of its dependencies doesn't seem to be installed correctly.N) r get_modulePlotlyRendererExporterrunresize strip_styleprintmsg plotly_figwarningswarn)figr,r-verbose matplotlylibrenderers r$ mpl_to_plotlyr7CsD$../DEL..0h'++C0  OO    "  (,, """  C r&c ddlm}tjdt |t r|dkr t dt |t r|dkr t dddg}|jD] }||vst dj| t|d} t|d}t|j } d ||d z zz |z } d ||d z zz |z } d} t|D]} t|D]}d j| d z}dj| d z}| |z|z}|| z}dj| d z}dj| d z}| |z| z}|| z}t||g|}|| d|<t||g|}|| d|<| d z } |r]tdd}d }t|D]5} d}t|D]}|dj|z }|d z }|dz|z}7t||j| S#t$r d |z }YwxYw#t$r d |z }YwxYw)aqReturn a dictionary instance with the subplots set in 'layout'. Example 1: # stack two subplots vertically fig = tools.get_subplots(rows=2) fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2], xaxis='x1', yaxis='y1')] fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2], xaxis='x2', yaxis='y2')] Example 2: # print out string showing the subplot grid you've put in the layout fig = tools.get_subplots(rows=3, columns=2, print_grid=True) Keywords arguments with constant defaults: rows (kwarg, int greater than 0, default=1): Number of rows, evenly spaced vertically on the figure. columns (kwarg, int greater than 0, default=1): Number of columns, evenly spaced horizontally on the figure. horizontal_spacing (kwarg, float in [0,1], default=0.1): Space between subplot columns. Applied to all columns. vertical_spacing (kwarg, float in [0,1], default=0.05): Space between subplot rows. Applied to all rows. print_grid (kwarg, True | False, default=False): If True, prints a tab-delimited string representation of your plot grid. Keyword arguments with variable defaults: horizontal_spacing (kwarg, float in [0,1], default=0.2 / columns): Space between subplot columns. vertical_spacing (kwarg, float in [0,1], default=0.3 / rows): Space between subplot rows. r graph_objszJtools.get_subplots is depreciated. Please use tools.make_subplots instead.z5Keyword argument 'rows' must be an int greater than 0z8Keyword argument 'columns' must be an int greater than 0horizontal_spacingvertical_spacingzInvalid keyword argument: '{0}'g?g333333?)layoutzxaxis{0}zy{0}zyaxis{0}zx{0})domainanchorr=z%This is the format of your plot grid!z[{0}]  )plotly.graph_objsr:r1r2 isinstanceint ExceptionkeysformatfloatKeyErrordictLayoutranger.Figure)rowscolumns print_gridkwargsr: VALID_KWARGSkeyr;r<r3 plot_width plot_heightplot_numrrrccc xaxis_namex_anchorx_startx_end yaxis_namey_anchory_starty_endxaxisyaxis grid_stringplot grid_lines r$ get_subplotsrg|sR- MMT dC DAIOPP gs #w!|RSS)*<=L{{}K l "=DDSIJ JK +"6*>#?@& (:!;< j'') *C(GaK88GCJ'4!844 C#**8a<8J}}X\2H!$66#=Gj(E#**8a<8J}}X\2H"%55) stacklevel)rOcols shared_xaxes shared_yaxes start_cellrQ)plotly.subplotsr1r2DeprecationWarningsubplots make_subplots)rOrjrkrlrmrQrRplotlys r$rrrrs[z MM ;  )6?? ( (   !!    r&defaultz*plotly\.tools\.make_subplots is deprecatedcddlm} t||}||S#ttf$r%t j dj|wxYw)zReturns a new graph object. OLD FUNCTION: this will *silently* strip out invalid pieces of the object. NEW FUNCTION: no striping of invalid pieces anymore - only raises error on unrecognized graph_objs rr9z#'{}' is not a recognized graph_obj.)rCr:getattrAttributeErrorrJr PlotlyErrorrH)objobj_typer:clss r$ get_graph_objr|sZ- j(+ s8O H % $$ 1 8 8 B   s 4Act|tr;t}t|jD]\}}t |||<|St|tr.t}t |D]\}}|t |gz }|St|t r.|jdd}||k7rtjd|S|S)z9Replaces ' ' with '
' for all strings in a collection.rBz
aLooks like you used a newline character: '\n'. Plotly uses a subset of HTML escape characters to do things like newline (
), bold (), italics (), etc. Your newline characters have been converted to '
' so they will show up right on your Plotly figure!) rDrKlistitems_replace_newline enumeratestrreplacer1r2)rydrTvaltempindexentryss r$rrs#t FSYY[) +HC%c*AcF + C v%cN .LE5 %e,- -D . C  KKf % 8 MM2  r&cddlm}ddlm}d}t |t r|}nIt |t rd|i}n4t ||r|j}d}ntjd|r3|s1 |d i|j}|dstjd |S#tj$r)}tjdj|d}~wwxYw) Nr)rN) BaseFigureFdataTzuThe `figure_or_data` positional argument must be `dict`-like, `list`-like, or an instance of plotly.graph_objs.FigureaInvalid 'figure_or_data' argument. Plotly will not be able to properly parse the resulting JSON. If you want to send this 'figure_or_data' to Plotly anyway (not recommended), you can set 'validate=False' as a plot option. Here's why you're seeing this error: {0}zEmpty data list found. Make sure that you populated the list of data objects you're sending and try again. Questions? Visit support.plot.lyrn) rCrNplotly.basedatatypesrrDrKr~to_dictrrxrHPlotlyEmptyDataError)figure_or_datavalidate_figurerNr validatedfigureerrs r$!return_figure_from_figure_or_datar s(/I.$' ND ).) NJ /'') $$ S  y %f%--/Ff~113  M'%% ((6#;   s0B""C5$CCz#3D9970z#FF4136)scatter histogramboxcatseqceZdZeddZedZedZedZedZedZ edZ ed Z ed Z ed Z ed Zed ZedZedZedZy) FigureFactoryNcV||}tjdj||y)NzIplotly.tools.FigureFactory.{} is deprecated. Use plotly.figure_factory.{})r1r2rH) old_method new_methods r$ _deprecatedzFigureFactory._deprecatedAs*  #J  ++16*j+I r&cJtjddddlm}||i|S)Ncreate_2D_densitycreate_2d_densityr)r)rrplotly.figure_factoryr)argsrRrs r$rzFigureFactory.create_2D_densityKs'!!"57JK; $1&11r&cHtjdddlm}||i|S)Ncreate_annotated_heatmapr)r)rrrr)rrRrs r$rz&FigureFactory.create_annotated_heatmapR$!!"<=B'888r&cHtjdddlm}||i|S)Ncreate_candlestickr)r)rrrr)rrRrs r$rz FigureFactory.create_candlestickYs$!!"67<!42622r&cHtjdddlm}||i|S)Ncreate_dendrogramr)r)rrrr)rrRrs r$rzFigureFactory.create_dendrogram`$!!"56; $1&11r&cHtjdddlm}||i|S)Ncreate_distplotr)r)rrrr)rrRrs r$rzFigureFactory.create_distplotgs$!!"349///r&cHtjdddlm}||i|S)Ncreate_facet_gridr)r)rrrr)rrRrs r$rzFigureFactory.create_facet_gridnrr&cHtjdddlm}||i|S)N create_ganttr)r)rrrr)rrRrs r$rzFigureFactory.create_ganttu#!!.16T,V,,r&cHtjdddlm}||i|S)N create_ohlcr)r)rrrr)rrRrs r$rzFigureFactory.create_ohlc|s#!!-05D+F++r&cHtjdddlm}||i|S)N create_quiverr)r)rrrr)rrRrs r$rzFigureFactory.create_quiver#!!/27d-f--r&cHtjdddlm}||i|S)Ncreate_scatterplotmatrixr)r)rrrr)rrRrs r$rz&FigureFactory.create_scatterplotmatrixrr&cHtjdddlm}||i|S)Ncreate_streamliner)r)rrrr)rrRrs r$rzFigureFactory.create_streamlinerr&cHtjdddlm}||i|S)N create_tabler)r)rrrr)rrRrs r$rzFigureFactory.create_tablerr&cHtjdddlm}||i|S)Ncreate_trisurfr)r)rrrr)rrRrs r$rzFigureFactory.create_trisurfs$!!"238t.v..r&cHtjdddlm}||i|S)N create_violinr)r)rrrr)rrRrs r$rzFigureFactory.create_violinrr&N)r __module__ __qualname__ staticmethodrrrrrrrrrrrrrrrrnr&r$rr@s,  22 99 33 22 00 22 -- ,, .. 99 22 -- // ..r&rchtjjtd}d}tjj |s|St |d5} t j|}t|tsi}dddjd|S#t$ri}Y'wxYw#1swY,xYw)aD Function to get the .config file's 'plotly_domain' without importing the chart_studio package. This property is needed to compute the default value of the plotly.js config plotlyServerURL, so it is independent of the chart_studio integration and still needs to live in Returns ------- str z.configzhttps://plot.lyrtN plotly_domain) ospathjoinrexistsopenjsonloadrDrKrFget) config_filedefault_server_urlf config_dicts r$get_config_plotly_server_urlrs'',,z95K* 77>>+ &!! k4 A ))A,Kk40  ???,> ??  K  s*B('B B%"B($B%%B((B1)NN)FFF)r>r>F)r>r>FFztop-leftNr) __doc__rr1rrsrr plotly.filesrDEFAULT_PLOTLY_COLORSREQUIRED_GANTT_KEYS PLOTLY_SCALESDEFAULT_FILLCOLORDEFAULT_HISTNORMALTERNATIVE_HISTNORMr% formatwarningr7rgrrfilterwarningsrpr|rr_DEFAULT_INCREASING_COLOR_DEFAULT_DECREASING_COLOR DIAG_CHOICESVALID_COLORMAP_TYPESobjectrrrnr&r$rs  /# 2 l. / ~12 ~12  23  /   _. /  !1 2 o1 2 ~~.0!#34 NN + L, -, 23 n0 1 12!" 12# *($S-3 rg"V  nb <>P &8)Z&%. u~k.Fk.\@r&