
    wg3y                       d dl mZ d dlmZ d dlmZmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZ d d	lmZmZmZmZmZmZ d d
lmZmZmZmZmZ d dlmZ d dl m!Z! d dl"m#Z# d dl$m%Z%m&Z& d dl'm(Z( d dl)m*Z* d dl+m,Z, d dl-m.Z.m/Z/m0Z0 d dl1m2Z2 d dl3m4Z4 d dl5m6Z6 ddl7m8Z8 d dl9Z9 G d de*      Z:dddddZ;d Z<d Z= G d  d!      Z>dBd"Z?d# Z@ G d$ d%e>      ZA G d& d'eA      ZB G d( d)eA      ZC G d* d+eA      ZD G d, d-eD      ZE G d. d/eA      ZF G d0 d1eD      ZG G d2 d3e>      ZH G d4 d5eH      ZI G d6 d7eH      ZJ G d8 d9eI      ZK G d: d;e>      ZL G d< d=e>      ZMd> ZNd? ZOdCd@ZPdA ZQy)D    )Callable)continuous_domain)SumProduct)Tuple)Expr)arity)default_sort_key)Symbol)atan2zetafracceilingfloorim)EqualityGreaterThanLessThan
RelationalNe)sympify)import_module)BooleanFunction)_get_free_symbolsextract_solution)latex)PythonCodePrinter)
precedence)SetIntervalUnion)	nsimplify)sympy_deprecation_warning)lambdify   )intervalNc                       e Zd ZdZd Zd Zy)IntervalMathPrinterzA printer to be used inside `plot_implicit` when `adaptive=True`,
    in which case the interval arithmetic module is going to be used, which
    requires the following edits.
    c                      t        |      dj                   fdt        |j                  t              D              S )Nz & c              3   B   K   | ]  }j                  |        y wNparenthesize.0aPRECselfs     Z/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/sympy/plotting/series.py	<genexpr>z1IntervalMathPrinter._print_And.<locals>.<genexpr>#   (      B ++At4 B   keyr   joinsortedargsr
   r2   exprr1   s   ` @r3   
_print_AndzIntervalMathPrinter._print_And!   ;    $zz B		/?@B B 	B    c                      t        |      dj                   fdt        |j                  t              D              S )Nz | c              3   B   K   | ]  }j                  |        y wr+   r,   r.   s     r3   r4   z0IntervalMathPrinter._print_Or.<locals>.<genexpr>(   r5   r6   r7   r9   r=   s   ` @r3   	_print_OrzIntervalMathPrinter._print_Or&   r@   rA   N)__name__
__module____qualname____doc__r?   rD    rA   r3   r(   r(      s    B
BrA   r(   F)modulesforce_real_evalhas_sumc                   	 t        d      fd	j                  	t        g      	d	fd	}dk(  r |       S 	  	| g S # t        $ r} ||      cY d}~S d}~ww xY w)zy
    Note: this is an experimental function, as such it is prone to changes.
    Please, do not use it in your code.
    numpyc                     	 t         | |       S # t        t        f$ r# t        j                  j                        cY S w xY wr+   )complexZeroDivisionErrorOverflowErrornan)funcr<   nps     r3   wrapper_funcz#_uniform_eval.<locals>.wrapper_func4   s@    	+4;''!=1 	+266266**	+s    /AA)otypesNc                 :   Id}| |dz  }t        |      |dz  }dj                  t        |       j                  |        t        |      | rEt	        j
                  dsdnz  dj                  t        |       j                  |       z   dz           g S )	Nz6Impossible to evaluate the provided numerical function.z,because the following exception was raised:
z{}: {}The evaluation with %s failed.
NumPy/SciPy{}: {}
OTrying to evaluate the expression with Sympy, but it might be a slow operation.)formattyperE   RuntimeErrorwarningswarn)errmsgr<   f2rJ   rV   s     r3   _eval_with_sympyz'_uniform_eval.<locals>._eval_with_sympy?   s    :JC{s
 s## FFS	 2 2C8s##MM2)0Mg?!!$s)"4"4c:;'' B&&&rA   sympyr+   )r   	vectorizerP   	Exception)
