
    g1                         d dl mZ d dlmZ d dlmZ d dlmc mc m	Z	 d dl
mZ d Zd Z G d d	e	j                  ZdS )
    )Callable)Basic)import_moduleN)latexc                 l    t          | t                    rt          | d          S t          |           S )Ninline)mode)
isinstancer   r   str)labels    p/var/www/html/ai-engine/env/lib/python3.11/site-packages/sympy/plotting/backends/matplotlibbackend/matplotlib.py_str_or_latexr      s3    % +U****u::    c                 h   g }g }t          |           rr| D ]n}|d         }|d         }|                    |j        |j        |j        |j        dg           |                    |j        |j        |j        |j        dg           on*|                    d           |                    d           ||fS )zi
    Returns lists for matplotlib ``fill`` command from a list of bounding
    rectangular intervals
    r      N)NNNN)lenextendstartend)interval_listxlistylist	intervals	intervalx	intervalys         r   _matplotlib_listr      s    
 EE
= /& 	A 	AI!!I!!ILL)/9?#-> ? ? ?LL)/9=#-$@ A A A A	A 	-...-...%<r   c                   ^     e Zd ZdZ fdZd Zedd            Zd Zd Z	d Z
d	 Zd
 Z xZS )MatplotlibBackendzd This class implements the functionalities to use Matplotlib with SymPy
    plotting functions.
    c                      t                      j        |i | t          ddg didt          f          | _        | j        j        | _        | j        j        | _        | j        j        j	        | _	        |
                    dd          | _        | j        dk    r-t          | j        d                   | j        d	         z  | _        |                    d
d           | _        |                    dd           | _        d S )N
matplotlibfromlist)pyplotcmcollectionsz1.1.0)import_kwargsmin_module_versioncatchaspect_ratioautor   r   figax)super__init__r   RuntimeErrorr    r"   pltr#   r$   LineCollectiongetaspectfloatpop_plotgrid_fig_plotgrid_ax)selfserieskwargs	__class__s      r   r-   zMatplotlibBackend.__init__0   s    &+F+++'%'F'F'FG&|o? ? ? ?)/$"o9Hjj88;&  A//$+a.@DK $ZZt44"JJtT22r   c                    d }| j         J| j         | _        | j        | _        t	          d | j        D                       s || j                   d S d S | j                            | j                  | _        t	          d | j        D                       r%| j        	                    dddd          | _        d S | j        	                    ddd          | _         || j                   d S )Nc                 n   | j         d                             d           | j         d                             d           | j         d                             d           | j         d                             d           | j                            d           | j                            d           d S )Nleftzerorightnonebottomtop)spinesset_position	set_colorxaxisset_ticks_positionyaxis)r+   s    r   
set_spinesz4MatplotlibBackend._create_figure.<locals>.set_spinesA   s    If**6222Ig((000Ih,,V444Ie&&v...H''111H''/////r   c              3   $   K   | ]}|j         V  d S Nis_3D.0ss     r   	<genexpr>z3MatplotlibBackend._create_figure.<locals>.<genexpr>L   s$      551qw555555r   )figsizec              3   $   K   | ]}|j         V  d S rK   rL   rN   s     r   rQ   z3MatplotlibBackend._create_figure.<locals>.<genexpr>P   s$      11q17111111r   r   3d)
projection)
r5   r*   r6   r+   any_seriesr/   figuresizeadd_subplot)r7   rI   s     r   _create_figurez MatplotlibBackend._create_figure@   s   	0 	0 	0 ))DH'DG5555555 $
47#####$ $ xty99DH11DL11111 $(..q!Q4.HH(..q!Q77
47#####r   Nc                    t          d          }|d}| ||f}nd}| |f}|j                            |          j                            dd|          }|j                            |dd         |dd         gd          S )a   Convert two list of coordinates to a list of segments to be used
        with Matplotlib's :external:class:`~matplotlib.collections.LineCollection`.

        Parameters
        ==========
            x : list
                List of x-coordinates

            y : list
                List of y-coordinates

            z : list
                List of z-coordinates for a 3D line.
        numpyN      r   )axis)r   maarrayTreshapeconcatenate)xyznpdimpointss         r   get_segmentszMatplotlibBackend.get_segmentsV   s      7##=CAYFFCVFV$$&..r1c::u  &"+vabbz!: CCCr   c                 F   t          d          }t          dddgi          }g g g }}}|D ]y}|j        r
