a
    kº”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   úb/var/www/auris/lib/python3.9/site-packages/sympy/plotting/backends/matplotlibbackend/matplotlib.pyÚ_str_or_latex   s    
r   c                 C   s€   g }g }t | ƒrd| D ]L}|d }|d }| |j|j|j|jdg¡ | |j|j|j|jdg¡ qn| 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rB| j | _| j| _tdd„ | jD ƒƒsœ|| jƒ nZ| jj| jd| _tdd„ | jD ƒƒr€| jj	ddddd	| _n| 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ÚleftZ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   s   | ]}|j V  qd S ©N©Zis_3D©Ú.0Úsr   r   r   Ú	<genexpr>L   ó    z3MatplotlibBackend._create_figure.<locals>.<genexpr>)Zfigsizec                 s   s   | ]}|j V  qd S r7   r8   r9   r   r   r   r<   P   r=   r   Z3d)Z
projection)
r'   r   r(   r   ÚanyÚ_seriesr!   ÚfigureÚsizeZadd_subplot)r)   r6   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ÚnpZ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 ]d}|jrÈ|jrP| ¡ \}	}
}n| ¡ \}	}
t|jttfƒsvt|jƒr¦|  	|	|
¡}|  
|¡}| | ¡ ¡ | |¡ n t|jƒ}|j|	|
||jd\}q.|jrÞ|j| ¡ Ž  q.|jr”| ¡ \}	}
}}t|jttfƒst|jƒrN|jj}|  	|	|
|¡}| |¡}| | ¡ ¡ | |¡ n t|jƒ}|j|	|
|||jd | |j¡ | |j¡ | |j¡ q.|jrR|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%rì| ¡ }t&|ƒdkr–t'|d ƒ\}	}
|j(|	|
|jdd nT| j)j*j+}|d|jgƒ}|\}}}}|dkrØ|j||||d n|j,||||d q.|j-r†|j.dkr|j|j/i |j0¤Ž nn|j.dkr8|j1|j/i |j0¤Ž nL|j.dkrZ|j2|j/i |j0¤Ž n*|j.dkr”| 3| j)j4j5|j/i |j0¤Ž¡ q.t6d 7|¡ƒ‚q.|jj8}t||ƒsÄ|j9| :¡ | ;¡ d n|r| <|¡}| =|d d …df ¡| >|d d …df ¡f}| ?|¡ n| ?ddg¡ |rb| <|¡}| =|d d …df ¡| >|d d …df ¡f}| @|¡ n| @ddg¡ |r¸| <|¡}| =|d d …df ¡| >|d d …df ¡f}| A|¡ n| Addg¡ | jBræt||ƒsæ| C| jB¡ | jDrt||ƒs| E| jD¡ t||ƒr | j)jFdkr,| G| jH¡ | jIr| jI} t||ƒrHnÌ| dkrt|jJd  Kd¡ |jJd  Kd¡ n | dkrä| L¡ \}!}"| M¡ \}#}$|!|" dkr¨dnd}%|#|$ dkr¾dnd}&|jJd  K|%¡ |jJd  K|&¡ n0|jJd  Kd| d f¡ |jJd  Kd| d f¡ | jNs$| O¡  | jPrD| P¡ rD|jQ R| jP¡ | jSrd| T| jS¡ | U| jS¡ | jVrx| W| jV¡ | jXr˜t| jXƒ}'|jY|'dd  | jZr¸t| jZƒ}(|j[|(d!d  t||ƒrä| j\rät| j\ƒ})|j]|)d!d  | j^rø| ?| j^¡ | j_r| @| j_¡ | j` a| jb¡ d S )"NrC   Úmpl_toolkitsr   Úmplot3d)r   )r
   ÚcolorZviridisr   gš™™™™™¹?)ÚcmapZrstrideZcstrideZ	linewidthrE   r   ÚNone)Z	facecolorZ	edgecolorZwhiteÚcontour)rU   Ú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.   r1   r   )Údatar   r\   )r   r   )Úposition)r   r   )cr   Z	is_2DlineZis_parametricÚget_datar   Z
line_colorÚintr%   ÚcallablerQ   r"   Z	set_arrayZget_color_arrayZadd_collectionr   r
   ZplotZ
is_contourrW   Z	is_3DlinerS   Úart3dZLine3DCollectionÚappendZ_xlimZ_ylimZ_zlimZis_3DsurfaceZplot_surfaceÚgetattrr   ZjetZsurface_colorr   rK   rA   r5   Zis_implicitr   r   rZ   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_onrI   ZaminZamaxZset_xlimZset_ylimZset_zlimZxscaleZ
set_xscaleZyscaleZ
set_yscaleÚ__version__Zset_autoscale_onZ	autoscaleZaxis_centerr3   r4   Zget_xlimZget_ylimrG   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   rO   rR   ZxlimsZylimsZzlimsr;   rL   rM   ÚparamÚsegmentsZ
collectionZlblÚlinerN   ra   ÚuÚvZcolor_arrayrP   re   ZcolormapZxarrayZyarrayZzarrayZ	plot_typerj   ro   rp   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)rB   rx   r?   r   ©r)   r   r   r   Úprocess_series&  s    z MatplotlibBackend.process_seriesc                 C   s0   |   ¡  tjr$| j ¡  | j ¡  n|  ¡  d S r7   )rz   Úbase_backendZ_showr   Ztight_layoutr!   ÚshowÚclosery   r   r   r   r|   .  s
    
zMatplotlibBackend.showc                 C   s   |   ¡  | j |¡ d S r7   )rz   r   Zsavefig)r)   Úpathr   r   r   Úsave9  s    zMatplotlibBackend.savec                 C   s   | j  | j¡ d S r7   )r!   r}   r   ry   r   r   r   r}   =  s    zMatplotlibBackend.close)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   rB   ÚstaticmethodrQ   rx   rz   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   