U
    L?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   úf/var/www/html/venv/lib/python3.8/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||Ž tdddddg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 k	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Ú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   s   | ]}|j V  qd S ©N©Zis_3D©Ú.0Úsr   r   r   Ú	<genexpr>L   s     z3MatplotlibBackend._create_figure.<locals>.<genexpr>)Zfigsizec                 s   s   | ]}|j V  qd S r8   r9   r:   r   r   r   r=   P   s     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k	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 ]T}|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-rv|j.dkr|j|j/|j0Ž nb|j.dkr0|j1|j/|j0Ž nD|j.dkrN|j2|j/|j0Ž n&|j.dkr„| 3| j)j4j5|j/|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¡ |rR| <|¡}| =|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||ƒr8nÌ| dkrd|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r4| P¡ r4|jQ R| jP¡ | jSrT| T| jS¡ | U| jS¡ | jVrh| 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 )"NrB   Úmpl_toolkitsr   Úmplot3d)r   )r
   ÚcolorZviridisr   gš™™™™™¹?)ÚcmapZrstrideZcstrideZ	linewidthrD   r   ÚNone)Z	facecolorZ	edgecolorÚ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.   r2   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_contourrX   Z	is_3DlinerS   Úart3dZLine3DCollectionÚappendZ_xlimZ_ylimZ_zlimZis_3DsurfaceZplot_surfaceÚgetattrr   ZjetZsurface_colorr   rJ   r@   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_onrH   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_ylimrF   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   rN   rR   ZxlimsZylimsZzlimsr<   rK   rL   ÚparamÚsegmentsZ
collectionZlblÚlinerM   rb   ÚuÚvZcolor_arrayrP   rf   ZcolormapZxarrayZyarrayZzarrayZ	plot_typerk   rp   rq   ZzlimÚvalZxlÚxhZylZyhZpos_leftZ
pos_bottomZxlblZylblZzlblr   r   r   Ú_process_seriesp   s0    ÿ
ÿ

ÿ


  þ

 ÿÿþÿþ

,
,
,





z!MatplotlibBackend._process_seriesc                 C   s   |   ¡  |  | j| j¡ dS )za
        Iterates over every ``Plot`` object and further calls
        _process_series()
        N)rA   ry   r?   r   ©r)   r   r   r   Úprocess_series&  s    z MatplotlibBackend.process_seriesc                 C   s0   |   ¡  tjr$| j ¡  | j ¡  n|  ¡  d S r8   )r{   Úbase_backendZ_showr   Ztight_layoutr!   ÚshowÚcloserz   r   r   r   r}   .  s
    
zMatplotlibBackend.showc                 C   s   |   ¡  | j |¡ d S r8   )r{   r   Zsavefig)r)   Úpathr   r   r   Úsave9  s    zMatplotlibBackend.savec                 C   s   | j  | j¡ d S r8   )r!   r~   r   rz   r   r   r   r~   =  s    zMatplotlibBackend.close)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   rA   ÚstaticmethodrQ   ry   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   