f1re   rJ   rK   rL   r<   rf   rc   rU   rV   s
    ``  `  @@r3   _uniform_evalrk   ,   sw     
w	B+ <<gY<?L' '& '!!%B&&& %$$%s   A 	A(A#A(#A(c                     t        d      } | |      }t        |t              r|j                  s|j	                         }t        |      }|j                  dkD  r|j                  S |j                  S )a(  Evaluate f(x) with an adaptive algorithm. Post-process the result.
    If a symbolic expression is evaluated with SymPy, it might returns
    another symbolic expression, containing additions, ...
    Force evaluation to a float.

    Parameters
    ==========
    f : callable
    x : float
    rN   g:0yE>)	r   
isinstancer   	is_NumberevalfrP   imagrS   real)fxrU   ys       r3   _adaptive_evalru   [   sX     
w	B	!A!TAKKGGI
Avv~vv66MrA   c                 N    d}| dk(  rd}|S | dk(  rd}|S | dk(  rd}|S | dk(  rd	}|S )
Nz%srq   zre(%s)rp   zim(%s)abszabs(%s)argzarg(%s)rI   )retwrappers     r3   _get_wrapper_for_exprr{   q   sW    G
f} N 

 N	 
 N 
NrA   c                      e Zd ZdZdZdZdZdZdZdZ	dZ
dZdZdZdZdZd Zd Zd Zd Zd Zd	 Zd
 Zd,dZd Zed        Zej6                  d        Zed        Zed        Zd Zed        Zej6                  d        Zed        Z e j6                  d        Z ed        Z!e!j6                  d        Z!d Z"ed        Z#e#j6                  d        Z#ed        Z$e$j6                  d        Z$ed        Z%e%j6                  d        Z%e&d-d       Z'e&d         Z(d! Z)d" Z*d# Z+d.d$Z,ed%        Z-e-j6                  d&        Z-ed'        Z.e.j6                  d(        Z.d) Z/d* Z0y+)/
BaseSeriesa  Base class for the data objects containing stuff to be plotted.

    Notes
    =====

    The backend should check if it supports the data series that is given.
    (e.g. TextBackend supports only LineOver1DRangeSeries).
    It is the backend responsibility to know how to use the class of
    data series that is given.

    Some data series classes are grouped (using a class attribute like is_2Dline)
    according to the api they present (based only on convention). The backend is
    not obliged to use that api (e.g. LineOver1DRangeSeries belongs to the
    is_2Dline group and presents the get_points method, but the
    TextBackend does not use the get_points method).

    BaseSeries
    Fd   c                    t        |j                         t        |             }|j                  dd      | _        |j                  dd       | _        |j                  dd      | _        |j                  dd      | _        |j                  dd      | _        |j                  d|j                  d	d            | _	        |j                  d
|j                  dd            | _
        dx| _        | _        g | _        t        |j                  d| j                              t        |j                  d| j                              t        |j                  d| j                              g| _        |j                  dd      |j                  dd      |j                  dd      g| _        |j                  di       | _        t'        | j$                  t(              st+        d      t-        | j$                        dkD  rd| _        |j                  di       | _        |j                  dd       | _        |j                  dd       | _        |j                  dd       | _        |j                  dd       | _        t;        d | j2                  | j4                  | j6                  | j8                  fD              st+        d      g | _        g | _        |j                  dd       | _         d | _!        d| _"        g | _#        d | _$        d| _%        y )Nonly_integersFrJ   show_in_legendTcolorbaruse_cmis_polarpolaris_pointpoint n1n2n3xscalelinearyscalezscaleparamsz@`params` must be a dictionary mapping symbols to numeric values.r   rendering_kwtxtytztpc              3   >   K   | ]  }t        |      xs |d u   y wr+   callabler/   ts     r3   r4   z&BaseSeries.__init__.<locals>.<genexpr>   s$      6!8A;-19- 6s   z)`tx`, `ty`, `tz`, `tp` must be functions.rK   )&_set_discretization_pointscopyr_   getr   rJ   r   r   r   r   r   _label_latex_label_rangesint_N_n_scales_paramsrm   dict	TypeErrorlenis_interactiver   _tx_ty_tz_tpall
_functions
_signature_force_real_eval_discretized_domain_interactive_ranges_needs_to_be_int
color_func_eval_color_func_with_signature)r2   r<   kwargss      r3   __init__zBaseSeries.__init__   s   +FKKM4:F#ZZ?zz)T2 %jj)94@
 

:t4 jj51 

:vzz'5/IJ

:vzz'5/IJ*,,d'

4)*

4)*

4)*
 JJx*JJx*JJx*
 zz(B/$,,- % & &t||q "&D #JJ~r: ::dD)::dD)::dD)::dD) 6XXtxx48846 6GHH  !'

+<d C $(  $)  !#  05,rA   c                 j    t        d |D              r!t        t        |       j                  dz         y)zSome data series can be used to plot numerical functions, others
        cannot. Execute this method inside the `__init__` to prevent the
        processing of numerical functions.
        c              3   2   K   | ]  }t        |        y wr+   r   r/   es     r3   r4   z5BaseSeries._block_lambda_functions.<locals>.<genexpr>+       *qx{*   z  requires a symbolic expression.N)anyr   r_   rE   r2   exprss     r3   _block_lambda_functionsz"BaseSeries._block_lambda_functions&  s:    
 *E**DJ// 3    +rA   c                   	 | j                   | j                  }}| j                  | j                  }}t	        |d      r|n|g}t        d |D              ryt        |      		j                  |j                               	|"	j                  |D cg c]  }|d   	 c}      	t        	      dkD  rMt        ddj                  ||||fn||f      z   dj                  |      z   dj                  	      z   d	z         |D cg c]  }|d   	 }}|D ]  } t               j                  |d
d D cg c]  }|j                   c} 	t        	fd|D              rt        dt        |      z        t        	      dkD  rd| _        	j                  |j                               }t        |      dkD  st        d|dd|z  z          yc c}w c c}w c c}w )z@ Checks if there are enogh parameters and free symbols.
        __iter__c              3   2   K   | ]  }t        |        y wr+   r   r   s     r3   r4   z'BaseSeries._check_fs.<locals>.<genexpr>5  r   r   Nr   z(Incompatible expression and parameters.
zExpression: {}
zparams: {}
z)Specify what these symbols represent: {}
zAre they ranges or parameters?r%   c              3   &   K   | ]  }|v  
 y wr+   rI   )r/   r   fss     r3   r4   z'BaseSeries._check_fs.<locals>.<genexpr>N  s     2q172s   zWRange symbols can't be included into minimum and maximum of a range. Received range: %sTz(Unkown symbols found in plotting range: z. z Are the following parameters? %s)r>   rangesr   labelhasattrr   r   
differencekeysr   
ValueErrorr^   setunionfree_symbolsstrr   )
r2   r   r   r   r   rrange_symbolsr   remaining_fsr   s
            @r3   	_check_fszBaseSeries._check_fs/  s    		4;;vTZZ 
3%*E** u%]]6;;=)f5!56Br7Q;;$++.4.@UFE*uenVV !''/0 ?EEbI	J
 33  (..!1.. 	GAqu=!q~~=>B2M22
 ! ")+.q6"2 3 3 2w{+/(==7L< 1$ FGI6EFG G	G  6 /=s   GG1G
c           
         t        | j                  d      r| j                  n| j                  g}t        d |D              st        |      }t	        |d       | _        g | _        |D ]V  }| j                  j                  t        | j
                  || j                        t        | j
                  |dd      g       X nEt	        | j                  D cg c]  }|d	   	 c}d
       | _        |D cg c]  }|df c}| _        t        | j                  t              r-t        | j
                  | j                        | _        d| _        yyc c}w c c}w )a  Create the lambda functions to be used by the uniform meshing
        strategy.

        Notes
        =====
        The old sympy.plotting used experimental_lambdify. It created one
        lambda function each time an evaluation was requested. If that failed,
        it went on to create a different lambda function and evaluated it,
        and so on.

        This new module changes strategy: it creates right away the default
        lambda function as well as the backup one. The reason is that the
        series could be interactive, hence the numerical function will be
        evaluated multiple times. So, let's create the functions just once.

        This approach works fine for the majority of cases, in which the
        symbolic expression is relatively short, hence the lambdification
        is fast. If the expression is very long, this approach takes twice
        the time to create the lambda functions. Be aware of that!
        r   c              3   2   K   | ]  }t        |        y wr+   r   r   s     r3   r4   z1BaseSeries._create_lambda_func.<locals>.<genexpr>t  s     .18A;.r   c                     | j                   S r+   namer   s    r3   <lambda>z0BaseSeries._create_lambda_func.<locals>.<lambda>v  s
    qvv rA   r7   )rJ   rg   T)rJ   dummifyr   c                     | j                   S r+   r   r   s    r3   r   z0BaseSeries._create_lambda_func.<locals>.<lambda>  s    PQPVPV rA   N)r   r>   r   r   r;   r   r   appendr$   rJ   r   rm   r   r   r   )r2   r   r   r   r   s        r3   _create_lambda_funczBaseSeries._create_lambda_func^  s   * %TYY
;		$))..."5)B$R-=>DO
 !DO  &&T__aFT__a$O(  %DKK%@qad%@FVWDO278Q4y8DO doot,&tHDO37D0 -	 &A8s   E5Ec                 x    | j                   st        |      S t        |j                  | j                              S )zIf the value of a plotting range is a symbolic expression,
        substitute the parameters in order to get a numerical value.
        )r   rP   subsr   )r2   r   s     r3   _update_range_valuezBaseSeries._update_range_value  s/     ''1:qvvdkk*++rA   c                    g }g }t        | j                        D ]L  \  }}|j                  |d          | j                  |d         }| j                  |d         }|j                  |j                  cxk(  rdk(  rn n|j
                  n|}|j                  |j                  cxk(  rdk(  rn n|j
                  n|}| j                  xs |d   | j                  v }	t        j                  ||| j                  |   | j                  |   |	      }
| j                  s#|	s!|
j                  dk7  r|
d|j                  z  z   }
|	r|
j                  t              }
|j                  |
       O | j!                  ||       y)z<Discretize the ranges for uniform meshing strategy.
        r   r%      )scaler   rP   y              ?N)	enumerater   r   r   rp   rq   r   r   r}   _discretizenscalesr   dtypeastyper   !_create_discretized_domain_helper)r2   discr_symbolsdiscretizationsir   c_startc_endstartendneeds_integer_discrds              r3   _create_discretized_domainz%BaseSeries._create_discretized_domain  sR     dkk* 	&DAq  1&..qt4G,,QqT2E$+LLEJJ$C!$CGLLE '

 ?a ?%**UC"&"4"4"W1AVAV9V&&uc466!9kk!n1 ' 3A **5HI%W\\))"HHSM""1%%	&* 	..}oNrA   c                     t        d      }d}| j                  s| j                  r| j                  rd} |j                  |d|i}t        t        ||            | _        y)zCreate 2D or 3D discretized grids.

        Subclasses should override this method in order to implement a
        different behaviour.
        rN   xyijindexingN)r   is_3Dvectoris_3Dsurfaceis_implicitmeshgridr   zipr   )r2   r   r   rU   r   meshess         r3   r   z,BaseSeries._create_discretized_domain_helper  s\     7#  1 1d6F6FHoAA#'M6(B#C rA   c                 l   t        d      }| j                  s| j                          | j                  r| j                  r| j                          | j                  D cg c]  }| j                  |d       }}| j                         }g }| j                  D ]Y  }t        g || }| j                  |j                  |      |d         }|j                  t              }|j                  |       [ |r1|D 	cg c]&  }	|j                  |	j                  t                    ( }}	g ||S c c}w c c}	w )zEvaluation of the symbolic expression (or expressions) with the
        uniform meshing strategy, based on current values of the parameters.
        rN   r   )r   r   r   r   r   r   r   _aggregate_argsrk   _correct_shapearrayr   rP   r   rq   )
r2   cast_to_realrU   sdiscrr<   resultsrr   r   r   s
             r3   	_evaluatezBaseSeries._evaluate  s    7# $$&((T-E-E++-9=EA))!A$/EE##% 	A(q(4(A##BHHQKq:A !ANN1	 9>?ARWWQXXg./?E?!!!!# F  @s   D,9+D1c                 r   g }| j                   D ]  }|| j                  j                         v ri|j                  || j                  v rt        | j                  |         n2| j                  r| j                  |   nt        | j                  |                |j                  | j                  |           |S )ztCreate a list of arguments to be passed to the lambda function,
        sorted accoring to self._signature.
        )	r   r   r   r   r   r   r   rP   r   )r2   r<   r  s      r3   r  zBaseSeries._aggregate_args  s      	9ADLL%%'',-1F1F,FCQ('+'<'<DLLO a13
 D44Q78	9 rA   c                     | j                   S )z5Return the expression (or expressions) of the series.)_exprr2   s    r3   r>   zBaseSeries.expr  s     zzrA   c                    t        |d      }|st        |      nt        d |D              }|r|| _        y|st	        |      nt        | | _        t               }| j                  j                  t        t              D ]>  }|j                  dd D ]*  }t        |d   t              s|j                  |d          , @ t        |      | _        t         t"        t$        t&        t(        g}| j*                  dur|D cg c]  }| j                  j-                  |       }}t        |      | _        | j*                  rp| j.                  (t        | j.                  t0              rJd| j.                  v r<t3        ||      D 	cg c]
  \  }}	|	s	| }
}}	t5        j6                  d|
z  d	z          | j8                  r| j;                          yyc c}w c c}	}w )
z2Set the expression (or expressions) of the series.r   c              3   2   K   | ]  }t        |        y wr+   r   r   s     r3   r4   z"BaseSeries.expr.<locals>.<genexpr>  s     9Q!(1+9Qr   r%   NTrN   zqNumPy is unable to evaluate with complex numbers some of the functions included in this symbolic expression: %s. zHence, the evaluation will use real numbers. If you believe the resulting plot is incorrect, change the evaluation module by setting the `modules` keyword argument.)r   r   r   r  r   r   r   atomsr   r   r<   rm   r   addlistr   r   r   r   r   r   r   hasrJ   r   r   ra   rb   r   r   )r2   r   is_iteris_callabler  r0   pfrr   	check_rescfuncss              r3   r>   zBaseSeries.expr   s    !Z()0hqkc9Qq9Q6QDJ+2q	DJ AZZ%%c73 % %A!!B%0ae%% %)GD! 5%t4B$$D08:;1TZZ^^A.;	;(+I%((t||/Cc2w$,,7N+.r9+=C41aQCECMM #46;#<6#6 7 ((*  < Ds   <"G
?
G
Gc                 ^    | j                   | j                  | j                  g}t        |      S r+   )	is_3Dliner   r   r   )r2   flags3Ds     r3   is_3DzBaseSeries.is_3D&  s(    >>4#4#4d6F6FG7|rA   c                 H    | j                   | j                  g}t        |      S r+   )	is_2Dliner  r   )r2   
flagsliness     r3   is_linezBaseSeries.is_line+  s    nndnn5
:rA   c                     t        | ||       t        |      st        |t              r|| _        t        | |d       y|d| _        yy)z>This method enables back-compatibility with old sympy.plottingN)setattrr   rm   r   r   )r2   propvals      r3   _line_surface_colorzBaseSeries._line_surface_color0  sD    
 	dC C=JsD1!DOD$%_"DO rA   c                     | j                   S r+   )_line_colorr  s    r3   
line_colorzBaseSeries.line_color<  s    rA   c                 (    | j                  d|       y )Nr*  r(  r2   r'  s     r3   r+  zBaseSeries.line_color@  s      4rA   c                     | j                   S )zIReturns a list [n1, n2, n3] of numbers of discratization points.
        )r   r  s    r3   r   zBaseSeries.nD  s     wwrA   c                     t        |d      s|| j                  d<   n|| j                  dt        |       | j                  r| j	                          yy)a  Set the numbers of discretization points. ``v`` must be an int or
        a list.

        Let ``s`` be a series. Then:

        * to set the number of discretization points along the x direction (or
          first parameter): ``s.n = 10``
        * to set the number of discretization points along the x and y
          directions (or first and second parameters): ``s.n = [10, 15]``
        * to set the number of discretization points along the x, y and z
          directions: ``s.n = [10, 15, 20]``

        The following is highly unreccomended, because it prevents
        the execution of necessary code in order to keep updated data:
        ``s.n[1] = 15``
        r   r   N)r   r   r   r   r   r2   vs     r3   r   zBaseSeries.nJ  sI    $ q*%DGGAJ DGGGSV##++- $rA   c                     | j                   S )zGet or set the current parameters dictionary.

        Parameters
        ==========

        p : dict

            * key: symbol associated to the parameter
            * val: the numeric value
        r   r  s    r3   r   zBaseSeries.paramsd  s     ||rA   c                     || _         y r+   r4  )r2   ps     r3   r   zBaseSeries.paramsr  s	    rA   c                    t        | j                  d      r| j                  n| j                  g}t        d |D              r| j                  rt	        d      t        d |D              r)| j
                  t        | j                        k(  rd| _        | j                          t        | d      r7| j                  r*| j                  rt        j                  d       d| _	        y y y y )	Nr   c              3   2   K   | ]  }t        |        y wr+   r   r   s     r3   r4   z(BaseSeries._post_init.<locals>.<genexpr>x  r   r   z`params` was provided, hence an interactive plot is expected. However, interactive plots do not support user-provided numerical functions.c              3   2   K   | ]  }t        |        y wr+   r   r   s     r3   r4   z(BaseSeries._post_init.<locals>.<genexpr>  r   r   r   adaptivez`params` was provided, hence an interactive plot is expected. However, interactive plots do not support adaptive evaluation. Automatically switched to adaptive=False.F)r   r>   r   r   r   r   r   r   r   r:  ra   rb   r   s     r3   
_post_initzBaseSeries._post_initv  s    $TYY
;		$))*E**t{{ 5 6 6 *E**{{c$))n,
4$4;;MM " # "DM <G$rA   c                     | j                   S r+   r   r  s    r3   r   zBaseSeries.scales      ||rA   c                 t    t        |t              r|| j                  d<   y || j                  d t        |       y Nr   )rm   r   r   r   r1  s     r3   r   zBaseSeries.scales  s-    aDLLO$%DLL#a&!rA   c                     | j                   S r+   )_surface_colorr  s    r3   surface_colorzBaseSeries.surface_color  s    """rA   c                 (    | j                  d|       y )NrB  r-  r.  s     r3   rC  zBaseSeries.surface_color  s      !137rA   c                     | j                   S r+   )_rendering_kwr  s    r3   r   zBaseSeries.rendering_kw  s    !!!rA   c                     t        |t              r|| _        y i | _        |%t        j                  dt        |      z  dz          y y )NzP`rendering_kw` must be a dictionary, instead an object of type %s was received. z;Automatically setting `rendering_kw` to an empty dictionary)rm   r   rF  ra   rb   r_   )r2   r   s     r3   r   zBaseSeries.rendering_kw  sO    fd#!'D!#D!79=fF!!" "rA   c                     t        d      }|du rt        |       t        |      }} || z
  dz   }|dk(  r|j                  | ||      S |j                  | ||      S )aX  Discretize a 1D domain.

        Returns
        =======

        domain : np.ndarray with dtype=float or complex
            The domain's dtype will be float or complex (depending on the
            type of start/end) even if only_integers=True. It is left for
            the downstream code to perform further casting, if necessary.
        rN   Tr%   r   )r   r   linspace	geomspace)r   r   Nr   r   rU   s         r3   r   zBaseSeries._discretize  sb     7#D USX3EeaAH;;uc1--||E3**rA   c                    t        d      }t        | |j                        s|j                  |       } | j                  |j                  k7  r@| j                  dk(  r| |j                  |      z  } | S | j                  |j                        } | S )a)  Convert ``a`` to a np.ndarray of the same shape of ``b``.

        Parameters
        ==========

        a : int, float, complex, np.ndarray
            Usually, this is the result of a numerical evaluation of a
            symbolic expression. Even if a discretized domain was used to
            evaluate the function, the result can be a scalar (int, float,
            complex). Think for example to ``expr = Float(2)`` and
            ``f = lambdify(x, expr)``. No matter the shape of the numerical
            array representing x, the result of the evaluation will be
            a single value.

        b : np.ndarray
            It represents the correct shape that ``a`` should have.

        Returns
        =======
        new_a : np.ndarray
            An array with the correct shape.
        rN   rI   )r   rm   ndarrayr  shape	ones_likereshape)r0   brU   s      r3   r  zBaseSeries._correct_shape  sv    0 7#!RZZ(A77aggww"}Q'  IIagg&rA   c           
         t        d      }| j                  )t        j                  d       |j	                  |d         S | j
                  r| j                         } | j                  | }|j                  |      |j                  |      }}|j                  ||j                  |j                  ||j                  |                  <   |S t        | j                        }|dk(  r| j                  rh| j                  r\t!        |      dk(  r'| j#                  | j                  |d         |d         S | j#                  | j                  |d         |d         S | j$                  r3| j                  r'| j#                  | j                  |d         |d         S | j&                  r3| j                  r'| j#                  | j                  |d         |d         S | j#                  | j                  |d         |d         S |dk(  rb| j&                  r1| j                  r%| j#                   | j                  |dd  |d         S | j#                   | j                  |dd  |d         S | j#                   | j                  |d|  |d         S )a  Evaluate the color function.

        Parameters
        ==========

        args : tuple
            Arguments to be passed to the coloring function. Can be coordinates
            or parameters or both.

        Notes
        =====

        The backend will request the data series to generate the numerical
        data. Depending on the data series, either the data series itself or
        the backend will eventually execute this function to generate the
        appropriate coloring value.
        rN   NzThis is likely not the result you were looking for. Please, re-execute the plot command, this time with the appropriate an appropriate value to line_color or surface_color.r   r%   r      )r   r   ra   rb   rO  r   r  rq   rp   rS   invertisclose
zeros_liker	   r!  is_parametricr   r  r  r   )r2   r<   rU   color_re_imnargss          r3   eval_color_funczBaseSeries.eval_color_func  sC   $ 7#??" MM $ % <<Q((//'')D#DOOT*Ewwu~rwwu~CBD&&C		"**S"--*<=>?Jdoo&A:~~$"4"4t9>..ttAw/GaQQ**4??47+CT!WMMD$6$6**4??47+CT!WMM""t'9'9**4??47+CT!WMM&&ttAw'?aIIaZ  T%7%7**?4??DH+EtAwOO&&tRa'A47KK""?4??D%L#A47KKrA   c                     t         )zCompute and returns the numerical data.

        The number of parameters returned by this method depends on the
        specific instance. If ``s`` is the series, make sure to read
        ``help(s.get_data)`` to understand what it returns.
        )NotImplementedErrorr  s    r3   get_datazBaseSeries.get_data*  s
     "!rA   c                     ||z  S )zGiven a latex representation of an expression, wrap it inside
        some characters. Matplotlib needs "$%s%$", K3D-Jupyter needs "%s".
        rI   )r2   r   rz   s      r3   _get_wrapped_labelzBaseSeries._get_wrapped_label3  s     rA   c                     |du r| j                   S | j                   t        | j                        k(  r| j                  | j                  |      S | j                  S a  Return the label to be used to display the expression.

        Parameters
        ==========
        use_latex : bool
            If False, the string representation of the expression is returned.
            If True, the latex representation is returned.
        wrapper : str
            The backend might need the latex representation to be wrapped by
            some characters. Default to ``"$%s$"``.

        Returns
        =======
        label : str
        F)r   r   r>   ra  r   r2   	use_latexrz   s      r3   	get_labelzBaseSeries.get_label9  sQ      ;;;;#dii.( **4+<+<gFF   rA   c                 "    | j                         S r+   )rf  r  s    r3   r   zBaseSeries.labelQ  s    ~~rA   c                      |x| _         | _        y)z)Set the labels associated to this series.N)r   r   r.  s     r3   r   zBaseSeries.labelU  s     +.-d'rA   c                     | j                   S r+   )r   r  s    r3   r   zBaseSeries.ranges_  r>  rA   c                     g }|D ]6  }||j                  t        |D cg c]  }t        |       c}             8 || _        y c c}w r+   )r   tupler   r   )r2   r'  new_valsr2  r   s        r3   r   zBaseSeries.rangesc  sK     	@A}1&=awqz&= >?	@   '>s   Ac           	         d }d\  }}}t        |      dk(  r+|\  }} ||| j                         ||| j                        fS t        |      dk(  rNt        | t              r>|\  }}} ||| j                         ||| j                         ||| j
                        fS t        |      dk(  r>|\  }}} ||| j                         ||| j                         ||| j                        fS t        |      dk(  rat        | t              rQ|\  }}}} ||| j                         ||| j                         ||| j                         ||| j
                        fS t        |      dk(  rQ|\  }}}} ||| j                         ||| j                         ||| j                         ||| j                        fS t        |      dk(  rRt        | t              rB|\  }}}}} ||| j                         ||| j                         ||| j                        ||fS t        |      dk(  r| j                  rw|\  }}}}}} ||| j                         ||| j                         ||| j                         ||| j                         ||| j                         ||| j                        fS t        |      dk(  r"|\  }}}	}
}}|| ||	| j                        |
||fS |S )a'  Apply transformations to the results of numerical evaluation.

        Parameters
        ==========
        args : tuple
            Results of numerical evaluation.

        Returns
        =======
        transformed_args : tuple
            Tuple containing the transformed results.
        c                     || S  ||       S r+   rI   rs   	transforms     r3   r   z-BaseSeries._apply_transform.<locals>.<lambda>x  s    i&7 Yq\ rA   )NNNr   rS           )
r   r   r   rm   Parametric2DLineSeriesr   r   Parametric3DLineSeriesParametricSurfaceSeriesr   )r2   r<   r   rs   rt   zur2  w_abs_argimgcolorss                r3   _apply_transformzBaseSeries._apply_transformk  s    J"1at9>DAqQ>1Q>11$i1n*T3I"JGAq!aNAaNAaNCCY!^GAq!Q>1Q>1Q>AA$i1n*T3I"JJAq!QaNAaNAaNAaNSSY!^JAq!Q!TXX!TXX!TXX!TXX  $i1n*T3J"K MAq!QaNAaNAaNAqII$i1n$"2"2#Aq!Q1!TXX!TXX!TXX!TXX!TXX!TXX  Y!^,0)Aq$c61adhh'sF< <rA   c                     d\  }}| j                   r1d}dt        t        | j                  j	                                     z   }||z   |z   S )N)r   r   interactive  and parameters )r   r   rk  r   r   )r2   r  preposts       r3   _str_helperzBaseSeries._str_helper  sH    	T C%E$++2B2B2D,E(FFDQw~rA   N)T)r   FFz$%s$)1rE   rF   rG   rH   r!  r  r   
is_contourr   r   rW  
is_generic	is_vectoris_2Dvectorr   r   r   r   r   r   r   r   r   r
  r  propertyr>   setterr  r#  r(  r+  r   r   r;  r   rC  r   staticmethodr   r  r\  r_  ra  rf  r   r   r~  r  rI   rA   r3   r}   r}   ~   s   . I I L
 J
 K N M
 J IKK 
B\5|-G^,8\,OBD."@   
[[#+ #+J    
#     5 5  
 XX. .2   ]] ".   ]]& & # # 8 8 " " 
" 
" + +*    D>L@"!0     \\. .   ]]   .`rA   r}   c                 P   t        d      }|j                         }|j                  dz  |z
  }t        t	        |       dz
        D ]\  }	| |	dz      | |	   z
  }
