
    wg9                        d 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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! 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) 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/ ddlm0Z0 ddl1m2Z2 dgdgdZ3d Z4d Z5d  Z6d! Z7d" Z8eed#Z9d$d%d&Z:d$d%d'Z;d$d%d(Z<d) Z=d$d%d*Z>d$d%d+Z?d$d%d,Z@d- ZAy.)/a   Plotting module for SymPy.

A plot is represented by the ``Plot`` class that contains a reference to the
backend and a list of the data series to be plotted. The data series are
instances of classes meant to simplify getting points and meshes from SymPy
expressions. ``plot_backends`` is a dictionary with all the backends.

This module gives only the essential. For all the fancy stuff use directly
the backend. You can get the backend wrapper for every plot from the
``_backend`` attribute. Moreover the data series classes have various useful
methods like ``get_points``, ``get_meshes``, etc, that may
be useful if you wish to use another plotting library.

Especially if you need publication ready graphs and this module is not enough
for you - just get the ``_backend`` attribute and add whatever you want
directly to it. In the case of matplotlib (the common way to graph data in
python) just copy ``_backend.fig`` which is the figure and ``_backend.ax``
which is the axis and work on them as you would on any other matplotlib object.

Simplicity of code takes much greater importance than performance. Do not use it
if you care at all about performance. A new backend instance is initialized
every time you call ``show()`` and the old one is left to the garbage collector.
    )Sum)Tuple)Expr)FunctionAppliedUndef)DummySymbolWild)import_module)sign)Plot)MatplotlibBackend)TextBackend)LineOver1DRangeSeriesParametric2DLineSeriesParametric3DLineSeriesParametricSurfaceSeriesSurfaceOver2DRangeSeriesContourSeries)_check_arguments_plot_sympify)Indexed)PlotGrid)
BaseSeries)Line2DBaseSeries)Line3DBaseSeries)SurfaceBaseSeries)List2DSeries)GenericDataSeries)centers_of_faces)centers_of_segments)flat)
unset_show)_matplotlib_list)textplot
matplotlib))plot3dplot3d_parametric_lineplot3d_parametric_surfaceplot_parametric)plotc                 d   d }t        |      }|d   }t        dd d g      }t        |j                  |            D ]i  }t        |j                        }t	        |      D ]*  \  }}|dkD  s|d    ||d   |        ||d   |       f||<   , t        | }	|j                  ||	      }k ||d<   |S )	a  Substitute oo (infinity) in the lower/upper bounds of a summation with
    some integer number.

    Parameters
    ==========

    sum_bound : int
        oo will be substituted with this integer number.
    *args : list/tuple
        pre-processed arguments of the form (expr, range, ...)

    Notes
    =====
    Let's consider the following summation: ``Sum(1 / x**2, (x, 1, oo))``.
    The current implementation of lambdify (SymPy 1.12 at the time of
    writing this) will create something of this form:
    ``sum(1 / x**2 for x in range(1, INF))``
    The problem is that ``type(INF)`` is float, while ``range`` requires
    integers: the evaluation fails.
    Instead of modifying ``lambdify`` (which requires a deep knowledge), just
    replace it with some integer number.
    c                 \    | j                   r| j                  r| S t        |       dk\  r|S | S )Nr   )	is_number	is_finiter   )tbounds     X/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/sympy/plotting/plot.py	new_boundz&_process_summations.<locals>.new_boundZ   s+    H7a<Lv    r   wc                 "    t        | t              S N)
isinstancer   r0   s    r2   <lambda>z%_process_summations.<locals>.<lambda>f   s    *Q$ r4   c                 L    t        d t        | j                        D              S )Nc              3   r   K   | ]/  \  }}|d kD  s|d   j                    xs |d   j                     1 yw)r         N)r/   ).0ias      r2   	<genexpr>z8_process_summations.<locals>.<lambda>.<locals>.<genexpr>g   s;     jtq!dehidi1Q4>>)B1Q4>>/ABjs   7'7)any	enumerateargsr9   s    r2   r:   z%_process_summations.<locals>.<lambda>g   s    #jyYZY_Y_O`jj r4   )
propertiesr=   r>   )listr
   findrE   rD   r   subs)
	sum_boundrE   r3   exprr5   r0   	sums_argsr@   rA   ss
             r2   _process_summationsrN   C   s    . :D7D 	S$j 	A
 $))A, L	i( 	0DAq1u !!i!i&@adI. 0	!	0 OyyA DGKr4   c                      g }t        |j                  dd            }| D ]T  }|\  }}}}|j                         }	|||	d<   t        |      st	        |g| }|j                  t        |dd i |	       V |S )zKLoop over the provided arguments and create the necessary line series.
    rJ   i  Nrendering_kw)intgetcopycallablerN   appendr   )
