o
    GZŽh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   úc/var/www/auris/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)Zinterval_listZxlistZylistZ	intervalsZ	intervalxZ	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_kwargsZmin_module_versionZcatchZ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_colorZxaxisZset_ticks_positionZyaxis)r   r   r   r   Ú
set_spinesA   s   z4MatplotlibBackend._create_figure.<locals>.set_spinesc                 s   ó    | ]}|j V  qd S ©N©Zis_3D©Ú.0Úsr   r   r   Ú	<genexpr>L   ó   € z3MatplotlibBackend._create_figure.<locals>.<genexpr>)Zfigsizec                 s   r8   r9   r:   r;   r   r   r   r>   P   r?   r   Z3d)Z
projection)
r'   r   r(   r   ÚanyÚ_seriesr!   ZfigureÚsizeZadd_subplot)r)   r7   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ÚreshapeZ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ƒs‡t|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||ƒržnf| dkr´|jJd  Kd¡ |jJd  Kd¡ nP| dkrì| L¡ \}!}"| M¡ \}#}$|!|" dkrÎdnd}%|#|$ dkrÙdnd}&|jJd  K|%¡ |jJd  K|&¡ n|jJd  Kd| d f¡ |jJd  Kd| d f¡ | jNs| O¡  | jPr| P¡ r|jQ R| 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 )"NrD   Úmpl_toolkitsr   Úmplot3d)r   )r
   ÚcolorZviridisr   gš™™™™™¹?)ÚcmapZrstrideZcstrideZ	linewidthrF   r   ÚNone)Z	facecolorZ	edgecolorÚwhiteÚcontour)rW   ÚmarkersÚannotationsÚfillZ
rectangleszc{} is not supported in the SymPy plotting module with matplotlib backend. Please report this issue.)ZscalexZscaleyz1.2.0Úcenterr.   r2   r   )Údatar   r_   )r   r   )Úposition)r   r   )cr   Z	is_2DlineZis_parametricÚget_datar   Z
line_colorÚintr%   ÚcallablerS   r"   Z	set_arrayZget_color_arrayZadd_collectionr   r
   ZplotZ
is_contourrZ   Z	is_3DlinerU   Úart3dZLine3DCollectionÚappendZ_xlimZ_ylimZ_zlimZis_3DsurfaceZplot_surfaceÚgetattrr   ZjetZsurface_colorr   rL   rB   r6   Zis_implicitr   r   r]   r   ÚcolorsÚListedColormapZcontourfZ
is_genericÚtypeÚargsZrendering_kwZannotateZfill_betweenZ	add_patchZpatchesZ	RectangleÚNotImplementedErrorÚformatÚAxes3DZautoscale_viewZget_autoscalex_onZget_autoscaley_onrJ   ZaminZamaxZset_xlimZset_ylimZset_zlimZxscaleZ
set_xscaleZyscaleZ
set_yscaleÚ__version__Zset_autoscale_onZ	autoscaleZaxis_centerr4   r5   Zget_xlimZget_ylimrH   Zset_axis_offZlegendZlegend_Zset_visibleÚmarginZset_xmarginZset_ymarginÚtitleÚ	set_titleZxlabelZ
set_xlabelZylabelZ
set_ylabelZzlabelZ
set_zlabelÚxlimÚylimr   Z
set_aspectr$   )*r)   r*   r   rP   rT   ZxlimsZylimsZzlimsr=   rM   rN   ÚparamÚsegmentsZ
collectionZlblÚlinerO   rd   ÚuÚvZcolor_arrayrR   rh   ZcolormapZxarrayZyarrayZzarrayZ	plot_typerm   rr   rs   ZzlimÚvalZxlÚxhZylZyhZpos_leftZ
pos_bottomZxlblZylblZ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)rC   r{   rA   r   ©r)   r   r   r   Úprocess_series&  s   z MatplotlibBackend.process_seriesc                 C   s2   |   ¡  tjr| j ¡  | j ¡  d S |  ¡  d S r9   )r}   Úbase_backendZ_showr   Ztight_layoutr!   ÚshowÚcloser|   r   r   r   r   .  s
   
zMatplotlibBackend.showc                 C   s   |   ¡  | j |¡ d S r9   )r}   r   Zsavefig)r)   Úpathr   r   r   Úsave9  s   zMatplotlibBackend.savec                 C   s   | j  | j¡ d S r9   )r!   r€   r   r|   r   r   r   r€   =  s   zMatplotlibBackend.closer9   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   rC   ÚstaticmethodrS   r{   r}   r   r‚   r€   Ú__classcell__r   r   r,   r   r   +   s     7r   )Úcollections.abcr   Zsympy.core.basicr   Zsympy.externalr   Z$sympy.plotting.backends.base_backendZplottingÚbackendsr~   Zsympy.printing.latexr   r   r   ZPlotr   r   r   r   r   Ú<module>   s    