t        ||	dz      ||	   z
        }|j                  ||
z        }t        |      |k\  sK|j                  ||	dz   <   ^ | |fS )a<  Compute the steepness of each segment. If it's greater than a
    threshold, set the right-point y-value non NaN and record the
    corresponding x-location for further processing.

    Returns
    =======
    x : np.ndarray
        Unchanged x-data.
    yy : np.ndarray
        Modified y-data with NaN values.
    rN   r   r%   )r   r   piranger   rw   arctanrS   )rs   rt   epsr>   symbsymbolicrU   yy	thresholdr   dxdyangles                r3   _detect_poles_numerical_helperr    s     
w	B	
B	CI3q6A: q1uX!_1q5AaD!		"r'"u:"Bq1uI b5LrA   c                    g }t        t        |      t        |            }t        | ||      }|j                         }||k(  r	 |S t	        |t
              rt        d |j                  D              rxg }|j                  D ]Q  }|j                  r|j                  |j                         |j                  s7|j                  |j                         S t        t        |            }|S t        d| d      )zAttempts to compute symbolic discontinuities.

    Returns
    =======
    pole : list
        List of symbolic poles, possibily empty.
    c              3   <   K   | ]  }t        |t                y wr+   )rm   r    r   s     r3   r4   z0_detect_poles_symbolic_helper.<locals>.<genexpr>  s     6Jq(#6s   z&Could not parse the following object: zJ .
Please, submit this as a bug. Consider also to set `detect_poles=True`.)r    r"   r   simplifyrm   r!   r   r<   	left_openr   left
right_openrightr  r   r   )r>   r  r   r   polesr&   resr  s           r3   _detect_poles_symbolic_helperr    s     E	%()C.9H
D$
1C
,,.C
h  L S%
 6SXX66 	&A{{QVV$||QWW%		&
 SZ  L 4SE :# #
 	
rA   c                        e Zd ZdZdZdZdZ fdZd Zd Z	d Z
ed	        Zed
        Zed        Zed        Zej                   d        Zd Z xZS )Line2DBaseSerieszA base class for 2D lines.

    - adding the label, steps and only_integers options
    - making is_2Dline true
    - defining get_segments and get_color_array
    Tr   i  c                    t        |   di | |j                  dd      | _        |j                  d|j                  dd            | _        |j                  d|j                  dd            | _        |j                  dd      | _        |j                  d	d
      | _        |j                  dd      | _        |j                  dd       | _	        |j                  dd       | _
        |j                  dd      | _        |j                  dd      | _        |j                  d|j                  dd            | _        |j                  dd      | _        g | _        |j                  dg       }t!        |t"              rt%        t'        |d            }t)        |d      s|g}|D cg c]  }t+        |       }}t-        |      | _        y c c}w )NstepsFr   r   	is_filledfillTr:  depth   r   r   r+  detect_polesr  {Gz?r   r   unwrapexcluder~   r   r   rI   )superr   r   r  r   r  r:  r  r   r   r+  r  r  r   r  poles_locationsrm   r   r  r   r   floatr;   r  )r2   r   r  r   	__class__s       r3   r   zLine2DBaseSeries.__init__  s{   "6"ZZ/


:vzz'5/IJKFD1IJ

:u5ZZ,
jj51 **\48 **\48"JJ~u=::eT*

