
    wg                     F    d dl mZ d dlmc mc mZ ddgiZ G d d      Zy)    )import_moduleN)PlotGrid
matplotlibc                   \    e Zd ZdZddddZd Zed        Zed        Zd	 Z	d
 Z
d Zd Zy)r   a	  This class helps to plot subplots from already created SymPy plots
    in a single figure.

    Examples
    ========

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

        >>> from sympy import symbols
        >>> from sympy.plotting import plot, plot3d, PlotGrid
        >>> x, y = symbols('x, y')
        >>> p1 = plot(x, x**2, x**3, (x, -5, 5))
        >>> p2 = plot((x**2, (x, -6, 6)), (x, (x, -5, 5)))
        >>> p3 = plot(x**3, (x, -5, 5))
        >>> p4 = plot3d(x*y, (x, -5, 5), (y, -5, 5))

    Plotting vertically in a single line:

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

        >>> PlotGrid(2, 1, p1, p2)
        PlotGrid object containing:
        Plot[0]: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)
        Plot[1]: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)

    Plotting horizontally in a single line:

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

        >>> PlotGrid(1, 3, p2, p3, p4)
        PlotGrid object containing:
        Plot[0]: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)
        Plot[1]:Plot object containing:
        [0]: cartesian line: x**3 for x over (-5.0, 5.0)
        Plot[2]:Plot object containing:
        [0]: cartesian surface: x*y for x over (-5.0, 5.0) and y over (-5.0, 5.0)

    Plotting in a grid form:

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

        >>> PlotGrid(2, 2, p1, p2, p3, p4)
        PlotGrid object containing:
        Plot[0]: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)
        Plot[1]: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)
        Plot[2]:Plot object containing:
        [0]: cartesian line: x**3 for x over (-5.0, 5.0)
        Plot[3]:Plot object containing:
        [0]: cartesian surface: x*y for x over (-5.0, 5.0) and y over (-5.0, 5.0)

    TN)showsizec                *   t        ddg didt        f      | _        || _        || _        g | _        d| _        || _        |D ]'  }| j
                  j                  |j
                         ) || _	        |r| j                  r| j                          yyy)a  
        Parameters
        ==========

        nrows :
            The number of rows that should be in the grid of the
            required subplot.
        ncolumns :
            The number of columns that should be in the grid
            of the required subplot.

        nrows and ncolumns together define the required grid.

        Arguments
        =========

        A list of predefined plot objects entered in a row-wise sequence
        i.e. plot objects which are to be in the top row of the required
        grid are written first, then the second row objects and so on

        Keyword arguments
        =================

        show : Boolean
            The default value is set to ``True``. Set show to ``False`` and
            the function will not display the subplot. The returned instance
            of the ``PlotGrid`` class can then be used to save or display the
            plot by calling the ``save()`` and ``show()`` methods
            respectively.
        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.
        r   fromlist)pyplotcmcollectionsz1.1.0)import_kwargsmin_module_versioncatchN)r   RuntimeErrorr   nrowsncolumns_series_figargsappendr   r   )selfr   r   r   r   r   kwargsargs           \/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/sympy/plotting/plotgrid.py__init__zPlotGrid.__init__\   s    F (%'FG&|o? 
 		 	-CLL,	-	DOOIIK $4    c                    | j                   j                  j                  | j                  | j                        }i }d}t        | j                        D ]P  }t        | j                        D ]6  }|t        | j                        k  r| j                  |   ||||f   <   |dz  }8 R | j                  si nd| j                  i} | j                   j                  j                  di || _        |j                         D ]  \  }}t        |j                        dkD  r|j                  d   j                  rddini } | j                  j                  |fi |}	| j                  |_        |	|_        |j%                           y )Nr      figsize
projection3d )r   gridspecGridSpecr   r   rangelenr   r   r   figurer   itemsr   is_3Dadd_subplot_plotgrid_fig_plotgrid_axprocess_series)
r   gsmappingcijkwspecpcur_axs
             r   _create_figurezPlotGrid._create_figure   sQ   __%%..tzz4==Itzz" 	A4==) s499~%(,		!GBq!tH%Q	 yyRy$))&<1DOO**117B7	}} 	GD!+.qyy>A+=		!""  &)+ *TYY**4626F"iiAO#AN	r   c                 R    | j                   s| j                          | j                   S N)r   r8   r   s    r   figzPlotGrid.fig   s    yy!yyr   c                     | S r:   r#   r;   s    r   _backendzPlotGrid._backend   s    r   c                 b    | j                   j                  j                  | j                         y r:   )r   r   closer<   r;   s    r   r@   zPlotGrid.close   s    $$TXX.r   c                     t         j                  r?| j                  j                          | j                  j
                  j                          y | j                          y r:   )base_backend_showr<   tight_layoutr   r   r   r@   r;   s    r   r   zPlotGrid.show   s:    HH!!#OO""'')JJLr   c                 :    | j                   j                  |       y r:   )r<   savefig)r   paths     r   savezPlotGrid.save   s    r   c                     t        | j                        D cg c]  \  }}d|z  t        |      z    }}}ddj                  |      z   S c c}}w )Nz	Plot[%d]:zPlotGrid object containing:

)	enumerater   strjoin)r   r2   plot	plot_strss       r   __str__zPlotGrid.__str__   sT    %.tyy%9;!!T "AoT2 ;	 ; /91EEE;s   A)__name__
__module____qualname____doc__r   r8   propertyr<   r>   r@   r   rH   rP   r#   r   r   r   r      sX    JV 59t /b(  
  /Fr   r   )sympy.externalr   $sympy.plotting.backends.base_backendplottingbackendsrB   __doctest_requires__r   r#   r   r   <module>r[      s-    ( ; ; L> 
lF lFr   