rL i`ldZddlZddlmZmZddlmZmZddl m Z ddl m Z ddl mZdd lmZdd lmZGd d e ZeZGd deZej, ddZy)a$ Tables drawing. .. note:: The table implementation in Matplotlib is lightly maintained. For a more featureful table implementation, you may wish to try `blume `_. Use the factory function `~matplotlib.table.table` to create a ready-made table from texts. If you need more control, use the `.Table` class and its methods. The table consists of a grid of cells, which are indexed by (row, column). The cell (0, 0) is positioned at the top left. Thanks to John Gill for providing the class and table. N)_api _docstring)Artistallow_rasterization) Rectangle)Text)Bbox)Path)_is_pandas_dataframeceZdZdZdZ dZdedddZdd d dd d d dfd ZfdZfdZ dZ dZ dZ dZ efdZdZdZdZej(dZedZej0dZdZxZS)Cellz A cell is a `.Rectangle` with some associated `.Text`. As a user, you'll most likely not creates cells yourself. Instead, you should use either the `~matplotlib.table.table` factory function or `.Table.add_cell`. g?BRTLBTRL)openclosed horizontalverticalkwTrightNr) edgecolor facecolorfilltextlocfontproperties visible_edgesc t ||||||||jd| |_||_t |d|dd|| |d|_y)a Parameters ---------- xy : 2-tuple The position of the bottom left corner of the cell. width : float The cell width. height : float The cell height. edgecolor : :mpltype:`color`, default: 'k' The color of the cell border. facecolor : :mpltype:`color`, default: 'w' The cell facecolor. fill : bool, default: True Whether the cell background is filled. text : str, optional The cell text. loc : {'right', 'center', 'left'} The alignment of the text within the cell. fontproperties : dict, optional A dict defining the font properties of the text. Supported keys and values are the keyword arguments accepted by `.FontProperties`. visible_edges : {'closed', 'open', 'horizontal', 'vertical'} or substring of 'BRTL' The cell edges to be drawn with a line: a substring of 'BRTL' (bottom, right, top, left), or one of 'open' (no edges drawn), 'closed' (all edges drawn), 'horizontal' (bottom and top), 'vertical' (right and left). )widthheightrrrFrrcenter)xyclip_onrrhorizontalalignmentverticalalignmentN)super__init__ set_clip_onr _locr _text) selfxyr"r#rrrrrrr __class__s V/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/matplotlib/table.pyr+z Cell.__init__:sjN 5d#,   C * BqERUE#N.1XO c2t||d|_yNT)r* set_transformstale)r/tr1s r2r6zCell.set_transformls a  r3cZt|||jj|yN)r* set_figurer.)r/figr1s r2r;zCell.set_figureqs" 3 c"r3c|jS)z!Return the cell `.Text` instance.)r.r/s r2get_textz Cell.get_textus zzr3cH|jj|d|_y)zSet the text fontsize.TN)r. set_fontsizer7)r/sizes r2rAzCell.set_fontsizeys % r3c6|jjS)zReturn the cell fontsize.)r. get_fontsizer>s r2rDzCell.get_fontsize~szz&&((r3c|j}|j|}|dkDrS||jkDr@|dz}|j||j|}|dkDr||jkDr@|S)z9Shrink font size until the text fits into the cell width.r)rDget_required_width get_widthrA)r/rendererfontsizerequireds r2auto_set_font_sizezCell.auto_set_font_sizesz$$&**84lx$..*:: MH   h '..x8Hlx$..*:: r3c|jsyt| ||j||jj|d|_y)NF) get_visibler*draw_set_text_positionr.r7)r/rHr1s r2rNz Cell.drawsC!   X ) ! r3c|j|}|j|jdz z}|jj }|dk(r|j |j dz z}nU|dk(r'|j |j |jzz}n)|j |j d|jz zz}|jj||fy)z.Set text up so it is drawn in the right place.r$leftrN) get_window_extenty0r#r.get_horizontalalignmentx0r"PAD set_position)r/rHbboxr&rr%s r2rOzCell._set_text_positions%%h/ GGdkkAo %jj002 (?$**q.(A F]$**txx//A$**DHH 55A A'r3c|jj|j|jj j S)zY Return the text bounds as *(x, y, width, height)* in table coordinates. )r.rS transformedget_data_transforminvertedbounds)r/rHs r2get_text_boundszCell.get_text_boundss< ,,X6T446??AB r3cX|j|\}}}}|dd|jzzzS)z/Return the minimal required width for the cell.?g@)r_rW)r/rHlbrhs r2rFzCell.get_required_widths2))(3 1aC3>*++r3c H|jj|d|_y)zk Update the text properties. Valid keyword arguments are: %(Text:kwdoc)s TN)r._internal_updater7)r/kwargss r2set_text_propszCell.set_text_propss ##F+ r3c|jS)a" The cell edges to be drawn with a line. Reading this property returns a substring of 'BRTL' (bottom, right, top, left'). When setting this property, you can use a substring of 'BRTL' or one of {'open', 'closed', 'horizontal', 'vertical'}. )_visible_edgesr>s r2r zCell.visible_edgess"""r3c p|j_d_y|jvrj|_d_ytfd|DrNt dj |dj jdj j|_d_y)Nc3:K|]}|jvywr:_edges.0edger/s r2 z%Cell.visible_edges..s=t4t{{*=sz=Invalid edge param {}, must only be one of {} or string of {}z, T)rnrj _edge_aliasesany ValueErrorformatjoinr7r/values` r2r zCell.visible_edgess ="&++D  d(( ("&"4"4U";D  =u== "66> #(D  r3ctjg}|jfdjDtj|ddvrtj|d<tddgddgddgddgddgg|dS) z*Return a `.Path` for the `.visible_edges`.c3zK|]2}|jvrtjntj4ywr:)rjr LINETOMOVETOros r2rrz Cell.get_path..s3% 4#6#66DKKDKK G%s8;rNraT)readonly)r r}extendrn CLOSEPOLY)r/codess` r2get_pathz Cell.get_paths  % % % ;;eABi 'E"I3Z#sc3Z#sc3Z H  r3)__name__ __module__ __qualname____doc__rWrnrsr+r6r;r?rArDrKrrNrOr_rFrinterpdrhpropertyr setterr __classcell__r1s@r2rr's C- F%'%+%)%)M# $' 0Od # )  (,    # #   r3rcVeZdZdZidddddddd d d d d ddddddddddddddddddd d!d"d#d$d%iZ dZd&Z d=fd' Zd(Zd)Z d*Z e d+Z e jd,Z d-Zed.Zd/Zd0Zd1Zd>d2Zd3Zd4Zd5Zd?d6Zd7Zd8Zd9Zd:Zd;Zd<ZxZS)@TableaD A table of cells. The table consists of a grid of cells, which are indexed by (row, column). For a simple table, you'll have a full grid of cells with indices from (0, 0) to (num_rows-1, num_cols-1), in which the cell (0, 0) is positioned at the top left. However, you can also add cells with negative indices. You don't have to add a cell to every grid position, so you can create tables that have holes. *Note*: You'll usually not create an empty table from scratch. Instead use `~matplotlib.table.table` to create a table from data. bestrz upper rightrz upper leftrQz lower leftz lower rightz center leftz center rightz lower centerz upper centerr$ z top right ztop left z bottom left z bottom right rrRtopbottomg{Gz?c "t|t|trQ||jvr4t dj |dj|j|j|}|j|jd||_ ||_ ||_ |j|j|ji|_d|_g|_d|_|j)||j+dy)a( Parameters ---------- ax : `~matplotlib.axes.Axes` The `~.axes.Axes` to plot the table into. loc : str, optional The position of the cell with respect to *ax*. This must be one of the `~.Table.codes`. bbox : `.Bbox` or [xmin, ymin, width, height], optional A bounding box to draw the table into. If this is not *None*, this overrides *loc*. Other Parameters ---------------- **kwargs `.Artist` properties. z3Unrecognized location {!r}. Valid locations are {}z FrootNT)r*r+ isinstancestrrrurvrwr; get_figure_axesr-_bbox_unstale_viewLimr6 transAxes_cellsrn _autoColumns _autoFontsizerfr,)r/axrrYrgr1s r2r+zTable.__init__s&  c3 $**$ KVCTZZ!89;;**S/C  5 12     2<<(  ! f% r3cNd}t|g|d|ji|}||||f<|S)aV Create a cell and add it to the table. Parameters ---------- row : int Row index. col : int Column index. *args, **kwargs All other parameters are passed on to `Cell`. Returns ------- `.Cell` The created cell. )rrr )redges)r/rowcolargsrgr0cells r2add_cellzTable.add_cellDs8&BB4BdjjB6BS#X r3c\tjt| |d|d}}|j |j d|j|j|jd||j||f<d|_ y#t$r}t d|d}~wwxYw) z8 Set a custom cell in a given position. )rrrz0Only tuples length 2 are accepted as coordinatesNFrT) rcheck_isinstancer ExceptionKeyErrorr;rr6 get_transformr,rr7)r/positionrrrerrs r2 __setitem__zTable.__setitem__\s d. 3{HQKC U34 4--/0  $ CH  3)*/2 3 3s B B+ B&&B+c |j|S)z-Retrieve a custom cell from a given position.r)r/rs r2 __getitem__zTable.__getitem__ls{{8$$r3c|jS)a The default value of `~.Cell.visible_edges` for newly added cells using `.add_cell`. Notes ----- This setting does currently only affect newly created cells using `.add_cell`. To change existing cells, you have to set their edges explicitly:: for c in tab.get_celld().values(): c.visible_edges = 'horizontal' rmr>s r2rz Table.edgesps"{{r3c ||_d|_yr5)rnr7rxs r2rz Table.edgess  r3c|jdz |jdjz|jjj z dzS)NgR@Trg333333?)FONTSIZErdpirrYr#r>s r2_approx_text_heightzTable._approx_text_heightsG $tD'A'E'EE &&'),- .r3c| |jdj}| td|jsy|j d|j |j |t|jD] }|j|j|"|jdd|_ y)NTrzNo renderer definedtable)gidF) r _get_renderer RuntimeErrorrM open_groupget_gid_update_positionssortedrrN close_groupr7)r/rHkeys r2rNz Table.draws  D1??AH  45 5! G8 x($++& ,C KK  ! !( + , W% r3c(|jjDcgc]#\\}}}|dk\r|dk\r|j|%}}}}tj|}|j |j jScc}}}w)z Get a bbox, in axes coordinates for the cells. Only include those in the range (0, 0) to (maxRow, maxCol). r)ritemsrSr unionr[rr])r/rHrrrboxesrYs r2_get_grid_bboxzTable._get_grid_bboxs*.):):)<++%Zc31H''1++zz%  2 2 4 = = ?@@ +s(B c|j|rdifS|jdj}||jj Dcgc]#\\}}}|dk\r|dk\r|j |%}}}}t j|}|j|j|jifSdifScc}}}w)NFTrr) _different_canvasrrrrrSr rcontainsr%r&)r/ mouseeventrHrrrrrYs r2rzTable.containss  ! !* -"9 ???-;;=  -1[[->->-@//)#sTqSAX++H5/E/::e$D==z||s r2 get_childrenzTable.get_childrensDKK&&())r3c| |jdj}|j||jj Dcgc]}|j |}}t j|Scc}w)NTr)rrrrrrSr r)r/rHrrs r2rSzTable.get_window_extentsx  D1??AH x(![[//13''133zz%  3sA?c4i}i}|jjD]f\\}}}|j|d}t||j ||<|j|d}t||j ||<hd}i} t |D]}|| |<|||z }d} i} t |dD]}| | |<| ||z } |jjD]0\\}}}|j| ||j| |2y)zV Calculate row heights and column widths; position cells accordingly. rrT)reverseN) rr setdefaultmax get_heightrGrset_xset_y) r/widthsheightsrrrr#r"xposleftsyposbottomss r2_do_cell_alignmentzTable._do_cell_alignments;  $ 1 1 3 7 JS#''S1Fvt'89GCL%%c3/EeT^^%56F3K  7&> CE#J F3K D '40 !CGCL GCL D ! !% 1 1 3 % JS# JJuSz " JJws| $ %r3ctj|}tj|jtjs t d|D]}|j j|d|_y)z Automatically set the widths of given columns to optimal sizes. Parameters ---------- col : int or sequence of ints The indices of the columns to auto-scale. z'col must be an int or sequence of ints.TN) np atleast_1d issubdtypedtypeinteger TypeErrorrappendr7)r/rcol1drs r2auto_set_column_widthzTable.auto_set_column_widths` c"}}U[["**5EF F +D    $ $T * + r3c|jjDcgc]\}}|d|k(s|}}}tfd|Dd}|D]}|j|ycc}}w)z#Automatically set width for column.rc3@K|]}|jywr:)rF)rprrHs r2rrz/Table._auto_set_column_width..sMt00:Msr)defaultN)rrr set_width)r/rrHrrcells max_widths ` r2_auto_set_column_widthzTable._auto_set_column_widthsg'+{{'8'8':L)#tc!fmLLMuM !#  &D NN9 % &Ms A&A&c ||_d|_y)zAutomatically set font size.TN)rr7rxs r2rKzTable.auto_set_font_sizes" r3ct|jdk(rytt|jj j }g}|jj D]E\}}|d|jvr|j|}t||}|j|G|jj D]}|j|y)Nrr) lenrnextiterrrDrrrKminrrA)r/rHrIrrrrBs r2_auto_set_font_sizezTable._auto_set_font_sizes t{{ q T[[//123@@B**, IC1v*****84D8T*H LL   KK&&( (D   h ' (r3c|jjD]F}|j|j|z|j |j |zHy)z Set the font size, in points, of the cell text. Parameters ---------- size : float Notes ----- As long as auto font size has not been disabled, the value will be clipped such that the text fits horizontally into the cell. You can disable this behavior using `.auto_set_font_size`. >>> the_table.auto_set_font_size(False) >>> the_table.set_fontsize(20) However, there is no automatic scaling of the row height so that the text may exceed the cell boundary. TN)rrrAr7)r/rBrs r2rAzTable.set_fontsize s5*KK&&( $D   d # $ r3c|jjD]J}|j|j}}|j ||z|j ||zLy)z-Move all the artists by ox, oy (axes coords).N)rrget_xget_yrr)r/oxoyr r%r&s r2_offsetz Table._offset9sQ##% A779aggiqA GGAFO GGAFO r3c|jD]}|j|||jr|j||j |j |}|j \}}}}|j{t|jtr|jj \}} } } n|j\}} } } |j| |z | |z ||z } | |z } |j nhtt|j\}}}}}}}}}}}}}}}}}}d|dz z |z } d|dz z |z } |j|||fvr|j|z } |j|||||fvrd||z|jzz } |j||||fvrd||z|jzz } |j|||fvr|j|z } |j|||fvr d|dz z |z } |j|||fvr d|dz z |z } |j|||fvr||z } |j|||fvrd|z } |j|||fvrd|z } |j|||fvr||z } |j!| | y)Ng?rQrra)rrrrrrr^rrr r rangerrr-AXESPADr) r/rHrrYrbrcrrdrlrbrwrhrrBESTURULLLLRCLCRLCUCCTRTLBLBRRLTBs r2rzTable._update_positions@s $$ 7C  ' 'X 6 7     $ $X . !""8,[[ 1a :: !$**d+!%!2!2BB!%BB JJrAvrAv &aBaB  # # %,1TZZ+A )T2r2r2r2r1 RQ1aA+"BA+"ByyRRL(\\A%yyT2r1b11!a%$,,./yyT2r2..!a%$,,./yyRRL(\\A%yyRQK'AEkQ&yyRQK'AEkQ&yyRQK'AYyyRQK'1WyyRQK'1WyyRQK'AY Rr3c|jS)a Return a dict of cells in the table mapping *(row, column)* to `.Cell`\s. Notes ----- You can also directly index into the Table object to access individual cells:: cell = table[row, col] rr>s r2 get_celldzTable.get_celldzs{{r3)NNr:)T) rrrrrrrr+rrrrrrrrrNrrrrSrrrrKrr rArrr.rrs@r2rrs  VQ  Q  Q Q Q   Q   Q  Q Q Q R R R R R R  R! "R# E&IHGG* X0 %$ \\.* A *!%>"& ($2 28t r3rc | | td|#t|}t|d}dg|zg|z}t|r@| |j}n td| |j}n td|j }t|}t|d}|D]}t||k7std|d|Bt||k7rtd|d |D]}t||k7std |dn d |zg|z}| d |z g|z}d}||dg|z}|d}n|d |z}|t||k7rtd |d}| | dg|z}n d}n| d |z} | d |zg|z}t || | fi|}| |_|j}t|D]<}t|D],}|j||z|||||||||||.>|1t|D]#}|jd||||||| || %|Kt|D]'}|j||zd|xsd||||||)|dk(r|jdd|vr|j|d|j||S)a Add a table to an `~.axes.Axes`. At least one of *cellText* or *cellColours* must be specified. These parameters must be 2D lists, in which the outer lists define the rows and the inner list define the column values per row. Each row must have the same number of elements. The table can optionally have row and column headers, which are configured using *rowLabels*, *rowColours*, *rowLoc* and *colLabels*, *colColours*, *colLoc* respectively. For finer grained control over tables, use the `.Table` class and add it to the Axes with `.Axes.add_table`. Parameters ---------- cellText : 2D list of str or pandas.DataFrame, optional The texts to place into the table cells. *Note*: Line breaks in the strings are currently not accounted for and will result in the text exceeding the cell boundaries. cellColours : 2D list of :mpltype:`color`, optional The background colors of the cells. cellLoc : {'right', 'center', 'left'} The alignment of the text within the cells. colWidths : list of float, optional The column widths in units of the axes. If not given, all columns will have a width of *1 / ncols*. rowLabels : list of str, optional The text of the row header cells. rowColours : list of :mpltype:`color`, optional The colors of the row header cells. rowLoc : {'left', 'center', 'right'} The text alignment of the row header cells. colLabels : list of str, optional The text of the column header cells. colColours : list of :mpltype:`color`, optional The colors of the column header cells. colLoc : {'center', 'left', 'right'} The text alignment of the column header cells. loc : str, default: 'bottom' The position of the cell with respect to *ax*. This must be one of the `~.Table.codes`. bbox : `.Bbox` or [xmin, ymin, width, height], optional A bounding box to draw the table into. If this is not *None*, this overrides *loc*. edges : {'closed', 'open', 'horizontal', 'vertical'} or substring of 'BRTL' The cell edges to be drawn with a line. See also `~.Cell.visible_edges`. Returns ------- `~matplotlib.table.Table` The created table. Other Parameters ---------------- **kwargs `.Table` properties. %(Table:kwdoc)s zZAt least one argument from "cellColours" or "cellText" must be provided to create a table.rrz3rowLabels cannot be used alongside Pandas DataFramez3colLabels cannot be used alongside Pandas DataFramez!Each row in 'cellText' must have z columnsz'cellColours' must have z rowsz$Each row in 'cellColours' must have rraz'rowLabels' must be of length r)r"r#rrrr~gV瞯"D4K=4'H%   IRS S   ((IRS S?? x=D x{ D( s8t @G''( ((  { t #7vUCD D 4C3x4 !G$(6"344 4 TzlT) 4ZL4' M  !t I%aLM  4Z  y>T !=dVDE EF  !t IF  4Z TzlT)  "c4 *6 *EEK  & & (FT{(; (C NN3<!*3 ( c 2%0%5c%:&  ( ((; 'C NN1c!*3 )#*S/%  ' '; 'C NN3<!.!7% )#*S/%  ' ' A   ' ' +V 6*-.LL Lr3) NNrNNNrRNNr$rNr)rnumpyrrrrartistrrpatchesrrr transformsr pathr cbookr r CustomCellrrrr3r2rIst$/'B9BJ XFXv  %)%)282:)1 CCr3