:vzz'5/IJjj51  "**Y+gs#+Gs;<Gw
+iG%,-58--g .s   'Gc                    t        d      }| j                         }t        | t              r| j                  dk(  rt        | j                  j                  | j                        g| j                  d    }|j                  |D cg c]  }t        |       c}      }d } ||j                  |      | j                        | _         | j                  | }| j                  rc| j                  rWt!        |      dk(  r$|\  }}t#        ||| j$                        \  }}||f}n%|\  }}}t#        ||| j$                        \  }}|||f}| j&                  rqi }| j&                  dur| j&                  }| j                  rIt!        |      dk(  r|\  }} |j&                  |fi |}||f}n|\  }}} |j&                  |fi |}|||f}| j(                  du r| j                  r|d   |d   }}|j                  ||f      j*                  j-                         dd }|j                  ||f      j*                  j-                         dd	 }| j.                  r	|||d   f}nv||f}nq| j0                  re|j3                  |d   d
      dd }|j3                  |d   d
      dd }|j3                  |d   d
      dd	 }	t!        |      d
kD  r
|||	|d
   f}n|||	f}t!        | j4                        dkD  r| j7                  |      }|S c c}w )a  Return coordinates for plotting the line.

        Returns
        =======

        x: np.ndarray
            x-coordinates

        y: np.ndarray
            y-coordinates

        z: np.ndarray (optional)
            z-coordinates in case of Parametric3DLineSeries,
            Parametric3DLineInteractiveSeries

        param : np.ndarray (optional)
            The parameter in case of Parametric2DLineSeries,
            Parametric3DLineSeries or AbsArgLineSeries (and their
            corresponding interactive series).
        rN   r  r   c                     || S  ||       S r+   rI   ro  s     r3   r   z+Line2DBaseSeries.get_data.<locals>.<lambda>  s    )*;Q 1 rA   r   Tr%   Nr  rS  )r   _get_data_helperrm   LineOver1DRangeSeriesr  r  r>   r   r   r   r  r  r   r  r~  r!  r   r  r  r  r  TflattenrW  r  repeatr  _insert_exclusions)
r2   rU   pointsr  r   rs   rt   r6  kwrw  s
             r3   r_  zLine2DBaseSeries.get_data  s   * 7#&&(t23*,1		t{{+>.2kk!n>EHH61eAh67EMA#$RXXe_dhh#?D  '&&/>>d//6{a15q$(($1Q 1a5aDHHE1Q;;B{{$&[[~~v;!#!DAq!		!*r*AVF$GAq!!		!*r*AAYF::~~ay&)1HHaV$&&..04HHaV$&&..0"5%%F1I.FVFIIfQi+AB/IIfQi+CR0IIfQi+Ab1v;?Avay1FAYFt||q ,,V4Fi 7s   K:c                 2   t        ddd       t        d      }t        |       j                  |       }|j                  j                  |      j                  j                  dd| j                        }|j                  j                  |d d |dd  gd      S )	Nz
            The Line2DBaseSeries.get_segments() method is deprecated.

            Instead, use the MatplotlibBackend.get_segments() method, or use
            The get_points() or get_data() methods.
            z1.9zdeprecated-get-segments)deprecated_since_versionactive_deprecations_targetrN   r  r%   )axis)
r#   r   r_   r_  mar  r  rP  _dimconcatenate)r2   rU   r  s      r3   get_segmentszLine2DBaseSeries.get_segmentsT  s    ! &+'@	B 7#d$$T*V$&&..r1dii@uu  &"+vabz!: CCrA   c           	      l   t        d      }t        |      }t        |      }|dz
  }|dk(  rd}t        t	        t        |            j                  |g            }| j                  D cg c]  }|d   	 }}| j                  D ](  }||   |z
  dk\  }	t        |	      st        |	       s(|j                  |	      }
|
dz  }
|
dkD  sD|
t        ||         dz
  k  sYt        |||   |
   z
        }t        |||   |
dz      z
        }t        ||      dz  }||z
  }||z   }|j                  ||   d|
 |||g||   |
dz   d f      ||<   d}|D ]\  } ||   |j                  ||g            }|dz  }|j                  ||   d|
 |d   |j                  |d   g||   |
dz   d f      ||<   ^ + |S c c}w )ap  Add NaN to each of the exclusion point. Practically, this adds a
        NaN to the exlusion point, plus two other nearby points evaluated with
        the numerical functions associated to this data series.
        These nearby points are important when the number of discretization
        points is low, or the scale is logarithm.

        NOTE: it would be easier to just add exclusion points to the
        discretized domain before evaluation, then after evaluation add NaN
        to the exclusion points. But that's only work with adaptive=False.
        The following approach work even with adaptive=True.
        rN   r%   r   r   r~   N)r   r  r   r;   r   r  r   r   r  r   	nanargmaxrw   minr  r  rS   )r2   r  rU   r   k	j_indecesrr   r  r   r  idx
delta_prev
delta_postdeltaprevr  r  jvaluess                      r3   r  z#Line2DBaseSeries._insert_exclusionsd  s    7#fK E6A3uQx=33QC89	#/!1// 	bA)a-1$C3xCIll3'q 7sS^a%77!$Q3%7!8J!$Q37);%;!<J
J7#=Eu9Du9D !#4C4D/6!9SUV;LM!OF1I A& b!)q"((D$<*@!AQ$&NN#AYt_vay"&&&).LfUViX[\]X]X^N_`%bq	b-	b6 ; 0s   )F1c                 B    | j                   sd S | j                   d   d   S r@  r   r  s    r3   varzLine2DBaseSeries.var  s     ;;t=DKKN1,==rA   c                     | j                   sy 	 | j                  | j                   d   d         S # t        $ r | j                   d   d   cY S w xY wNr   r%   r   _castr   r  s    r3   r   zLine2DBaseSeries.start  O    {{	%::dkk!nQ/00 	%;;q>!$$	%    0 AAc                     | j                   sy 	 | j                  | j                   d   d         S # t        $ r | j                   d   d   cY S w xY wNr   r   r  r  s    r3   r   zLine2DBaseSeries.end  r  r  c                      | j                   d   S r@  r=  r  s    r3   r   zLine2DBaseSeries.xscale  s    ||ArA   c                     || _         y r+   )r   r1  s     r3   r   zLine2DBaseSeries.xscale  	    rA   c                    t        d      }| j                  }t        |d      r|j                  |      }t	        |      }|dk(  r-| j
                  r!| j                         } |t        |            S t        t        t        | j                                     }|dk(  r ||d         S |dk(  r ||d d  S  || S ||j                  | j                        z  S )NrN   __call__r%   r   r   )r   r+  r   rh   r	   rW  get_parameter_pointscenters_of_segmentsr  map
