o
    ݹi1                     @   sn   d dl mZ d dlmZ d dlmZ d dlm  m  m	Z	 d dl
mZ dd Zdd	 ZG d
d de	jZdS )    )Callable)Basic)import_moduleN)latexc                 C   s   t | trt| ddS t| S )Ninline)mode)
isinstancer   r   str)label r   q/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/sympy/plotting/backends/matplotlibbackend/matplotlib.py_str_or_latex   s   
r   c                 C   s   g }g }t | r5| D ]&}|d }|d }||j|j|j|jdg ||j|j|j|jdg q
||fS |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	intervalyr   r   r   _matplotlib_list   s    



r   c                       s^   e Zd ZdZ fddZdd ZedddZd	d
 Zdd Z	dd Z
dd Zdd Z  ZS )MatplotlibBackendzd This class implements the functionalities to use Matplotlib with SymPy
    plotting functions.
    c                    s   t  j|i | tddg didtfd| _| jj| _| jj| _| jjj	| _	|
dd| _| jdkr@t| jd | jd	  | _|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__r   r   r(   0   s   



zMatplotlibBackend.__init__c                 C   s   dd }| j d ur$| j | _| j| _tdd | jD s"|| j d S d S | jj| jd| _tdd | jD rD| jj	ddddd	| _d S | j	ddd| _|| j d S )
Nc                 S   s\   | 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&   r   r   r   
set_spinesA   s   z4MatplotlibBackend._create_figure.<locals>.set_spinesc                 s       | ]}|j V  qd S Nis_3D.0sr   r   r   	<genexpr>L       z3MatplotlibBackend._create_figure.<locals>.<genexpr>)figsizec                 s   rD   rE   rF   rH   r   r   r   rK   P   rL   r   3d)
projection)
r0   r%   r1   r&   any_seriesr*   figuresizeadd_subplot)r2   rC   r   r   r   _create_figure@   s   
z MatplotlibBackend._create_figureNc                 C   sh   t d}|durd}| ||f}nd}| |f}|j|jdd|}|jj|dd |dd gd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pointsr   r   r   get_segmentsV   s   $zMatplotlibBackend.get_segmentsc           *   
   C   s  t d}t dddgid}g g g }}}|D ]}|jrd|jr(| \}	}
}n| \}	}
t|jttfs;t|jrS| 	|	|
}| 
|}||  || qt|j}|j|	|
||jd\}q|jro|j|   q|jr| \}	}
}}t|jttfst|jr|jj}| 	|	|
|}||}||  || nt|j}|j|	|
|||jd ||j ||j ||j q|jr%|jr| \}	}
}}}n| \}	}
}|j|	|
|t| jd| jjddd	d
}t|j ttt!fr| }|"|j#}|| n|$|j  ||j ||j ||j q|j%rr| }t&|dkrGt'|d \}	}
|j(|	|
|jdd q| j)j*j+}|d|jg}|\}}}}|dkrh|j||||d q|j,||||d q|j-r|j.dkr|j|j/i |j0 q|j.dkr|j1|j/i |j0 q|j.dkr|j2|j/i |j0 q|j.dkr|3| j)j4j5|j/i |j0 qt6d7||jj8}t||s|j9|: |; d n|r |<|}|=|d d df |>|d d df f}|?| n|?ddg |r+|<|}|=|d d df |>|d d df f}|@| n|@ddg |rV|<|}|=|d d df |>|d d df f}|A| n|Addg | jBrmt||sm|C| jB | jDr}t||s}|E| jD t||r| j)jFdkr|G| jH | jIr| jI} t||rnf| dkr|jJd Kd |jJd Kd nP| dkr|L \}!}"|M \}#}$|!|" dkrdnd}%|#|$ dkrdnd}&|jJd K|% |jJd K|& n|jJd Kd| d f |jJd Kd| d f | jNs|O  | jPr|P r|jQR| jP | jSr,|T| jS |U| jS | jVr6|W| jV | jXrFt| jX}'|jY|'dd  | jZrVt| jZ}(|j[|(d!d  t||rl| j\rlt| j\})|j]|)d!d  | j^rv|?| j^ | j_r|@| j_ | j`a| jb d S )"NrV   mpl_toolkitsr   mplot3d)r    )r
   colorviridisr   g?)cmaprstridecstride	linewidthrX   r   None)	facecolor	edgecolorwhitecontour)rk   markersannotationsfill
rectangleszc{} is not supported in the SymPy plotting module with matplotlib backend. Please report this issue.)scalexscaleyz1.2.0centerr7   r;   r$   )datar   r{   )r   r   )position)r   r   )cr   	is_2Dlineis_parametricget_datar   
line_colorintr.   callablerf   r+   	set_arrayget_color_arrayadd_collectionr   r
   plot
is_contourrs   	is_3Dlinerh   art3dLine3DCollectionappend_xlim_ylim_zlimis_3Dsurfaceplot_surfacegetattrr   jetsurface_colorr   r^   rS   r?   is_implicitr   r   rv   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_onr\   aminamaxset_xlimset_ylimset_zlimxscale
set_xscaleyscale
set_yscale__version__set_autoscale_on	autoscaleaxis_centerr=   r>   get_xlimget_ylimrZ   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_aspectr-   )*r2   r3   r&   rc   rg   xlimsylimszlimsrJ   r`   ra   paramsegments
collectionlbllinerb   r   uvcolor_arrayre   r   colormapxarrayyarrayzarray	plot_typer   r   r   zlimvalxlxhylyhpos_left
pos_bottomxlblylblzlblr   r   r   _process_seriesp   s,  









,
,
,





z!MatplotlibBackend._process_seriesc                 C   s   |    | | j| j dS )za
        Iterates over every ``Plot`` object and further calls
        _process_series()
        N)rU   r   rQ   r&   r2   r   r   r   process_series&  s   z MatplotlibBackend.process_seriesc                 C   s2   |    tjr| j  | j  d S |   d S rE   )r   base_backend_showr%   tight_layoutr*   showcloser   r   r   r   r   .  s
   
zMatplotlibBackend.showc                 C   s   |    | j| d S rE   )r   r%   savefig)r2   pathr   r   r   save9  s   zMatplotlibBackend.savec                 C   s   | j | j d S rE   )r*   r   r%   r   r   r   r   r   =  s   zMatplotlibBackend.closerE   )__name__
__module____qualname____doc__r(   rU   staticmethodrf   r   r   r   r   r   __classcell__r   r   r5   r   r   +   s     7r   )collections.abcr   sympy.core.basicr   sympy.externalr   $sympy.plotting.backends.base_backendplottingbackendsr   sympy.printing.latexr   r   r   Plotr   r   r   r   r   <module>   s    