|j        r|                                \  }	}
}n|                                \  }	}
t	          |j        t          t          f          st          |j                  rh| 	                    |	|
          }| 
                    |          }|                    |                                           |                    |           t          |j                  }|                    |	|
||j                  \  }|j        r |j        |                                  :|j        rF|                                \  }	}
}}t	          |j        t          t          f          st          |j                  ru|j        j        }| 	                    |	|
|          }|                    |          }|                    |                                           |                    |           n3t          |j                  }|                    |	|
|||j                   |                    |j                   |                    |j                   |                    |j                   |j        rI|j        r|                                \  }	}
}}}n|                                \  }	}
}|                    |	|
|t;          | j        d| j        j                  ddd	
          }t	          |j         t          t          tB          f          rD|                                }|"                    |j#                  }|                    |           n|$                    |j                    |                    |j                   |                    |j                   |                    |j                   |j%        r|                                }tM          |          dk    r8tO          |d                   \  }	}
|(                    |	|
|j        d           ?| j)        j*        j+        } |d|j        g          }|\  }}}}|dk    r|                    ||||           |,                    ||||           |j-        r|j.        dk    r |j        |j/        i |j0         |j.        dk    r |j1        |j/        i |j0         |j.        dk    r |j2        |j/        i |j0         |j.        dk    r4|3                     | j)        j4        j5        |j/        i |j0                   Ytm          d7                    |                    |j        j8        }t	          ||          s=|9                    |:                                |;                                           n|ri|<                    |          }|=                    |d d df                   |>                    |d d df                   f}|?                    |           n|?                    ddg           |ri|<                    |          }|=                    |d d df                   |>                    |d d df                   f}|@                    |           n|@                    ddg           |ri|<                    |          }|=                    |d d df                   |>                    |d d df                   f}|A                    |           n|A                    ddg           | jB        r*t	          ||          s|C                    | jB                   | jD        r*t	          ||          s|E                    | jD                   t	          ||          r| j)        jF        dk    r|G                    | jH                   | jI        r?| jI        } t	          ||          rn&| dk    rA|jJ        d         K                    d           |jJ        d         K                    d           n| dk    r|L                                \  }!}"|M                                \  }#}$|!|"z  dk    rdnd}%|#|$z  dk    rdnd}&|jJ        d         K                    |%           |jJ        d         K                    |&           nP|jJ        d         K                    d| d         f           |jJ        d         K                    d| d         f           | jN        s|O                                 | jP        r3|P                                r|jQ        R                    | jP                   | jS        r4|T                    | jS                   |U                    | jS                   | jV        r|W                    | jV                   | jX        r+t          | jX                  }'|Y                    |'d            | jZ        r+t          | jZ                  }(|[                    |(d!            t	          ||          r2| j\        r+t          | j\                  })|]                    |)d!            | j^        r|?                    | j^                   | j_        r|@                    | j_                   | j`        a                    | jb                   d S )"Nr]   mpl_toolkitsr!   mplot3d)r%   )r   colorviridisr   g?)cmaprstridecstride	linewidthr_   r   None)	facecolor	edgecolorwhitecontour)rs   markersannotationsfill
rectangleszc{} is not supported in the SymPy plotting module with matplotlib backend. Please report this issue.)scalexscaleyz1.2.0centerr=   rA   r)   )datar   r   )r   r   )position)r   r   )cr   	is_2Dlineis_parametricget_datar
   