get_pointsonesnb_of_points)r2   rU   r  rr   r[  rs   	variabless          r3   get_color_arrayz Line2DBaseSeries.get_color_array  s    7#OO1j!QA!HEzd00--/,Q/00 %8$//:K!LM	A:Yq\?*aZim,,i=(RWWT..///rA   )rE   rF   rG   rH   r!  r  r   r   r_  r  r  r  r  r   r   r   r  r  __classcell__r  s   @r3   r  r    s     ID	B'2PdD 4l > > % % % %   ]] 0rA   r  c                   6     e Zd ZdZd fd	Zd Zd Zd Z xZS )List2DSeriesz7Representation for a line consisting of list of points.c                 @   t        |   di | t        d      t        |      t        |      k7  r>t	        dj                  t        |            dj                  t        |            z         | j                  ||       d }t         ||       ||      z         s| j                  r2| j                  st	        d      t        | | _
        t        | | _        nDj                  |j                        | _
        j                  |j                        | _        | j                  | j                  f| _        t        fd| j                  | j                  fD              s| j                          |j!                  d|j!                  d	d
            | _        || _        |j!                  di       | _        | j(                  rT| j*                  rGd| _        t/        | j*                  t0              r%t3        d| j4                  j6                  z  dz         y y y )NrN   z_The two lists of coordinates must have the same number of elements.
Received: len(list_x) = {} zand len(list_y) = {}c                 f    | D cg c]!  }t        |t              xr |j                   # c}S c c}w r+   )rm   r   	is_number)lr   s     r3   r   z'List2DSeries.__init__.<locals>.<lambda>  s)    aP:a.DODP Ps   &.zSome or all elements of the provided lists are symbolic expressions, but the ``params`` dictionary was not provided: those elements can't be evaluated.r   c              3   J   K   | ]  }t        |j                          y wr+   )rm   rM  )r/   r   rU   s     r3   r4   z(List2DSeries.__init__.<locals>.<genexpr>  s     Q:a,Qs    #r   r   Fr   Tz%s don't support symbolic zexpression for `color_func`.rI   )r  r   r   r   r   r^   r   r   r   r   list_xlist_yr  float64r  r   r   r   r   r   r   r   rW  rm   r   r   r  rE   )r2   r  r  r   r   checkrU   r  s         @r3   r   zList2DSeries.__init__  s   "6"7#v;#f+%..4fS[.A&--c&k:;  	$$VV4PuV}uV},-;;  "K L L  .DK.DK((6(<DK((6(<DKkk4;;/
Qt{{DKK6PQQNN

:vzz'5/IJ
"JJ~r:;;4??!%D$//4004>>3J3JJ234 4 1 +;rA   c                      y)Nz2D list plotrI   r  s    r3   __str__zList2DSeries.__str__  s    rA   c                    | j                   | j                  }}| j                  s| j                  ||      S t	        d      }|j                  |D cg c]  }|j                  | j                          c}t              }|j                  |D cg c]  }|j                  | j                          c}t              }| j                  ||      S c c}w c c}w )3Returns coordinates that needs to be postprocessed.rN   )r   r  )	r  r  r   _eval_color_func_and_returnr   r  ro   r   r  )r2   lxlyrU   r   s        r3   r  zList2DSeries._get_data_helper  s    dkkB""33B;;7#XX"=QqwwDKKw0=UXKXX"=QqwwDKKw0=UXK//B77 >=s   #C#Cc                 n    | j                   r(t        | j                        rg | | j                  | S |S r+   )r   r   r   r\  r2   datas     r3   r  z(List2DSeries._eval_color_func_and_return  s7    ;;8DOO47T7/4//677rA   r   )	rE   rF   rG   rH   r   r  r  r  r  r  s   @r3   r  r    s    A"4H
8rA   r  c                   |     e Zd ZdZd fd	Zed        Zej                  d        Zd Zd Z	d Z
d Zd	 Zd
 Z xZS )r  zHRepresentation for a line consisting of a SymPy expression over a range.c                    t        |   di | t        |      r|n
t        |      | _        |t        | j                        n|| _        |t        | j                        n|| _        |g| _	        t        | _        |j                  dd       | _        | j                          | j                  sh| j                  d   dd  D cg c]  }t        |       c}\  }}t!        |      t!        |      k7  r%t#        d| j$                  j&                  z  dz         | j(                  r*| j                  rt+        j,                  d       d| _        y y y c c}w )	Nreturnr   r%   z%s requires the imaginary z=part of the start and end values of the range to be the same.zjThe adaptive algorithm is unable to deal with complex numbers. Automatically switching to uniform meshing.FrI   )r  r   r   r   r>   r   r   r   r   r   rP   r  r   _returnr;  r   r   r   r  rE   r:  ra   rb   )	r2   r>   var_start_endr   r   r   r   r   r  s	           r3   r   zLineOver1DRangeSeries.__init__  s!   "6"$TND	(-c$))n505E$)),5$o
 zz(D1'' /3kk!nQR.@A'!*AJE3%yBsG# 04>>3J3JJ&&' '
 ==T\\MM O P!DM *= Bs   Ec                      | j                   d   S r@  r  r  s    r3   r  z"LineOver1DRangeSeries.nb_of_points'      vvayrA   c                     || _         y r+   r  r1  s     r3   r  z"LineOver1DRangeSeries.nb_of_points+  	    rA   c                    d }| j                   rdnd}d}| j                   r/dt        t        | j                  j	                                     z   }t        | j                        }|d|| j                  z  dt        | j                        dt         || j                         || j                        f      z   |z   S )Nc                 `    t        | t              r| j                  dk7  r| S | j                  S | S r@  )rm   rP   rp   rq   r   s    r3   rr   z(LineOver1DRangeSeries.__str__.<locals>.f0  s*    !W%66Q;HvvHrA   r  r   r  zcartesian line:  for  over )r   r   rk  r   r   r{   r  r>   r  r   r   )r2   rr   r  r  rz   s        r3   r  zLineOver1DRangeSeries.__str__/  s    	 !% 3 3n%E$++2B2B2D,E(FFD'5diiM4::$((,-
 
 	 	rA   c                 "    | j                         S )a  Return lists of coordinates for plotting. Depending on the
        ``adaptive`` option, this function will either use an adaptive algorithm
        or it will uniformly sample the expression over the provided range.

        This function is available for back-compatibility purposes. Consider
        using ``get_data()`` instead.

        Returns
        =======
            x : list
                List of x-coordinates

            y : list
                List of y-coordinates
        r  r  s    r3   r  z LineOver1DRangeSeries.get_pointsA  s      $$&&rA   c           	          	 t        | j                        r| j                  }n,t        | j                  g| j                  | j                        }| j                  |      \  }}||fS # t        $ r}t        j                  d| j                  sdn| j                  z  dj                  t        |      j                  |      z   dz          t        | j                  g| j                  d      }| j                  |      \  }}Y d }~||fS d }~ww xY wNrZ   r[   r\   r]   rg   )r   r>   r$   r  rJ   _adaptive_sampling_helperri   ra   rb   r^   r_   rE   )r2   rr   rs   rt   rc   s        r3   _adaptive_samplingz(LineOver1DRangeSeries._adaptive_samplingS  s    	5		"IIdhhZDLLA11!4DAq !t  		5MM2)-M4<<I!!$s)"4"4c:;'' $((TYY8A11!4DAq!t		5s   A"A( (	D1BDDc                     t        d      g g  fdt         j                  j                        }t         j                  j                        }j                   j                  j                         j                  |        j                   j                  j                  |g      j                   j                  j                  |g      d       fS )aZ  The adaptive sampling is done by recursively checking if three
        points are almost collinear. If they are not collinear, then more
        points are added between those points.

        References
        ==========

        .. [1] Adaptive polygonal approximation of parametric curves,
               Luiz Henrique de Figueiredo.
        rN   c                 F   dj                   j                         dz  z   }j                  dk(  rEdj                  | d         |j                  |d         j                  | d         z
  z  z   z  }n| d   ||d   | d   z
  z  z   }t	        
|      }j                  ||g      }|j                  kD  r)j                  |d          j                  |d          y|dk  r | ||dz           |||dz          y| d   |d   j                  dk(  rj                  | d   |d   d      }nj                  | d   |d   d      }t        t        
|            }t        d	 |D              sNt        t        |      dz
        D ]3  }	||	   	||	dz       ||	   ||	   g||	dz      ||	dz      g|dz          5 yy| d   |d   |d   t        | ||      s | ||dz           |||dz          yj                  |d          j                  |d          y)
 Samples recursively if three points are almost collinear.
            For depth < 6, points are added irrespective of whether they
            satisfy the collinearity condition or not. The maximum depth
            allowed is 12.
            ?皙?log
   r   r%   rs  Nc              3   $   K   | ]  }|d u  
 y wr+   rI   )r/   rt   s     r3   r4   zRLineOver1DRangeSeries._adaptive_sampling_helper.<locals>.sample.<locals>.<genexpr>  s     5195s   )randomrandr   log10ru   r  r  r   logspacerI  r  r  r   r  r   flat)r6  qr  r   xnewynew	new_pointxarrayyarrayr   rr   rU   sampler2   x_coordsy_coordss             r3   r+  z?LineOver1DRangeSeries._adaptive_sampling_helper.<locals>.sampleu  sT    BIINN,s22F{{e#BHHQqTNVrxx!~8:18G .H H I tf!qt44!!T*D$.I tzz!!%!% q)UQY/y!UQY/
 1!A$,;;%'[[1qtR8F[[1qtR8Fc!Vn-5f55"3v;?3 K &q	 1fQUm6K"F1Ivay#9!'Aq1u >	KK 6 A$,!A$,)A,2F9a0q)UQY/y!UQY/!%!%rA   r   )r   ru   r   rq   r   r   r  )r2   rr   f_startf_endrU   r+  r,  r-  s   ``  @@@@r3   r  z/LineOver1DRangeSeries._adaptive_sampling_helperf  s     7#2	& 2	&h !DJJOO4q$((--0

( rxx'23$((--/0!	5 (##rA   c                     t        d      }| j                         \  }}|j                  |      |j                  |      }}| j	                  ||      }| j	                  ||      }|||fS NrN   )r   r
  rq   rp   r  )r2   rU   rs   resultrY  rZ  s         r3   _uniform_samplingz'LineOver1DRangeSeries._uniform_sampling  se    7#NN$	6776?BGGFOS!!#q)!!#q)#s{rA   c           
         t        d      }| j                  r@| j                  s4| j                         \  }}||fD cg c]  }|j	                  |       c}S | j                         \  }}}| j                  A|j                  ||j                  |j                  ||j                  |                  <   ||fS | j                  dk(  r	 ||fS | j                  dk(  r|}||fS | j                  dk(  r|j                  |dz  |dz  z         }||fS | j                  dk(  r|j                  ||      }||fS t        d| j                  z        c c}w )z<Returns coordinates that needs to be postprocessed.
        rN   rq   rp   rw   r   rx   z&`_return` not recognized. Received: %s)r   r:  r   r  r  r3  r  rS   rT  rU  rV  sqrtarctan2r   )r2   rU   rs   rt   r   rY  rZ  s          r3   r  z&LineOver1DRangeSeries._get_data_helper  s_    7#==$"4"4**,DAq*+Q0ABHHQK00,,.3<< CE&&C		"**S"--*<=>? #v \\V# #v \\V#C #v \\U"''#q&36/*C #v \\U"**S#&C
 #v  !%. / /# 1s   Er  )rE   rF   rG   rH   r   r  r  r  r  r  r  r  r3  r  r  r  s   @r3   r  r  	  sY    R"6    $'$&J$XrA   r  c                   j    e Zd ZdZd ZddZd Zd Zd Zd Z	e
d        Zej                  d	        Zy
)ParametricLineBaseSeriesTc                    |t        | j                        n|| _        |t        | j                        n|| _        | j
                  du rV| j                  t        | j                        k(  r4t        | j                        | _        t        | j                        | _        t        d | j                  D              r8| j
                  s+| j                  t        | j                        k(  rd| _        yyyy)aU  Logic to set the correct label to be shown on the plot.
        If `use_cm=True` there will be a colorbar, so we show the parameter.
        If `use_cm=False`, there might be a legend, so we show the expressions.

        Parameters
        ==========
        label : str
            label passed in by the pre-processor or the user
        NFc              3   2   K   | ]  }t        |        y wr+   r   r   s     r3   r4   zFParametricLineBaseSeries._set_parametric_line_label.<locals>.<genexpr>  s     .qx{.r   r   )r   r  r   r   r   r   r>   r   )r2   r   s     r3   _set_parametric_line_labelz3ParametricLineBaseSeries._set_parametric_line_label  s     (-}c$((m%/4}E$((O%KK5 t{{c$((m'Cdii.DK %dii 0D .DII..{{c$))n,  - 9D.rA   c                    | j                   rjt        | j                        | j                  k(  r<|r%| j	                  t        | j                        |      S t        | j                        S | j                  S |rJ| j                  t        | j                        k7  r| j                  S | j	                  | j                  |      S | j                  S r+   )r   r   r  r   ra  r   r>   r   rd  s      r3   rf  z"ParametricLineBaseSeries.get_label  s     ;;488}+225?GLL488}$;;{{c$))n,(((**4+<+<gFF{{rA   c                    | j                   r:t        d      }| j                         }|D cg c]  }|j                  |       }}n| j	                         }| j
                  rQ| j                  rEt        d      }|\  }}}|j                  |dz  |dz  z         }|j                  ||      }|||d   g}t        | j                        rt        |      } | j                  | |d<   |S c c}w )zReturns coordinates that needs to be postprocessed.
        Depending on the `adaptive` option, this function will either use an
        adaptive algorithm or it will uniformly sample the expression over the
        provided range.
        rN   r   r  )r:  r   r  r  r3  r!  r   r5  r6  r   r   r  r\  )r2   rU   coordsr   rs   rt   _r   s           r3   r  z)ParametricLineBaseSeries._get_data_helper  s     ==w'B,,.F+12abhhqk2F2++-F>>dmmw'BGAq!1q!t$A

1a AF2J'FDOO$&\F---v6F2J! 3s   C(c                 >   t        d      }| j                         }t        |      D ]i  \  }}|j                  |      |j	                  |      }}|j
                  ||j                  |j                  ||j                  |                  <   |||<   k g |dd |d   S )r  rN   r%   Nr   )	r   r
  r   rq   rp   rS   rT  rU  rV  )r2   rU   r	  r   r   rY  rZ  s          r3   r3  z*ParametricLineBaseSeries._uniform_sampling  s    7#.."g& 	DAqwwqz2771:CBD&&C		"**S"--*<=>?GAJ	
 *)gaj))rA   c                 (    | j                         d   S )Nr  r_  r  s    r3   r  z-ParametricLineBaseSeries.get_parameter_points)  s    }}r""rA   c                 (    | j                         dd S )aJ   Return lists of coordinates for plotting. Depending on the
        ``adaptive`` option, this function will either use an adaptive algorithm
        or it will uniformly sample the expression over the provided range.

        This function is available for back-compatibility purposes. Consider
        using ``get_data()`` instead.

        Returns
        =======
            x : list
                List of x-coordinates
            y : list
                List of y-coordinates
            z : list
                List of z-coordinates, only for 3D parametric line plot.
        Nr  r  r  s    r3   r  z#ParametricLineBaseSeries.get_points,  s    " $$&s++rA   c                      | j                   d   S r@  r  r  s    r3   r  z%ParametricLineBaseSeries.nb_of_points?  r  rA   c                     || _         y r+   r  r1  s     r3   r  z%ParametricLineBaseSeries.nb_of_pointsC  r  rA   Nr  )rE   rF   rG   rW  r;  rf  r  r3  r  r  r  r  r  rI   rA   r3   r8  r8    sS    M!,"6
*#,&    rA   r8  c                   :     e Zd ZdZdZd fd	Zd Zd Zd Z xZ	S )rt  zZRepresentation for a line consisting of two parametric SymPy expressions
    over a range.Tc                 h   t        |   di | t        |      r|n
t        |      | _        t        |      r|n
t        |      | _        | j                  | j
                  f| _        |g| _        t        | _	        |j                  dd      | _        | j                  |       | j                          y )Nr   TrI   )r  r   r   r   expr_xexpr_yr>   r   r  r  r   r   r;  r;  )r2   rH  rI  r	  r   r   r  s         r3   r   zParametric2DLineSeries.__init__N  s    "6" ( 0fgfo ( 0fgfo[[$++.	$o
jj40''.rA   c                     | j                  dt        | j                        dt        | j                        dt        | j                        dt        | j
                  | j                  f            S )Nzparametric cartesian line: (, ) for r  )r  r   rH  rI  r  r   r   r  s    r3   r  zParametric2DLineSeries.__str__Y  sR    MTXX&'	
 	rA   c           	         	 t        | j                        r.t        | j                        r| j                  }| j                  }nBt        | j                  g| j                        }t        | j                  g| j                        }| j                  ||      \  }}}|||fS # t        $ r}t        j                  d| j                  sdn| j                  z  dj                  t        |      j                  |      z   dz          t        | j                  g| j                  d      }t        | j                  g| j                  d      }| j                  ||      \  }}}Y d }~d }~ww xY wr  )r   rH  rI  r$   r  r  ri   ra   rb   rJ   r^   r_   rE   )r2   f_xf_yrs   rt   r6  rc   s          r3   r  z)Parametric2DLineSeries._adaptive_samplingb  s*   	?$$++)>kkkkz4;;7z4;;744S#>GAq! !Qw  
	?MM2)-M4<<I!!$s)"4"4c:;'' DHH:t{{G<CDHH:t{{G<C44S#>GAq!
	?s   BB" "	E(+B3E##E(c                    	
 g g g 		
 fd
t         j                        }t         j                        }||g}t         j                        }t         j                        }||g}j                  |       j                  |       	j                   j                          
 j                   j                  ||d       	fS )aW  The adaptive sampling is done by recursively checking if three
        points are almost collinear. If they are not collinear, then more
        points are added between those points.

        References
        ==========

        .. [1] Adaptive polygonal approximation of parametric curves,
            Luiz Henrique de Figueiredo.
        c           	      d   t        d      }d|j                  j                         dz  z   }| ||| z
  z  z   }t        |      }t        |      }	|j	                  ||	g      }
|j
                  kD  r:j                  |d          j                  |d          j                  |        y|dk  r | |||
|dz           |||
||dz          y|d   |d   
|d   |d   |j                  | |d      }|D cg c]  }t        |       }}|D cg c]  }t        |       }}t        d	 t        ||      D              sht        t        |      dz
        D ]M  }||   ||   ||dz      ||dz      ||   ||   g}||dz      ||dz      g} ||   ||   |||dz          O yy|d   |d   |d   |d   t        ||
|      s | |||
|dz           |||
||dz          yj                  |d          j                  |d          j                  |        yc c}w c c}w )
r  rN   r  r  r   r%   rs  Nr  c              3   6   K   | ]  \  }}|d u xr |d u   y wr+   rI   )r/   rs   rt   s      r3   r4   zSParametric2DLineSeries._adaptive_sampling_helper.<locals>.sample.<locals>.<genexpr>  s,      >#q! 92d2 >s   )r   r   r!  ru   r  r  r   rI  r   r   r  r   r$  )param_pparam_qr6  r%  r  rU   r   	param_newr&  r'  r(  param_arrayr   x_arrayy_arrayr   point_apoint_brN  rO  paramr+  r2   r,  r-  s                     r3   r+  z@Parametric2DLineSeries._adaptive_sampling_helper.<locals>.sample  s    w'BBIINN,s22F&Gg,=">>I!#y1D!#y1D$.I tzz!!%!%W% w	1iCy'9aC
 Q4<AaDLqT\adl kk'7B?;FGa>#q1GG;FGa>#q1GG >'*7G'<> >"3w<!#34 7$QZ3
8N!(Q!;A@Z'.qz71:&>G'.q1u~wq1u~&FG";q>;q>7#*EAI77> A$,!A$,t|qt|9a0w	1iCy'9aC!%!%W%- HGs   ;H(H-r   )ru   r   r   r   )r2   rN  rO  	f_start_x	f_start_yr   f_end_xf_end_yr   r[  r+  r,  r-  s   ```      @@@@r3   r  z0Parametric2DLineSeries._adaptive_sampling_helperx  s     6	& 6	&p #3