rE   kwargsseriesrJ   argrK   rlabelrP   kws
             r2   _build_line_seriesr]   v   s     FFJJ{D12I >'*$a[[]#!-B~~%i6#6C+S"X<<=> Mr4   c                     g }|D ]9  }|j                         }|d   |d   |d<   |j                   | |dd i |       ; |S )zoExtract the rendering_kw dictionary from the provided arguments and
    create an appropriate data series.
    rQ   NrP   )rT   rV   )series_type	plot_exprrW   rX   rE   r\   s         r2   _create_seriesra      s^     F 5[[]8!%bB~k49334	5
 Mr4   c                 d   t        |t        t        f      s|g}t        |      dkD  rt        |      dk(  rt        |       dkD  r|t        |       z  }t        |       t        |      k7  r$t	        dt        |        dt        |       d      t        | |      D ]  \  }}||_         |rt        |t              r|g}t        |      dk(  r|t        |       z  }n;t        |       t        |      k7  r$t	        dt        |        dt        |       d      t        | |      D ]  \  }}||_         yy)zJApply the `label` and `rendering_kw` keyword arguments to the series.
    r   r=   zXThe number of labels must be equal to the number of expressions being plotted.
Received z expressions and z labelszhThe number of rendering dictionaries must be equal to the number of expressions being plotted.
Received N)	r8   rG   tuplelen
ValueErrorzipr[   dictrP   )rX   labelsrP   rM   lrZ   s         r2   _set_labelsrj      sI    ftUm,
6{Qv;!Fa c&k!Fv;#f+% Bv;-0VWF G G ' 	DAqAG	 lD)(>L|!CK'L[C-- Ov;-0VWF G G - 	DAqAN	 r4   c                  ,   |j                  dd      }t        |t              r>|dk(  r+t        ddt        f      }|rt        | i |S t        | i |S t        |   | i |S t        |      t        k(  rt        |t              r || i |S t        d      )Nbackenddefaultr&   z1.1.0)min_module_versioncatchz:backend must be either a string or a subclass of ``Plot``.)popr8   strr   RuntimeErrorr   r   plot_backendstype
issubclassr   	TypeError)rE   rW   rl   r&   s       r2   plot_factoryrw      s    jjI.G'3i&|#*</CJ($9&99///W%t6v66
w-4
Z%>'''TUUr4   )r&   textT)showc                    t        |      }t        |ddfi |}|j                  dd      }t               }|D ]:  }t	        |d   d   t
              s||d   d   hz  }&|t        |d   d         hz  }< |r|j                  |j                               }|r|j                         n
t        d      }|j                  d|       |j                  d t        d      |             |j                  d	g       }|j                  d
d      }	t        |i |}
t        |
||	       t        |
i |}| r|j                          |S )a  Plots a function of a single variable as a curve.

    Parameters
    ==========

    args :
        The first argument is the expression representing the function
        of single variable to be plotted.

        The last argument is a 3-tuple denoting the range of the free
        variable. e.g. ``(x, 0, 5)``

        Typical usage examples are in the following:

        - Plotting a single expression with a single range.
            ``plot(expr, range, **kwargs)``
        - Plotting a single expression with the default range (-10, 10).
            ``plot(expr, **kwargs)``
        - Plotting multiple expressions with a single range.
            ``plot(expr1, expr2, ..., range, **kwargs)``
        - Plotting multiple expressions with multiple ranges.
            ``plot((expr1, range1), (expr2, range2), ..., **kwargs)``

        It is best practice to specify range explicitly because default
        range may change in the future if a more advanced default range
        detection algorithm is implemented.

    show : bool, optional
        The default value is set to ``True``. Set show to ``False`` and
        the function will not display the plot. The returned instance of
        the ``Plot`` class can then be used to save or display the plot
        by calling the ``save()`` and ``show()`` methods respectively.

    line_color : string, or float, or function, optional
        Specifies the color for the plot.
        See ``Plot`` to see how to set color for the plots.
        Note that by setting ``line_color``, it would be applied simultaneously
        to all the series.

    title : str, optional
        Title of the plot. It is set to the latex representation of
        the expression, if the plot has only one expression.

    label : str, optional
        The label of the expression in the plot. It will be used when
        called with ``legend``. Default is the name of the expression.
        e.g. ``sin(x)``

    xlabel : str or expression, optional
        Label for the x-axis.

    ylabel : str or expression, optional
        Label for the y-axis.

    xscale : 'linear' or 'log', optional
        Sets the scaling of the x-axis.

    yscale : 'linear' or 'log', optional
        Sets the scaling of the y-axis.

    axis_center : (float, float), optional
        Tuple of two floats denoting the coordinates of the center or
        {'center', 'auto'}

    xlim : (float, float), optional
        Denotes the x-axis limits, ``(min, max)```.

    ylim : (float, float), optional
        Denotes the y-axis limits, ``(min, max)```.

    annotations : list, optional
        A list of dictionaries specifying the type of annotation
        required. The keys in the dictionary should be equivalent
        to the arguments of the :external:mod:`matplotlib`'s
        :external:meth:`~matplotlib.axes.Axes.annotate` method.

    markers : list, optional
        A list of dictionaries specifying the type the markers required.
        The keys in the dictionary should be equivalent to the arguments
        of the :external:mod:`matplotlib`'s :external:func:`~matplotlib.pyplot.plot()` function
        along with the marker related keyworded arguments.

    rectangles : list, optional
        A list of dictionaries specifying the dimensions of the
        rectangles to be plotted. The keys in the dictionary should be
        equivalent to the arguments of the :external:mod:`matplotlib`'s
        :external:class:`~matplotlib.patches.Rectangle` class.

    fill : dict, optional
        A dictionary specifying the type of color filling required in
        the plot. The keys in the dictionary should be equivalent to the
        arguments of the :external:mod:`matplotlib`'s
        :external:meth:`~matplotlib.axes.Axes.fill_between` method.

    adaptive : bool, optional
        The default value is set to ``True``. Set adaptive to ``False``
        and specify ``n`` if uniform sampling is required.

        The plotting uses an adaptive algorithm which samples
        recursively to accurately plot. The adaptive algorithm uses a
        random point near the midpoint of two points that has to be
        further sampled. Hence the same plots can appear slightly
        different.

    depth : int, optional
        Recursion depth of the adaptive algorithm. A depth of value
        `n` samples a maximum of `2^{n}` points.

        If the ``adaptive`` flag is set to ``False``, this will be
        ignored.

    n : int, optional
        Used when the ``adaptive`` is set to ``False``. The function
        is uniformly sampled at ``n`` number of points. If the ``adaptive``
        flag is set to ``True``, this will be ignored.
        This keyword argument replaces ``nb_of_points``, which should be
        considered deprecated.

    size : (float, float), optional
        A tuple in the form (width, height) in inches to specify the size of
        the overall figure. The default value is set to ``None``, meaning
        the size will be set by the default backend.

    Examples
    ========

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

       >>> from sympy import symbols
       >>> from sympy.plotting import plot
       >>> x = symbols('x')

    Single Plot

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

       >>> plot(x**2, (x, -5, 5))
       Plot object containing:
       [0]: cartesian line: x**2 for x over (-5.0, 5.0)

    Multiple plots with single range.

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

       >>> plot(x, x**2, x**3, (x, -5, 5))
       Plot object containing:
       [0]: cartesian line: x for x over (-5.0, 5.0)
       [1]: cartesian line: x**2 for x over (-5.0, 5.0)
       [2]: cartesian line: x**3 for x over (-5.0, 5.0)

    Multiple plots with different ranges.

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

       >>> plot((x**2, (x, -6, 6)), (x, (x, -5, 5)))
       Plot object containing:
       [0]: cartesian line: x**2 for x over (-6.0, 6.0)
       [1]: cartesian line: x for x over (-5.0, 5.0)

    No adaptive sampling.

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

       >>> plot(x**2, adaptive=False, n=400)
       Plot object containing:
       [0]: cartesian line: x**2 for x over (-10.0, 10.0)

    See Also
    ========

    Plot, LineOver1DRangeSeries

    r=   paramsNr   xxlabelylabelfr[   rP   )r   r   rS   setr8   rq   r	   
differencekeysrp   
setdefaultr   r]   rj   rw   ry   )ry   rE   rW   r`   r{   freepr|   rh   rP   rX   plotss               r2   r+   r+      s9   z D q!6v6IZZ$'F5D &!A$q'3'QqT!WIDVAaDG_%%D	&
 v{{}-
sA
h"
ha 01ZZ$F::nd3L5f5F-&+F+E

Lr4   c                     t        |      }t        |ddfi |}|j                  dg       }|j                  dd      }t        t        |fi |}t        |||       t        |i |}| r|j                          |S )a  
    Plots a 2D parametric curve.

    Parameters
    ==========

    args
        Common specifications are:

        - Plotting a single parametric curve with a range
            ``plot_parametric((expr_x, expr_y), range)``
        - Plotting multiple parametric curves with the same range
            ``plot_parametric((expr_x, expr_y), ..., range)``
        - Plotting multiple parametric curves with different ranges
            ``plot_parametric((expr_x, expr_y, range), ...)``

        ``expr_x`` is the expression representing $x$ component of the
        parametric function.

        ``expr_y`` is the expression representing $y$ component of the
        parametric function.

        ``range`` is a 3-tuple denoting the parameter symbol, start and
        stop. For example, ``(u, 0, 5)``.

        If the range is not specified, then a default range of (-10, 10)
        is used.

        However, if the arguments are specified as
        ``(expr_x, expr_y, range), ...``, you must specify the ranges
        for each expressions manually.

        Default range may change in the future if a more advanced
        algorithm is implemented.

    adaptive : bool, optional
        Specifies whether to use the adaptive sampling or not.

        The default value is set to ``True``. Set adaptive to ``False``
        and specify ``n`` if uniform sampling is required.

    depth :  int, optional
        The recursion depth of the adaptive algorithm. A depth of
        value $n$ samples a maximum of $2^n$ points.

    n : int, optional
        Used when the ``adaptive`` flag is set to ``False``. Specifies the
        number of the points used for the uniform sampling.
        This keyword argument replaces ``nb_of_points``, which should be
        considered deprecated.

    line_color : string, or float, or function, optional
        Specifies the color for the plot.
        See ``Plot`` to see how to set color for the plots.
        Note that by setting ``line_color``, it would be applied simultaneously
        to all the series.

    label : str, optional
        The label of the expression in the plot. It will be used when
        called with ``legend``. Default is the name of the expression.
        e.g. ``sin(x)``

    xlabel : str, optional
        Label for the x-axis.

    ylabel : str, optional
        Label for the y-axis.

    xscale : 'linear' or 'log', optional
        Sets the scaling of the x-axis.

    yscale : 'linear' or 'log', optional
        Sets the scaling of the y-axis.

    axis_center : (float, float), optional
        Tuple of two floats denoting the coordinates of the center or
        {'center', 'auto'}

    xlim : (float, float), optional
        Denotes the x-axis limits, ``(min, max)```.

    ylim : (float, float), optional
        Denotes the y-axis limits, ``(min, max)```.

    size : (float, float), optional
        A tuple in the form (width, height) in inches to specify the size of
        the overall figure. The default value is set to ``None``, meaning
        the size will be set by the default backend.

    Examples
    ========

    .. plot::
       :context: reset
       :format: doctest
       :include-source: True

       >>> from sympy import plot_parametric, symbols, cos, sin
       >>> u = symbols('u')

    A parametric plot with a single expression:

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

       >>> plot_parametric((cos(u), sin(u)), (u, -5, 5))
       Plot object containing:
       [0]: parametric cartesian line: (cos(u), sin(u)) for u over (-5.0, 5.0)

    A parametric plot with multiple expressions with the same range:

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

       >>> plot_parametric((cos(u), sin(u)), (u, cos(u)), (u, -10, 10))
       Plot object containing:
       [0]: parametric cartesian line: (cos(u), sin(u)) for u over (-10.0, 10.0)
       [1]: parametric cartesian line: (u, cos(u)) for u over (-10.0, 10.0)

    A parametric plot with multiple expressions with different ranges
    for each curve:

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

       >>> plot_parametric((cos(u), sin(u), (u, -5, 5)),
       ...     (cos(u), u, (u, -5, 5)))
       Plot object containing:
       [0]: parametric cartesian line: (cos(u), sin(u)) for u over (-5.0, 5.0)
       [1]: parametric cartesian line: (cos(u), u) for u over (-5.0, 5.0)

    Notes
    =====

    The plotting uses an adaptive algorithm which samples recursively to
    accurately plot the curve. The adaptive algorithm uses a random point
    near the midpoint of two points that has to be further sampled.
    Hence, repeating the same plot command can give slightly different
    results because of the random sampling.

    If there are multiple plots, then the same optional arguments are
    applied to all the plots drawn in the same canvas. If you want to
    set these options separately, you can index the returned ``Plot``
    object and set it.

    For example, when you specify ``line_color`` once, it would be
    applied simultaneously to both series.

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

        >>> from sympy import pi
        >>> expr1 = (u, cos(2*pi*u)/2 + 1/2)
        >>> expr2 = (u, sin(2*pi*u)/2 + 1/2)
        >>> p = plot_parametric(expr1, expr2, (u, 0, 1), line_color='blue')

    If you want to specify the line color for the specific series, you
    should index each item and apply the property manually.

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

        >>> p[0].line_color = 'red'
        >>> p.show()

    See Also
    ========

    Plot, Parametric2DLineSeries
    r>   r=   r[   rP   N)r   r   rp   ra   r   rj   rw   ry   ry   rE   rW   r`   rh   rP   rX   r   s           r2   r*   r*     s    j D q!6v6IZZ$F::nd3L2IHHF-&+F+E

Lr4   c                 b   t        |      }t        |ddfi |}|j                  dd       |j                  dd       |j                  dd       |j                  d	g       }|j                  d
d      }t	        t
        |fi |}t        |||       t        |i |}| r|j                          |S )aB  
    Plots a 3D parametric line plot.

    Usage
    =====

    Single plot:

    ``plot3d_parametric_line(expr_x, expr_y, expr_z, range, **kwargs)``

    If the range is not specified, then a default range of (-10, 10) is used.

    Multiple plots.

    ``plot3d_parametric_line((expr_x, expr_y, expr_z, range), ..., **kwargs)``

    Ranges have to be specified for every expression.

    Default range may change in the future if a more advanced default range
    detection algorithm is implemented.

    Arguments
    =========

    expr_x : Expression representing the function along x.

    expr_y : Expression representing the function along y.

    expr_z : Expression representing the function along z.

    range : (:class:`~.Symbol`, float, float)
        A 3-tuple denoting the range of the parameter variable, e.g., (u, 0, 5).

    Keyword Arguments
    =================

    Arguments for ``Parametric3DLineSeries`` class.

    n : int
        The range is uniformly sampled at ``n`` number of points.
        This keyword argument replaces ``nb_of_points``, which should be
        considered deprecated.

    Aesthetics:

    line_color : string, or float, or function, optional
        Specifies the color for the plot.
        See ``Plot`` to see how to set color for the plots.
        Note that by setting ``line_color``, it would be applied simultaneously
        to all the series.

    label : str
        The label to the plot. It will be used when called with ``legend=True``
        to denote the function with the given label in the plot.

    If there are multiple plots, then the same series arguments are applied to
    all the plots. If you want to set these options separately, you can index
    the returned ``Plot`` object and set it.

    Arguments for ``Plot`` class.

    title : str
        Title of the plot.

    size : (float, float), optional
        A tuple in the form (width, height) in inches to specify the size of
        the overall figure. The default value is set to ``None``, meaning
        the size will be set by the default backend.

    Examples
    ========

    .. plot::
       :context: reset
       :format: doctest
       :include-source: True

       >>> from sympy import symbols, cos, sin
       >>> from sympy.plotting import plot3d_parametric_line
       >>> u = symbols('u')

    Single plot.

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

       >>> plot3d_parametric_line(cos(u), sin(u), u, (u, -5, 5))
       Plot object containing:
       [0]: 3D parametric cartesian line: (cos(u), sin(u), u) for u over (-5.0, 5.0)


    Multiple plots.

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

       >>> plot3d_parametric_line((cos(u), sin(u), u, (u, -5, 5)),
       ...     (sin(u), u**2, u, (u, -5, 5)))
       Plot object containing:
       [0]: 3D parametric cartesian line: (cos(u), sin(u), u) for u over (-5.0, 5.0)
       [1]: 3D parametric cartesian line: (sin(u), u**2, u) for u over (-5.0, 5.0)


    See Also
    ========

    Plot, Parametric3DLineSeries

       r=   r}   r|   r~   yzlabelzr[   rP   N)	r   r   r   rp   ra   r   rj   rw   ry   r   s           r2   r(   r(   j  s    d D q!6v6I
h$
h$
h$ZZ$F::nd3L2IHHF-&+F+E

Lr4   c                    ddl m} t        |      }t        |ddfi |}t	               }t	               }t
        |t        t        f}|D ]b  }|t        |d   d   |      r	|d   d   hnt        |d   d         hz  }|t        |d   d   |      r	|d   d   hnt        |d   d         hz  }d |r|j                         n
t        d      }	|r|j                         n
t        d      }
|j                  d|	       |j                  d|
       |j                  d	 t        d
      |	|
             |j                  dd      r&t        |d         rd|d<   t        |d         rd|d<   |j                  dg       }|j                  dd      }t        | |fi |}t        |||       t!        |i |}|j                  dd      r|j#                          |S )zZplot3d and plot_contour are structurally identical. Let's reduce
    code repetition.
    r   )
BaseScalarr=   r>   r|   r   r}   r~   r   r   is_polarF r[   rP   Nry   T)sympy.vectorr   r   r   r   r	   r   r   r8   rp   r   r   rS   rU   ra   rj   rw   ry   )SeriesrE   rW   r   r`   free_xfree_y_typesr   r|   r   rh   rP   rX   r   s                  r2   _plot3d_plot_contour_helperr     s    (D q!6v6IUFUFj'<8F Rz!A$q'6:1Q47)!Q@QQz!A$q'6:1Q47)!Q@QQR 

F3KA

F3KA
h"
h"
ha 34 zz*e$F8$%!F8F8$%!F8ZZ$F::nd3LFI88F-&+F+Ezz&$

Lr4   c                 L    |j                  d|        t        t        g|i |S )a  
    Plots a 3D surface plot.

    Usage
    =====

    Single plot

    ``plot3d(expr, range_x, range_y, **kwargs)``

    If the ranges are not specified, then a default range of (-10, 10) is used.

    Multiple plot with the same range.

    ``plot3d(expr1, expr2, range_x, range_y, **kwargs)``

    If the ranges are not specified, then a default range of (-10, 10) is used.

    Multiple plots with different ranges.

    ``plot3d((expr1, range_x, range_y), (expr2, range_x, range_y), ..., **kwargs)``

    Ranges have to be specified for every expression.

    Default range may change in the future if a more advanced default range
    detection algorithm is implemented.

    Arguments
    =========

    expr : Expression representing the function along x.

    range_x : (:class:`~.Symbol`, float, float)
        A 3-tuple denoting the range of the x variable, e.g. (x, 0, 5).

    range_y : (:class:`~.Symbol`, float, float)
        A 3-tuple denoting the range of the y variable, e.g. (y, 0, 5).

    Keyword Arguments
    =================

    Arguments for ``SurfaceOver2DRangeSeries`` class:

    n1 : int
        The x range is sampled uniformly at ``n1`` of points.
        This keyword argument replaces ``nb_of_points_x``, which should be
        considered deprecated.

    n2 : int
        The y range is sampled uniformly at ``n2`` of points.
        This keyword argument replaces ``nb_of_points_y``, which should be
        considered deprecated.

    Aesthetics:

    surface_color : Function which returns a float
        Specifies the color for the surface of the plot.
        See :class:`~.Plot` for more details.

    If there are multiple plots, then the same series arguments are applied to
    all the plots. If you want to set these options separately, you can index
    the returned ``Plot`` object and set it.

    Arguments for ``Plot`` class:

    title : str
        Title of the plot.

    size : (float, float), optional
        A tuple in the form (width, height) in inches to specify the size of the
        overall figure. The default value is set to ``None``, meaning the size will
        be set by the default backend.

    Examples
    ========

    .. plot::
       :context: reset
       :format: doctest
       :include-source: True

       >>> from sympy import symbols
       >>> from sympy.plotting import plot3d
       >>> x, y = symbols('x y')

    Single plot

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

       >>> plot3d(x*y, (x, -5, 5), (y, -5, 5))
       Plot object containing:
       [0]: cartesian surface: x*y for x over (-5.0, 5.0) and y over (-5.0, 5.0)


    Multiple plots with same range

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

       >>> plot3d(x*y, -x*y, (x, -5, 5), (y, -5, 5))
       Plot object containing:
       [0]: cartesian surface: x*y for x over (-5.0, 5.0) and y over (-5.0, 5.0)
       [1]: cartesian surface: -x*y for x over (-5.0, 5.0) and y over (-5.0, 5.0)


    Multiple plots with different ranges.

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

       >>> plot3d((x**2 + y**2, (x, -5, 5), (y, -5, 5)),
       ...     (x*y, (x, -3, 3), (y, -3, 3)))
       Plot object containing:
       [0]: cartesian surface: x**2 + y**2 for x over (-5.0, 5.0) and y over (-5.0, 5.0)
       [1]: cartesian surface: x*y for x over (-3.0, 3.0) and y over (-3.0, 3.0)


    See Also
    ========

    Plot, SurfaceOver2DRangeSeries

    ry   )r   r   r   ry   rE   rW   s      r2   r'   r'     s5    F fd#& 3#'3+13 3r4   c                 b   t        |      }t        |ddfi |}|j                  dd       |j                  dd       |j                  dd       |j                  d	g       }|j                  d
d      }t	        t
        |fi |}t        |||       t        |i |}| r|j                          |S )a@  
    Plots a 3D parametric surface plot.

    Explanation
    ===========

    Single plot.

    ``plot3d_parametric_surface(expr_x, expr_y, expr_z, range_u, range_v, **kwargs)``

    If the ranges is not specified, then a default range of (-10, 10) is used.

    Multiple plots.

    ``plot3d_parametric_surface((expr_x, expr_y, expr_z, range_u, range_v), ..., **kwargs)``

    Ranges have to be specified for every expression.

    Default range may change in the future if a more advanced default range
    detection algorithm is implemented.

    Arguments
    =========

    expr_x : Expression representing the function along ``x``.

    expr_y : Expression representing the function along ``y``.

    expr_z : Expression representing the function along ``z``.

    range_u : (:class:`~.Symbol`, float, float)
        A 3-tuple denoting the range of the u variable, e.g. (u, 0, 5).

    range_v : (:class:`~.Symbol`, float, float)
        A 3-tuple denoting the range of the v variable, e.g. (v, 0, 5).

    Keyword Arguments
    =================

    Arguments for ``ParametricSurfaceSeries`` class:

    n1 : int
        The ``u`` range is sampled uniformly at ``n1`` of points.
        This keyword argument replaces ``nb_of_points_u``, which should be
        considered deprecated.

    n2 : int
        The ``v`` range is sampled uniformly at ``n2`` of points.
        This keyword argument replaces ``nb_of_points_v``, which should be
        considered deprecated.

    Aesthetics:

    surface_color : Function which returns a float
        Specifies the color for the surface of the plot. See
        :class:`~Plot` for more details.

    If there are multiple plots, then the same series arguments are applied for
    all the plots. If you want to set these options separately, you can index
    the returned ``Plot`` object and set it.


    Arguments for ``Plot`` class:

    title : str
        Title of the plot.

    size : (float, float), optional
        A tuple in the form (width, height) in inches to specify the size of the
        overall figure. The default value is set to ``None``, meaning the size will
        be set by the default backend.

    Examples
    ========

    .. plot::
       :context: reset
       :format: doctest
       :include-source: True

       >>> from sympy import symbols, cos, sin
       >>> from sympy.plotting import plot3d_parametric_surface
       >>> u, v = symbols('u v')

    Single plot.

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

       >>> plot3d_parametric_surface(cos(u + v), sin(u - v), u - v,
       ...     (u, -5, 5), (v, -5, 5))
       Plot object containing:
       [0]: parametric cartesian surface: (cos(u + v), sin(u - v), u - v) for u over (-5.0, 5.0) and v over (-5.0, 5.0)


    See Also
    ========

    Plot, ParametricSurfaceSeries

    r   r>   r}   r|   r~   r   r   r   r[   rP   N)	r   r   r   rp   ra   r   rj   rw   ry   r   s           r2   r)   r)     s    R D q!6v6I
h$
h$
h$ZZ$F::nd3L3YI&IF-&+F+E

Lr4   c                 L    |j                  d|        t        t        g|i |S )a  
    Draws contour plot of a function

    Usage
    =====

    Single plot

    ``plot_contour(expr, range_x, range_y, **kwargs)``

    If the ranges are not specified, then a default range of (-10, 10) is used.

    Multiple plot with the same range.

    ``plot_contour(expr1, expr2, range_x, range_y, **kwargs)``

    If the ranges are not specified, then a default range of (-10, 10) is used.

    Multiple plots with different ranges.

    ``plot_contour((expr1, range_x, range_y), (expr2, range_x, range_y), ..., **kwargs)``

    Ranges have to be specified for every expression.

    Default range may change in the future if a more advanced default range
    detection algorithm is implemented.

    Arguments
    =========

    expr : Expression representing the function along x.

    range_x : (:class:`Symbol`, float, float)
        A 3-tuple denoting the range of the x variable, e.g. (x, 0, 5).

    range_y : (:class:`Symbol`, float, float)
        A 3-tuple denoting the range of the y variable, e.g. (y, 0, 5).

    Keyword Arguments
    =================

    Arguments for ``ContourSeries`` class:

    n1 : int
        The x range is sampled uniformly at ``n1`` of points.
        This keyword argument replaces ``nb_of_points_x``, which should be
        considered deprecated.

    n2 : int
        The y range is sampled uniformly at ``n2`` of points.
        This keyword argument replaces ``nb_of_points_y``, which should be
        considered deprecated.

    Aesthetics:

    surface_color : Function which returns a float
        Specifies the color for the surface of the plot. See
        :class:`sympy.plotting.Plot` for more details.

    If there are multiple plots, then the same series arguments are applied to
    all the plots. If you want to set these options separately, you can index
    the returned ``Plot`` object and set it.

    Arguments for ``Plot`` class:

    title : str
        Title of the plot.

    size : (float, float), optional
        A tuple in the form (width, height) in inches to specify the size of
        the overall figure. The default value is set to ``None``, meaning
        the size will be set by the default backend.

    See Also
    ========

    Plot, ContourSeries

    ry   )r   r   r   r   s      r2   plot_contourr     s*    ` fd#&}FtFvFFr4   c           
      H   | sg S |dkD  rOt        | d   t              r;t        |       |k  rt        d      t	        t        |             D ]  }t        | |   t
              s n t        |       dz   }t        | d|  }t         t               j                  |D cg c]  }|j                   c}       }t        |       ||z   k(  r|t        | |d  z   g}|S t        dd      }g }	|D ]  }
|	j                  t        |
      |z          ! t	        t        |      |z
        D ]'  }|	j                  t        t                     |z          ) |t        |	 z   g}|S t        | d   t              s,t        | d   t
              rt        | d         |k(  r|dk7  rt	        t        |             D ]M  }t        | |   t
              rt        | |         |k7  r n5t        | |   t
              r=t        | |         | |<   O t        |       dz   }| d| }t        d |D              sJ t         t               j                  |D cg c]  }|D ]  }|j                    c}}       }t        |      |kD  rt        d	|z        t        |       ||z   k(  r>t        | |   t
              r+t        t        | |||z           }	|D cg c]  }||	z   	 }}|S t        dd      }g }	|D ]  }
|	j                  t        |
      |z          ! t	        |t        |      z
        D ]'  }|	j                  t        t                     |z          ) t        |	 }	|D cg c]  }||	z   	 }}|S t        | d   t
              rt        | d         ||z   k(  r| D ]  }t	        |      D ]/  }t        ||   t              rt        d
t        ||         z         t	        |      D ]3  }t        |||z            dk(  rt        dt        |||z            z          | S yyc c}w c c}}w c c}w c c}w )a  
    Checks the arguments and converts into tuples of the
    form (exprs, ranges).

    Examples
    ========

    .. plot::
       :context: reset
       :format: doctest
       :include-source: True

       >>> from sympy import cos, sin, symbols
       >>> from sympy.plotting.plot import check_arguments
       >>> x = symbols('x')
       >>> check_arguments([cos(x), sin(x)], 2, 1)
           [(cos(x), sin(x), (x, -10, 10))]

       >>> check_arguments([x, x**2], 1, 1)
           [(x, (x, -10, 10)), (x**2, (x, -10, 10))]
    r=   r   z*len(args) should not be less than expr_lenNi
   r   c              3   J   K   | ]  }|D ]  }t        |t                 y wr7   )r8   r   )r?   rK   es      r2   rB   z"check_arguments.<locals>.<genexpr>  s$     G4$GQ:a&G&Gs   !#z?The number of free_symbols in the expression is greater than %dz Expected an expression, given %sz0The ranges should be a tuple of length 3, got %s)r8   r   rd   re   ranger   rG   r   unionfree_symbolsrV   r   allrq   )rE   expr_lennb_of_free_symbolsr@   exprsr   r   r   default_rangerangessymbolrK   rY   s                r2   check_argumentsr   k  sl   , 	!|
47D1 t9xIJJs4y! 	A$q'5)	 D	AAtBQx KCEKK%)HQ!..)HIJt9#555UDO445E  "#rNMF& =eFmm;<= 3|,/AAB >eEGn}<=>UF^+,E$q'4 ZQ%?%(a\X%=%-] s4y! 	A$q'5)c$q'lh.Fd1gu-Q.Q		 D	AARaG5GGGGKCEKKU *7T15*7,- +,.. *7. *7 8 9 |11 24FG H Ht9...:d1gu3MDQ!33"5 6 7F/45tTF]5E5L "#rNMF& =eFmm;<= -L0AAB >eEGn}<=>F^F/45tTF]5E5L	DGU	#DGCU8U(U 	RC8_ 2!#a&$/$%G%(Q[&1 2 22 -. R3q8|,-2$ &8:=c!h,>O:P&Q R RR	R  )V	#o *I>*7 6 6s   PP PPN)B__doc__sympy.concrete.summationsr   sympy.core.containersr   sympy.core.exprr   sympy.core.functionr   r   sympy.core.symbolr   r	   r
   sympy.externalr   sympy.functionsr   $sympy.plotting.backends.base_backendr   )sympy.plotting.backends.matplotlibbackendr   #sympy.plotting.backends.textbackendr   sympy.plotting.seriesr   r   r   r   r   r   sympy.plotting.utilsr   r   sympy.tensor.indexedr   sympy.plotting.plotgridr   r   r   r   r   r   r   r    r!   r"   r#   r$   sympy.plotting.textplotr%   __doctest_requires__rN   r]   ra   rj   rw   rs   r+   r*   r(   r   r'   r)   r   r    r4   r2   <module>r      s   0 * '   6 3 3 (   5 G ;F F A ( , , 2 2 3 . 3 2 5 & ; F , ' ~ 0f"
@V" $  Tn !% @F (, @F&R  E3P +/ wr " QGhgr4   