line_colorintr3   callablerm   r0   	set_arrayget_color_arrayadd_collectionr   r   plot
is_contourr{   	is_3Dlinerp   art3dLine3DCollectionappend_xlim_ylim_zlimis_3Dsurfaceplot_surfacegetattrr#   jetsurface_colorr   re   rY   rE   is_implicitr   r   r~   r    colorsListedColormapcontourf
is_generictypeargsrendering_kwannotatefill_between	add_patchpatches	RectangleNotImplementedErrorformatAxes3Dautoscale_viewget_autoscalex_onget_autoscaley_onrc   aminamaxset_xlimset_ylimset_zlimxscale
set_xscaleyscale
set_yscale__version__set_autoscale_on	autoscaleaxis_centerrC   rD   get_xlimget_ylimra   set_axis_offlegendlegend_set_visiblemarginset_xmarginset_ymargintitle	set_titlexlabel
set_xlabelylabel
set_ylabelzlabel
set_zlabelxlimylimr+   
set_aspectr2   )*r7   r8   r+   rj   ro   xlimsylimszlimsrP   rg   rh   paramsegments
collectionlbllineri   r   uvcolor_arrayrl   r   colormapxarrayyarrayzarray	plot_typer   r   r   zlimvalxlxhylyhpos_left
pos_bottomxlblylblzlbls*                                             r   _process_seriesz!MatplotlibBackend._process_seriesp   s
   7##$:	{*CE E E
 !"beu W	! W	!A{ U!? ("#**,,KAq%%::<<DAqq|c5\:: I ..I#00A66H!%!4!4X!>!>J(():):)<)<===%%j1111'00CGGAq1<GHHEDD G!
AJJLL))) E!!"1aq|c5\:: 	D ..	D(06E#00Aq99H!&!7!7!A!AJ(():):)<)<===%%j1111'00CGGAq!3alGCCCQW%%%QW%%%QW%%%% 5!? +$%JJLLMAq!QjjllGAq!__Q1 )TW[AAqC - 9 9
 aosH/EFF :"#"3"3"5"5K"-"5"5k6F"G"GK((5555((999QW%%%QW%%%QW%%%% #!v;;!##+F1I66DAqGGAqALFGKKKK
 &*_%;%JN-~w.EFFH8>5FFFI I--

666
IIIIFFFJJJJ !6Y&&BGQV6q~6666V},,BK:1>::::Vv%%#BOQV>q~>>>>V|++LL9/9V7'(~7 78 8 8 *IVBZZ! ! !
 %,"f%% 	$++--++--  / / / /  $aaad,,bggeAAAqDk.B.BCD!!!!QF### $aaad,,bggeAAAqDk.B.BCD!!!!QF### $aaad,,bggeAAAqDk.B.BCD!!!!QF###
 ; 	'z"f55 	'MM$+&&&; 	'z"f55 	'MM$+&&&"f%% 	0)D)O)O/// 	C"C"f%% C	&!..x888	(#00::::BB*,R%1**;;(,.rEQJJ[[H
	&!..x888	(#00<<<<	&!..A/?@@@	(#00&#a&1ABBBy 	OO; 	4yy{{ 4
&&t{333; 	(NN4;'''NN4;''': 	%LL$$$; 	1 --DMM$M000; 	1 --DMM$M000b&!! 	1dk 	1 --DMM$M000 9 	#KK	"""9 	#KK	"""4;'''''r   c                 n    |                                   |                     | j        | j                   dS )za
        Iterates over every ``Plot`` object and further calls
        _process_series()
        N)r[   r   rW   r+   r7   s    r   process_seriesz MatplotlibBackend.process_series&  s6    
 	T\4733333r   c                     |                                   t          j        r4| j                                         | j                                         d S |                                  d S rK   )r   base_backend_showr*   tight_layoutr/   showcloser   s    r   r   zMatplotlibBackend.show.  sY      	H!!###HMMOOOOOJJLLLLLr   c                 b    |                                   | j                            |           d S rK   )r   r*   savefig)r7   paths     r   savezMatplotlibBackend.save9  s0    r   c                 D    | j                             | j                   d S rK   )r/   r   r*   r   s    r   r   zMatplotlibBackend.close=  s    tx     r   rK   )__name__
__module____qualname____doc__r-   r[   staticmethodrm   r   r   r   r   r   __classcell__)r:   s   @r   r   r   +   s         3 3 3 3 3 $ $ $, D D D \D2s( s( s(l4 4 4	 	 	  ! ! ! ! ! ! !r   r   )collections.abcr   sympy.core.basicr   sympy.externalr   $sympy.plotting.backends.base_backendplottingbackendsr   sympy.printing.latexr   r   r   Plotr    r   r   <module>r	     s    $ $ $ $ $ $ " " " " " " ( ( ( ( ( ( ; ; ; ; ; ; ; ; ; ; ; ; & & & & & &    0S! S! S! S! S!) S! S! S! S! S!r   