3	"3

3	I& dhh/ dhh/ 	"	"TZZ tzz488UC35((rA   r  )
rE   rF   rG   rH   r!  r   r  r  r  r  r  s   @r3   rt  rt  H  s$     I	,R)rA   rt  c                   .     e Zd ZdZdZdZdZ fdZ xZS )Line3DBaseSerieszSA base class for 3D lines.

    Most of the stuff is derived from Line2DBaseSeries.FTrS  c                 "    t         |           y r+   )r  r   )r2   r  s    r3   r   zLine3DBaseSeries.__init__  s    rA   )	rE   rF   rG   rH   r!  r  r  r   r  r  s   @r3   ra  ra    s#    ; IID rA   ra  c                   <     e Zd ZdZdZdZd fd	Zd Z fdZ xZ	S )ru  z^Representation for a 3D line consisting of three parametric SymPy
    expressions and a range.FTc                    t        |   di | t        |      r|n
t        |      | _        t        |      r|n
t        |      | _        t        |      r|n
t        |      | _        | j                  | j
                  | j                  f| _        |g| _        t        | _
        d| _        |j                  dd      | _        | j                  |       | j                          d | _        d | _        d | _        y )NFr   TrI   )r  r   r   r   rH  rI  expr_zr>   r   r  r  r:  r   r   r;  r;  _xlim_ylim_zlim)r2   rH  rI  re  r	  r   r   r  s          r3   r   zParametric3DLineSeries.__init__  s    "6" ( 0fgfo ( 0fgfo ( 0fgfo[[$++t{{;	$o
jj40''.


rA   c                    | j                  dt        | j                        dt        | j                        dt        | j                        dt        | j
                        dt        | j                  | j                  f      
      S )Nz3D parametric cartesian line: (rK  rL  r  )r  r   rH  rI  re  r  r   r   r  s    r3   r  zParametric3DLineSeries.__str__  s^    MTXX&'
 	rA   c                 6   t        d      }t        | 	         \  }}}}|j                  |      |j	                  |      f| _        |j                  |      |j	                  |      f| _        |j                  |      |j	                  |      f| _        ||||fS r1  )r   r  r_  aminamaxrf  rg  rh  )r2   rU   rs   rt   rw  r6  r  s         r3   r_  zParametric3DLineSeries.get_data  s    7#W%'
1aggaj"''!*-
ggaj"''!*-
ggaj"''!*-
!QzrA   r  )
rE   rF   rG   rH   r!  r  r   r  r_  r  r  s   @r3   ru  ru    s(      II" rA   ru  c                   2     e Zd ZdZdZ fdZd Zd Z xZS )SurfaceBaseSerieszA base class for 3D surfaces.Tc                 Z   t        |   di | |j                  dd      | _        |j                  d|j                  dd            | _        |j                  dd       | _        |j                  dd       | _        t        | j
                        r| j
                  | _        d | _        y y )	Nr   Fr   r   rC  r   c                     |S r+   rI   )rs   rt   rw  s      r3   r   z,SurfaceBaseSeries.__init__.<locals>.<lambda>  s    1 rA   rI   )r  r   r   r   r   rC  r   r   r2   r<   r   r  s      r3   r   zSurfaceBaseSeries.__init__  s    "6"jj51 

:vzz'5/IJ#ZZ> **\3DED&&'"00DO!%D (rA   c                    | j                   }|t        |      n|| _        |t        |      n|| _        t        |d      st        |      nt        d |D              }|r(| j                  t        |      k(  rd| _        d| _        y y y )Nr   c              3   2   K   | ]  }t        |        y wr+   r   r   s     r3   r4   z7SurfaceBaseSeries._set_surface_label.<locals>.<genexpr>&  s     0QXa[0r   r   )r>   r   r   r   r   r   r   r   )r2   r   r   	is_lambdas       r3   _set_surface_labelz$SurfaceBaseSeries._set_surface_label  s{    		$)Mc%ju,1ME%Lu -4E:,FXe_0%00 	$++U3 $&! 49rA   c                    t        d      }| j                  }t        |t              r|j	                  |      }t        |      }| j                  rAt        t        t        | j                                     }|dk(  r ||d         S |dk(  r || S t        t        t        | j                                     }|dk(  r ||d         S |dk(  r ||d d  S  || S t        | t              r2||j                  t        | j                  | j                               z  S ||j                  t        | j"                  | j$                              z  S )NrN   r%   r   r   )r   rC  rm   r   rh   r	   rW  r  r  centers_of_facesget_parameter_meshes
get_meshesSurfaceOver2DRangeSeriesr  r  nb_of_points_xnb_of_points_ynb_of_points_unb_of_points_v)r2   rU   r  rr   r[  r  s         r3   r  z!SurfaceBaseSeries.get_color_array+  s*   7#a"QA!HE!! %5t7P7P7R!ST	A:Yq\?*aZi=(S!14??3DEFIz1&!)BQ-(()}$$ 89T%8%8$:M:M!NOOOT%8%8$:M:M!NOOOrA   )	rE   rF   rG   rH   r   r   ru  r  r  r  s   @r3   rn  rn    s    'L&"'PrA   rn  c                        e Zd ZdZd fd	Zed        Zed        Zed        Zed        Z	ed        Z
ed        Zed	        Zej                  d
        Zed        Zej                  d        Zd Zd Zd Z xZS )rz  zRRepresentation for a 3D surface consisting of a SymPy expression and 2D
    range.c                 &   t        |   di | t        |      r|n
t        |      | _        ||g| _        | j                  |       | j                          | j                  | j                  f| _
        | j                  | j                  f| _        y )NrI   )r  r   r   r   r>   r   ru  r;  start_xend_xrf  start_yend_yrg  )r2   r>   var_start_end_xvar_start_end_yr   r   r  s         r3   r   z!SurfaceOver2DRangeSeries.__init__I  sr    "6"$TND	&8&llDJJ/
llDJJ/
rA   c                 &    | j                   d   d   S r@  r  r  s    r3   var_xzSurfaceOver2DRangeSeries.var_xS      {{1~a  rA   c                 &    | j                   d   d   S Nr%   r   r  r  s    r3   var_yzSurfaceOver2DRangeSeries.var_yW  r  rA   c                 |    	 t        | j                  d   d         S # t        $ r | j                  d   d   cY S w xY wr  r  r   r   r  s    r3   r  z SurfaceOver2DRangeSeries.start_x[  A    	%Q*++ 	%;;q>!$$	%    ;;c                 |    	 t        | j                  d   d         S # t        $ r | j                  d   d   cY S w xY wr  r  r  s    r3   r  zSurfaceOver2DRangeSeries.end_xb  r  r  c                 |    	 t        | j                  d   d         S # t        $ r | j                  d   d   cY S w xY wNr%   r  r  s    r3   r  z SurfaceOver2DRangeSeries.start_yi  r  r  c                 |    	 t        | j                  d   d         S # t        $ r | j                  d   d   cY S w xY wNr%   r   r  r  s    r3   r  zSurfaceOver2DRangeSeries.end_yp  r  r  c                      | j                   d   S r@  r  r  s    r3   r{  z'SurfaceOver2DRangeSeries.nb_of_points_xw  r  rA   c                 4    | j                   }||dd  g| _         y r  r  r2   r2  r   s      r3   r{  z'SurfaceOver2DRangeSeries.nb_of_points_x{      FFQqrUrA   c                      | j                   d   S r  r  r  s    r3   r|  z'SurfaceOver2DRangeSeries.nb_of_points_y  r  rA   c                 <    | j                   }|d   ||d   g| _         y r  r  r  s      r3   r|  z'SurfaceOver2DRangeSeries.nb_of_points_y       FFA$1Q4rA   c                 V   | j                   rdnd}| j                  |dt        | j                        dt        | j                        dt        | j
                  | j                  f      dt        | j                        dt        | j                  | j                  f      
z         S )Nzcartesian surfacecontourz: r  r   and )
r   r  r   r>   r  r  r  r  r  r  )r2   series_types     r3   r  z SurfaceOver2DRangeSeries.__str__  s{    -1->->)I		N

OS$,,

!;<

OS$,,

!;<
 
 	rA   c                 "    | j                         S )Return the x,y,z coordinates for plotting the surface.
        This function is available for back-compatibility purposes. Consider
        using ``get_data()`` instead.
        rB  r  s    r3   ry  z#SurfaceOver2DRangeSeries.get_meshes  s    
 }}rA   c                 F   t        d      }| j                         }t        |      D ]i  \  }}|j                  |      |j	                  |      }}|j
                  ||j                  |j                  ||j                  |                  <   |||<   k |\  }}}	| j                  rD| j                  r8|j                         }||j                  |      z  }||j                  |      z  }|j                  |	      |j                  |	      f| _        | j#                  |||	      S )a  Return arrays of coordinates for plotting.

        Returns
        =======
        mesh_x : np.ndarray
            Discretized x-domain.
        mesh_y : np.ndarray
            Discretized y-domain.
        mesh_z : np.ndarray
            Results of the evaluation.
        rN   )r   r
  r   rq   rp   rS   rT  rU  rV  r   r   r   cossinrk  rl  rh  r~  
