
    sg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y)
    )Callable)Basic)import_moduleN)latexc                 R    t        | t              rt        | d      S t        |       S )Ninline)mode)
isinstancer   r   str)labels    g/var/www/html/venv/lib/python3.12/site-packages/sympy/plotting/backends/matplotlibbackend/matplotlib.py_str_or_latexr      s#    %U**u:    c                    g }g }t        |       r| D ]  }|d   }|d   }|j                  |j                  |j                  |j                  |j                  dg       |j                  |j                  |j                  |j                  |j                  dg        ||fS |j                  d       |j                  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I!!I!!ILL)//9??#--> ?LL)//9==#--$@ A	A %< 	-.-.%<r   c                   X     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        |   |i | t        ddg didt        f      | _        | j                  j
                  | _        | j                  j                  | _        | j                  j                  j                  | _	        |j                  dd      | _        | j                  dk7  r-t        | j                  d         | j                  d	   z  | _        |j                  d
d       | _        |j                  dd       | _        y )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G&|o? ??))//$$"oo99HHjj8;;& A/$++a.@DK $ZZt4"JJtT2r   c                    d }| j                   R| j                   | _        | j                  | _        t	        d | j
                  D              s || j                         y y | j                  j                  | j                        | _        t	        d | j
                  D              r%| j                  j                  dddd      | _        y | j                  j                  ddd      | _         || j                         y )Nc                 `   | j                   d   j                  d       | j                   d   j                  d       | j                   d   j                  d       | j                   d   j                  d       | j                  j	                  d       | j
                  j	                  d       y )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    IIf**62IIg((0IIh,,V4IIe&&v.HH''1HH''/r   c              3   4   K   | ]  }|j                     y wNis_3D.0ss     r   	<genexpr>z3MatplotlibBackend._create_figure.<locals>.<genexpr>L   s     51qww5   )figsizec              3   4   K   | ]  }|j                     y wrK   rL   rN   s     r   rQ   z3MatplotlibBackend._create_figure.<locals>.<genexpr>P   s     1q1771rR   r   3d)
projection)
r5   r*   r6   r+   any_seriesr/   figuresizeadd_subplot)r7   rI   s     r   _create_figurez MatplotlibBackend._create_figure@   s    	0 )))DH''DG555477# 6 xxtyy9DH1DLL11((..q!Q4.H((..q!Q7477#r   c                     t        d      }|d}| ||f}nd}| |f}|j                  j                  |      j                  j	                  dd|      }|j                  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AYFCVFV$&&..r1c:uu  &"+vabz!: CCr   c                 P   t        d      }t        dddgi      }g g g }}}|D ]  }|j                  r|j                  r|j                         \  }	}
}n|j                         \  }	}
t	        |j
                  t        t        f      st        |j
                        rT| j                  |	|
      }| j                  |      }|j                  |j                                |j                  |       t        |j                        }|j!                  |	|
||j
                        \  }|j"                  r |j$                  |j                           0|j&                  r=|j                         \  }	}
}}t	        |j
                  t        t        f      st        |j
                        rk|j(                  j*                  }| j                  |	|
|      }|j-                  |      }|j                  |j                                |j                  |       n5t        |j                        }|j!                  |	|
|||j
                         |j/                  |j0                         |j/                  |j2                         |j/                  |j4                         z|j6                  rH|j                  r|j                         \  }	}
}}}n|j                         \  }	}
}|j9                  |	|
|t;        | j<                  d| j<                  j>                        ddd	
      }t	        |j@                  t        t        tB        f      r=|j                         }|jE                  |jF                        }|j                  |       n|jI                  |j@                         |j/                  |j0                         |j/                  |j2                         |j/                  |j4                         |jJ                  r|j                         }tM        |      dk(  r2tO        |d         \  }	}
|jQ                  |	|
|j
                  d       +| jR                  jT                  jV                  } |d|j
                  g      }|\  }}}}|dk(  r|j%                  ||||       |jY                  ||||       |jZ                  r|j\                  dk(  r( |j                   |j^                  i |j`                   |j\                  dk(  r( |jb                  |j^                  i |j`                   |j\                  dk(  r( |jd                  |j^                  i |j`                   K|j\                  dk(  s\|jg                   | jR                  jh                  jj                  |j^                  i |j`                         tm        djo                  |             |j(                  jp                  }t	        ||      s1|js                  |ju                         |jw                                n8|rS|jy                  |      }|j{                  |d d df         |j}                  |d d df         f}|j                  |       n|j                  ddg       |rS|jy                  |      }|j{                  |d d df         |j}                  |d d df         f}|j                  |       n|j                  ddg       |rS|jy                  |      }|j{                  |d d df         |j}                  |d d df         f}|j                  |       n|j                  ddg       | j                  r't	        ||      s|j                  | j                         | j                  r't	        ||      s|j                  | j                         t	        ||      r| jR                  j                  dk\  r|j                  | j                         | j                  r"| j                  } t	        ||      rn| dk(  r=|j                  d   j                  d       |j                  d   j                  d       n| dk(  r{|j                         \  }!}"|j                         \  }#}$|!|"z  dk  rdnd}%|#|$z  dk  rdnd}&|j                  d   j                  |%       |j                  d   j                  |&       nF|j                  d   j                  d| d   f       |j                  d   j                  d| d   f       | j                  s|j                          | j                  r5|j                         r%|j                  j                  | j                         | j                  r6|j                  | j                         |j                  | j                         | j                  r|j                  | j                         | j                  r(t        | j                        }'|j                  |'d        | j                  r(t        | j                        }(|j                  |(d!        t	        ||      r4| j                  r(t        | j                        })|j                  |)d!        | j                  r|j                  | j                         | j                  r|j                  | j                         | j                  j                  | j                         y )"Nr^   mpl_toolkitsr!   mplot3d)r%   )r   colorviridisr   g?)cmaprstridecstride	linewidthr`   r   None)	facecolor	edgecolorwhitecontour)rt   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   callablern   r0   	set_arrayget_color_arrayadd_collectionr   r   plot
is_contourr|   	is_3Dlinerq   art3dLine3DCollectionappend_xlim_ylim_zlimis_3Dsurfaceplot_surfacegetattrr#   jetsurface_colorr   rf   rZ   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_onrd   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_ylimrb   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+   rk   rp   xlimsylimszlimsrP   rh   ri   paramsegments
collectionlbllinerj   r   uvcolor_arrayrm   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
 !"beu W	!A{{??"#**,KAq%::<DAqq||c5\: .#00A6H!%!4!4X!>J(():):)<=%%j1'0CGGAq1<<GHED

AJJL)!"1aq||c5\: .(0066E#00Aq9H!&!7!7!AJ(():):)<=%%j1'0CGGAq!3allGCQWW%QWW%QWW%??$%JJLMAq!QjjlGAq!__Q1 )TWW[[AqC - 9
 aoosH/EF"#"3"3"5K"-"5"5k6F6F"GK((5((9QWW%QWW%QWW%v;!#+F1I6DAqGGAqALLFGK
 &*__%;%;%J%JN-w.EFH8>5FFFI I-

666
IFFFJ66Y&BGGQVV6q~~6VV},BKK:1>>:VVv%#BOOQVV>q~~>VV|+LL9//99VV7'(~~78 *IVBZ! !iW	!r %%,,"f%++-++-  / ad,bggeAqDk.BCD!QF#ad,bggeAqDk.BCD!QF#ad,bggeAqDk.BCD!QF#
 ;;z"f5MM$++&;;z"f5MM$++&"f%)D)D)O/""C"f%		&!..x8		(#00:BB*,R%1*;(,.rEQJ[H
		&!..x8		(#00<		&!..A/?@		(#00&#a&1AByyOO;;yy{

&&t{{3;;NN4;;'NN4;;'::LL$;; -DMM$M0;; -DMM$M0b&!dkk -DMM$M0 99KK		"99KK		"4;;'r   c                 p    | j                          | j                  | j                  | j                         y)za
        Iterates over every ``Plot`` object and further calls
        _process_series()
        N)r\   r   rX   r+   r7   s    r   process_seriesz MatplotlibBackend.process_series&  s(    
 	T\\4773r   c                     | j                          t        j                  r5| j                  j	                          | j
                  j                          y | j                          y rK   )r   base_backend_showr*   tight_layoutr/   showcloser   s    r   r   zMatplotlibBackend.show.  s?     HH!!#HHMMOJJLr   c                 Z    | j                          | j                  j                  |       y rK   )r   r*   savefig)r7   paths     r   savezMatplotlibBackend.save9  s     r   c                 N    | j                   j                  | j                         y rK   )r/   r   r*   r   s    r   r   zMatplotlibBackend.close=  s    txx r   rK   )__name__
__module____qualname____doc__r-   r\   staticmethodrn   r   r   r   r   r   __classcell__)r:   s   @r   r   r   +   sC    3 $, D D2s(l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
     s5    $ " ( ; ; &0S!)) S!r   