r2   rU   r	  r   r   rY  rZ  rs   rt   rw  s
             r3   r_  z!SurfaceOver2DRangeSeries.get_data  s     7#.."g& 	DAqwwqz2771:CBD&&C		"**S"--*<=>?GAJ	
 1a==T..ABFF1IABFF1IA ggaj"''!*-
$$Q1--rA   r  )rE   rF   rG   rH   r   r  r  r  r  r  r  r  r{  r  r|  r  ry  r_  r  r  s   @r3   rz  rz  E  s    0 ! ! ! ! % % % % % % % %       ! !.rA   rz  c                   
    e Zd ZdZdZ	 d fd	Zed        Zed        Zed        Z	ed        Z
ed        Zed	        Zed
        Zej                  d        Zed        Zej                  d        Zd Zd Zd Zd Z xZS )rv  zaRepresentation for a 3D surface consisting of three parametric SymPy
    expressions and a range.Tc                    t        |   di | t        |      r|n
t        |      | _        t        |      r|n
t        |      | _        t        |      r|n
t        |      | _        | j                  | j
                  | j                  f| _        ||g| _        |j                  dd       | _
        | j                  |       | j                          y )Nr   c                     |S r+   rI   )rs   rt   rw  rx  r2  s        r3   r   z2ParametricSurfaceSeries.__init__.<locals>.<lambda>  s     rA   rI   )r  r   r   r   rH  rI  re  r>   r   r   r   ru  r;  )	r2   rH  rI  re  var_start_end_uvar_start_end_vr   r   r  s	           r3   r   z ParametricSurfaceSeries.__init__  s    "6" ( 0fgfo ( 0fgfo ( 0fgfo[[$++t{{;	&8 **\3JK&rA   c                 &    | j                   d   d   S r@  r  r  s    r3   var_uzParametricSurfaceSeries.var_u  r  rA   c                 &    | j                   d   d   S r  r  r  s    r3   var_vzParametricSurfaceSeries.var_v  r  rA   c                 |    	 t        | j                  d   d         S # t        $ r | j                  d   d   cY S w xY wr  r  r  s    r3   start_uzParametricSurfaceSeries.start_u  r  r  c                 |    	 t        | j                  d   d         S # t        $ r | j                  d   d   cY S w xY wr  r  r  s    r3   end_uzParametricSurfaceSeries.end_u  r  r  c                 |    	 t        | j                  d   d         S # t        $ r | j                  d   d   cY S w xY wr  r  r  s    r3   start_vzParametricSurfaceSeries.start_v  r  r  c                 |    	 t        | j                  d   d         S # t        $ r | j                  d   d   cY S w xY wr  r  r  s    r3   end_vzParametricSurfaceSeries.end_v  r  r  c                      | j                   d   S r@  r  r  s    r3   r}  z&ParametricSurfaceSeries.nb_of_points_u  r  rA   c                 4    | j                   }||dd  g| _         y r  r  r  s      r3   r}  z&ParametricSurfaceSeries.nb_of_points_u  r  rA   c                      | j                   d   S r  r  r  s    r3   r~  z&ParametricSurfaceSeries.nb_of_points_v  r  rA   c                 <    | j                   }|d   ||d   g| _         y r  r  r  s      r3   r~  z&ParametricSurfaceSeries.nb_of_points_v  r  rA   c                    | j                  dt        | j                        dt        | j                        dt        | j                        dt        | j
                        dt        | j                  | j                  f      dt        | j                        dt        | j                  | j                  f            S )Nzparametric cartesian surface: (rK  rL  r  r  )r  r   rH  rI  re  r  r  r  r  r  r  r  s    r3   r  zParametricSurfaceSeries.__str__  s|     c$++.DKK0@

OS$,,

!;<

OS$,,

!;<	
 	rA   c                 (    | j                         dd  S )NrS  rB  r  s    r3   rx  z,ParametricSurfaceSeries.get_parameter_meshes  s    }}qr""rA   c                 (    | j                         dd S )r  NrS  rB  r  s    r3   ry  z"ParametricSurfaceSeries.get_meshes  s    
 }}r""rA   c                 V   t        d      }| j                         }t        |      D ]i  \  }}|j                  |      |j	                  |      }}|j
                  ||j                  |j                  ||j                  |                  <   |||<   k |dd \  }}}	|j                  |      |j                  |      f| _        |j                  |      |j                  |      f| _        |j                  |	      |j                  |	      f| _         | j                  g |dd |dd  S )a  Return arrays of coordinates for plotting.

        Returns
        =======
        x : np.ndarray [n2 x n1]
            x-coordinates.
        y : np.ndarray [n2 x n1]
            y-coordinates.
        z : np.ndarray [n2 x n1]
            z-coordinates.
        mesh_u : np.ndarray [n2 x n1]
            Discretized u range.
        mesh_v : np.ndarray [n2 x n1]
            Discretized v range.
        rN   r   N)r   r
  r   rq   rp   rS   rT  rU  rV  rk  rl  rf  rg  rh  r~  r  s
             r3   r_  z ParametricSurfaceSeries.get_data  s     7#.."g& 	DAqwwqz2771:CBD&&C		"**S"--*<=>?GAJ	 !"+1aggaj"''!*-
ggaj"''!*-
ggaj"''!*-
$t$$@gabk@GBQK@@rA   r  )rE   rF   rG   rH   rW  r   r  r  r  r  r  r  r  r}  r  r~  r  rx  ry  r_  r  r  s   @r3   rv  rv    s     M 13
 ! ! ! ! % % % % % % % %       ! !##ArA   rv  c                   *     e Zd ZdZdZdZ fdZ xZS )ContourSeriesz"Representation for a contour plot.FTc                     t        |   |i | |j                  d|j                  dd            | _        |j                  dd      | _        |j                  d|j                  di             | _        y )Nr  r  Tclabels
contour_kwr   )r  r   r   r  show_clabelsr   rq  s      r3   r   zContourSeries.__init__>  sh    $)&)KFD1IJ"JJy$7
 #JJ|JJ~r*,rA   )rE   rF   rG   rH   r   r  r   r  r  s   @r3   r  r  8  s    ,LJ	, 	,rA   r  c                        e Zd ZdZdZd Zd Zy)GenericDataSeriesal  Represents generic numerical data.

    Notes
    =====
    This class serves the purpose of back-compatibility with the "markers,
    annotations, fill, rectangles" keyword arguments that represent
    user-provided numerical data. In particular, it solves the problem of
    combining together two or more plot-objects with the ``extend`` or
    ``append`` methods: user-provided numerical data is also taken into
    consideration because it is stored in this series class.

    Also note that the current implementation is far from optimal, as each
    keyword argument is stored into an attribute in the ``Plot`` class, which
    requires a hard-coded if-statement in the ``MatplotlibBackend`` class.
    The implementation suggests that it is ok to add attributes and
    if-statements to provide more and more functionalities for user-provided
    numerical data (e.g. adding horizontal lines, or vertical lines, or bar
    plots, etc). However, in doing so one would reinvent the wheel: plotting
    libraries (like Matplotlib) already implements the necessary API.

    Instead of adding more keyword arguments and attributes, users interested
    in adding custom numerical data to a plot should retrieve the figure
    created by this plotting module. For example, this code:

    .. plot::
       :context: close-figs
       :include-source: True

       from sympy import Symbol, plot, cos
       x = Symbol("x")
       p = plot(cos(x), markers=[{"args": [[0, 1, 2], [0, 1, -1], "*"]}])

    Becomes:

    .. plot::
       :context: close-figs
       :include-source: True

       p = plot(cos(x), backend="matplotlib")
       fig, ax = p._backend.fig, p._backend.ax[0]
       ax.plot([0, 1, 2], [0, 1, -1], "*")
       fig

    Which is far better in terms of readibility. Also, it gives access to the
    full plotting library capabilities, without the need to reinvent the wheel.
    Tc                 .    || _         || _        || _        y r+   )r_   r<   r   )r2   r   r<   r   s       r3   r   zGenericDataSeries.__init__{  s    		"rA   c                     | j                   S r+   )r<   r  s    r3   r_  zGenericDataSeries.get_data  s    yyrA   N)rE   rF   rG   rH   r  r   r_  rI   rA   r3   r  r  J  s    -\ J#
rA   r  c                        e Zd ZdZdZdZdZd fd	Zed        Z	e	j                  d        Z	ed        Zej                  d	        ZeZd
 Zd Zd Zd Zd Zd Zed        ZddZ xZS )ImplicitSeriesz$Representation for 2D Implicit plot.TFr~   c                 T   t        |   d
i | |j                  dd      | _        || _        |t        |      n|| _        |t        |      n|| _        ||g| _	        | j                  d   \  | _
        | _        | _        | j                  d   \  | _        | _        | _        |j                  d|j                  dd             | _        | j"                  r| j                  rt%        d      |j                  dd      }|d	kD  rd	}n|dk  rd}d	|z   | _        | j)                          y )Nr:  Fr   r%   rX  r+  z7Interactive plot with `adaptive=True` is not supported.r  rq  rI   )r  r   r   r:  r>   r   r   r   r   r   r  r  r  r  r  r  _colorr   r^  r  r;  )r2   r>   r  r  r   r   r  r  s          r3   r   zImplicitSeries.__init__  s   "6"

:u5	#(=c$ie+0=E$Ke&8/3{{1~,
DL$*/3{{1~,
DL$*jj&**\4*HI4==% '$ % % 

7A&19EQYEY
rA   c                 J    | j                   r| j                  S | j                  S r+   )r:  _adaptive_expr_non_adaptive_exprr  s    r3   r>   zImplicitSeries.expr  s!    ==&&&&&&rA   c                 
   | j                  |       | j                  t        |            \  }}|| _        || _        t        |      | _        t        |      | _        t        |t        t        f      rE| j                  s9d| _        d}t        |t              rd}t        j                  d|z   dz   dz          t        |t              rd | _        d| _        y | j#                  || j                        \  }}|| _        || _        y )NTzcontains Boolean functions. zis an unequality. zThe provided expression z/In order to plot the expression, the algorithm z/automatically switched to an adaptive sampling.F)r   _has_equalityr   r  has_equalityr   r   r   r   rm   r   r   r:  ra   rb   r  _is_equality_preprocess_meshgrid_expression)r2   r>   r  rd   is_equalitys        r3   r>   zImplicitSeries.expr  s    $$T*!//>l"($i!$Kd_b12DMM DM0C$#*MM*S0CDCD dO,&*D# %D !% D DT4== YD+&*D# +DrA   c                     | j                   S r+   r  r  s    r3   r+  zImplicitSeries.line_color  s    {{rA   c                     || _         y r+   r  r1  s     r3   r+  zImplicitSeries.line_color  r  rA   c                     d}fdg t        |t              r  |       t        d D              rd}||fS t        |t              st	        |d      }d}||fS t        |t        t
        t        f      rd}||fS )NFc                     | j                   D ]=  }t        |t              r	 |       t        |t              s-j	                  |       ? y)z8Recursively expands the arguments of an Boolean FunctionN)r<   rm   r   r   r   )	bool_exprrx   
arg_expandarg_lists     r3   r  z0ImplicitSeries._has_equality.<locals>.arg_expand  s=     ~~ )c?3sOZ0OOC(	)rA   c              3   R   K   | ]  }t        |t        t        t        f       ! y wr+   )rm   r   r   r   r   s     r3   r4   z/ImplicitSeries._has_equality.<locals>.<genexpr>  s     V:a(K!BCVs   %'Tr   )rm   r   r   r   r   r   r   )r2   r>   r  r  r  s      @@r3   r  zImplicitSeries._has_equality  s     	) dO,tVXVV# \!! D*-D!$DL \!! xh?@L\!!rA   c                 X   d }| j                  d      t        | j                        t        | j                        t         || j                         || j
                        f      t        | j                        t         || j                         || j                        f      fz  S )Nc                 L    t        | j                        dk(  rt        |       S | S r@  )r   r   r  r   s    r3   r   z(ImplicitSeries.__str__.<locals>.<lambda>  s    #ann"5":eAh  rA   z5Implicit expression: %s for %s over %s and %s over %s)	r  r   r  r  r  r  r  r  r  )r2   rr   s     r3   r  zImplicitSeries.__str__  s    ACE##$

O4<<!DJJ-01

O4<<!DJJ-01H

 	
rA   c                 b    | j                   r| j                         }||S | j                         S )a  Returns numerical data.

        Returns
        =======

        If the series is evaluated with the `adaptive=True` it returns:

        interval_list : list
            List of bounding rectangular intervals to be postprocessed and
            eventually used with Matplotlib's ``fill`` command.
        dummy : str
            A string containing ``"fill"``.

        Otherwise, it returns 2D numpy arrays to be used with Matplotlib's
        ``contour`` or ``contourf`` commands:

        x_array : np.ndarray
        y_array : np.ndarray
        z_array : np.ndarray
        plot_type : str
            A string specifying which plot command to use, ``"contour"``
            or ``"contourf"``.
        )r:  ru   _get_meshes_gridr  s     r3   r_  zImplicitSeries.get_data  s3    0 ==&&(D$$&&rA   c                 >   ddl mc mc m} i }t	        ddd|d      }t        |      D cg c]  }d|vs|dvs| }}|D cg c]  }t        ||       }}t        t        ||            }t        | j                  | j                  f| j                  |g|      }	d}
	 | j                  |	      }
|
S c c}w c c}w # t        $ r-}t        j                   d	|z  d
z          d| _        Y d}~|
S d}~wt$        $ r  t        j                   d       d| _        Y |
S w xY w)aN  
        References
        ==========

        .. [1] Jeffrey Allen Tupper. Reliable Two-Dimensional Graphing Methods for
        Mathematical Formulae with Two Free Variables.

        .. [2] Jeffrey Allen Tupper. Graphing Equations with Generalized Interval
        Arithmetic. Master's thesis. University of Toronto, 1996
        r   NFT)fully_qualified_modulesinlineallow_unknown_functionsuser_functions__)r   r&   )rJ   printerzAdaptive meshing could not be applied to the expression, as some functions are not yet implemented in the interval math module:

NameError: %s

z Proceeding with uniform meshing.zOAdaptive meshing could not be applied to the expression. Using uniform meshing.)(sympy.plotting.intervalmath.lib_intervalplottingintervalmathlib_intervalr(   dirgetattrr   r   r$   r  r  r>   _get_raster_interval	NameErrorra   rb   r:  r   )r2   lir  r  r   r   r  valsr   rT   r  rc   s               r3   ru   zImplicitSeries._adaptive_eval	  s9    	>=%','+,'. /
 r7cat1}1Da;acc(,-1A--T4!TZZ0$))aSRYZ	",,T2D  / d-  	"MM$ '** 3	3 "DMM   	"MM67 "DM	"s3   	B5B5B5B:"B? ?	D"C00(DDc                 v   t        d      }| j                  }g }| j                  | j                  fD cg c]  }t	        |       c}\  }}| j
                  | j                  fD cg c]  }t	        |       c}\  }}	|j                  ||d      }
|j                  ||	d      }|j                  j                  t        |
            dz  dz
  ||z
  z  dz  }|j                  j                  t        |            dz  dz
  |	|z
  z  dz  }|
|z  }
||z  }t        |
dd |
dd       D cg c]  \  }}t        ||       }}}t        |dd |dd       D cg c]  \  }}t        ||       }}}|D cg c]  }|D ]  }||g  }}}g }fd}|d	k\  r=t        |      r2 ||      \  }}|j                  |       |dz
  }|d	k\  rt        |      r2| j                  r;|D ]6  }|d	   }|d   } ||      }|d   s|d	   d
us$|j                  ||g       8 |dfS c c}w c c}w c c}}w c c}}w c c}}w )z9Uses interval math to adaptively mesh and obtain the plotrN   !   r   r%   i   Nr  c                 *   g }g }| D ]  }|d   }|d   } ||      }|d   du s|d   du r&|dk(  r|j                  ||g       ?|d   |d   J|j                  }|j                  }t        |j                  |      }	t        ||j                        }
t        |j                  |      }t        ||j                        }|j                  |	|g       |j                  |	|g       |j                  |
|g       |j                  |
|g        ||fS )ziEvaluates the intervals and subdivides the interval if the
            expression is partially satisfied.r   r%   F)TT)r   midr&   r   r   )interval_listtemp_interval_list	plot_list	intervals	intervalx	intervaly	func_evalavgxavgyr0   rQ  r  r   rT   s                r3   refine_pixelsz:ImplicitSeries._get_raster_interval.<locals>.refine_pixelsf	  s0    "$I* 6	 &aL	%aL	 I6	 Q<5(IaLE,A,.$$i%;<q\)Yq\-A$==D$==D $7A y}}5A $7A y}}5A&--q!f5&--q!f5&--q!f5&--q!f5/60 &y00rA   r   Fr  )r   r  r  r  r  r  r  rI  r   r!  r   r   r&   extendr  r   )r2   rT   rU   r  r  r   sxsyexeyxsampleysamplejitterxjitteryx1x2xintery1y2yinterrs   rt   r  r  plot_list_tempr  r  r  r  s    `                           r3   r  z#ImplicitSeries._get_raster_intervalC	  sf   7#JJ%)\\4<<$@Aq%(AB%)ZZ$<=q%(=B++b"b)++b"b) YY^^CL)A-1Bw 	 YY^^CL)A-1Bw 	
 	7714WSb\712;1OPvr2(2r"PP14WSb\712;1OPvr2(2r"PP)/@A@A!Q@@@		1> 1f]+,9-,H)M>^,AA 1f]+ * =	%aL	%aL	 I6	Q<IaL$=$$i%;<= &  W B=* QP@s   H'H$*H)H/6H5c           
      .   t        d      }| j                         \  }}}|j                  |      |j                  |      }}|j                  ||j                  |j                  ||j                  |                  <   | j                  r|||dfS |||dfS )zGenerates the mesh for generating a contour.

        In the case of equality, ``contour`` function of matplotlib can
        be used. In other cases, matplotlib's ``contourf`` is used.
        rN   r  contourf)	r   r
  rq   rp   rS   rT  rU  rV  r  )r2   rU   r)  r*  z_gridrY  rZ  s          r3   r  zImplicitSeries._get_meshes_grid	  s     7#!%!1776?BGGFOS>@ffBIIbjjbmmC&89:;63	11vsJ..rA   c                     d}t        | t              r| j                  | j                  z
  } d}| |fS t        | t              r| j
                  | j                  z
  } | |fS |st        d      | |fS )a  If the expression is a Relational, rewrite it as a single
        expression.

        Returns
        =======

        expr : Expr
            The rewritten expression

        equality : Boolean
            Wheter the original expression was an Equality or not.
        FTzDThe expression is not supported for plotting in uniform meshed plot.)rm   r   lhsrhsr   gtsltsr^  )r>   r:  equalitys      r3   r  z.ImplicitSeries._preprocess_meshgrid_expression	  s     dH%88dhh&DH X~ j)88dhh&D X~ %3  X~rA   c                     |du r| j                   S | j                   t        | j                        k(  r| j                  | j                  |      S | j                  S rc  )r   r   r  ra  r   rd  s      r3   rf  zImplicitSeries.get_label	  sR      ;;;;#d1122**4+<+<gFF   rA   r  r  )rE   rF   rG   rH   r   r   r   r   r  r>   r  r+  rX  r  r  r_  ru   r  r  r  r  rf  r  r  s   @r3   r  r    s    .KF	B0 ' '
 
[[, ,:     E"6

'>*XQ!f/  4!rA   r  c                 j    t        d      }|j                  |j                  | d d | dd  f      d      S )NrN   r  r%   r   )r   meanvstackr  rU   s     r3   r  r  	  s7    	w	B77299eCRj%)45q99rA   c                     t        d      }|j                  |j                  | d dd df   | dd d df   | d ddd f   | d dd df   f      d      S )NrN   r  r%   r   )r   r  dstackr   s     r3   rw  rw  	  sy    	w	B77299eCRC"Ho"12ss7^"3B37^"3B38_   "#	$ $rA   c                 :   t        d      }| |z
  j                  t              }||z
  j                  t              }|j                  ||      }|j                  j                  |      }|j                  j                  |      }	|||	z  z  }
t        |
dz         |k  S )z0Checks whether three points are almost collinearrN   r%   )r   r   r  dotlinalgnormrw   )rs   rt   rw  r  rU   vector_avector_bdot_productvector_a_normvector_b_norm	cos_thetas              r3   r$  r$  	  s    	w	BA~~e$HA~~e$H&&8,KIINN8,MIINN8,M}}<=Iy1}##rA   c                 (   ddddddd}|j                         D ],  \  }}|| j                         v s| j                  |      | |<   . |t        t        t
        fv rGd| j                         v r3| d   | d<   t        | d   d      rt        | d         dkD  r| d   d   | d<   | S |t        t        t        t        fv rWd| j                         v rEt        | d   d      r)t        | d         dkD  r| d   d   | d<   | d   d   | d<   | S | d   x| d<   | d<   | S )a  Allow the use of the keyword arguments ``n, n1, n2`` to
    specify the number of discretization points in one and two
    directions, while keeping back-compatibility with older keyword arguments
    like, ``nb_of_points, nb_of_points_*, points``.

    Parameters
    ==========

    kwargs : dict
        Dictionary of keyword arguments passed into a plotting function.
    pt : type
        The type of the series, which indicates the kind of plot we are
        trying to create.
    r   r   r   )r  r{  r|  r}  r~  r  r   r   r%   )itemsr   popr  rt  ru  r   r   rz  r  rv  r  )r   ptreplace_old_keywordsr  r2  s        r3   r   r   	  sO      %**, &1

1F1I& 
#%;   &++-!#;F4Lvc{J/S5E5I%c{1~t M 
(-1 
1&++-vc{J/S5E5I%c{1~t%c{1~t M /5Sk9tvd|MrA   )r  NNF)gMbP?)Rcollections.abcr   sympy.calculus.utilr   sympy.concreter   r   sympy.core.containersr   sympy.core.exprr   sympy.core.functionr	   sympy.core.sortingr
   sympy.core.symbolr   sympy.functionsr   r   r   r   r   r   sympy.core.relationalr   r   r   r   r   sympy.core.sympifyr   sympy.externalr   sympy.logic.boolalgr   sympy.plotting.utilsr   r   sympy.printing.latexr   sympy.printing.pycoder   sympy.printing.precedencer   sympy.sets.setsr   r    r!   sympy.simplify.simplifyr"   sympy.utilities.exceptionsr#   sympy.utilities.lambdifyr$   r  r&   ra   r(   rk   ru   r{   r}   r  r  r  r  r  r8  rt  ra  ru  rn  rz  rv  r  r  r  r  rw  r$  r   rI   rA   r3   <module>rG     sn   $ 1 ' '   % / $ A A  & ( / D & 3 0 0 0 - @ - " B+ B  *.5,%^,
b bJ2Bm0z m0`9# 9xL, L^m/ m`B)5 B)L
' 
)5 )Z:P
 :Pzr.0 r.jzA/ zA|,, ,$7
 7tP!Z P!n
:
$
$)rA   