Ë
    £�DjÆ  ã                   óN   — d Z ddlmZ ddlZddlmZ ddlmc m	Z	 	 	 	 dd„Z
d„ Zy)z@
Authors:    Josef Perktold, Skipper Seabold, Denis A. Engemann
é    )ÚlrangeN)Úrainbowc           	      ó  — ddl m} t        j                  |«      \  }}|xs t	        |dd«      }t	        |dt        |«      «      }|› d|› �}|xs t	        | dd«      }|xs t	        |dd«      }|j                  |«       |j                  |«       d	x}}t        | d   t
        «      rUt        j                  | «      D �cg c]  }|‘Œ }}t        t        |«      «      }t        | t        t        ||«      «      «      }  |t        | ||¬
«      «      }|j!                  ddg«      j#                  |«      j%                  «       }t        |d   j                  «       «      }|
€dg|z  n|
}
|	€dg|z  n|	}	|€t'        |«      n|}t        |
«      |k7  rt)        d«      ‚t        |	«      |k7  rt)        d«      ‚t        |«      |k7  rt)        d«      ‚|dk(  s|dk(  rit+        |j!                  d«      «      D ]K  \  }\  }}t        |d   j,                  d   «      } |j.                  |d   |d   f||   |	|   ||
|   dœ|¤Ž ŒM nì|dk(  s|dk(  ret+        |j!                  d«      «      D ]G  \  }\  }}t        |d   j,                  d   «      } |j.                  |d   |d   f||   ||
|   dœ|¤Ž ŒI n}|dk(  s|dk(  ret+        |j!                  d«      «      D ]G  \  }\  }}t        |d   j,                  d   «      } |j0                  |d   |d   f||   ||	|   dœ|¤Ž ŒI nt)        d|z  «      ‚|j3                  ||¬«       |j5                  d«       t7        ||g«      r"|j9                  |«       |j;                  |«       |S c c}w )a  
    Interaction plot for factor level statistics.

    Note. If categorial factors are supplied levels will be internally
    recoded to integers. This ensures matplotlib compatibility. Uses
    a DataFrame to calculate an `aggregate` statistic for each level of the
    factor or group given by `trace`.

    Parameters
    ----------
    x : array_like
        The `x` factor levels constitute the x-axis. If a `pandas.Series` is
        given its name will be used in `xlabel` if `xlabel` is None.
    trace : array_like
        The `trace` factor levels will be drawn as lines in the plot.
        If `trace` is a `pandas.Series` its name will be used as the
        `legendtitle` if `legendtitle` is None.
    response : array_like
        The reponse or dependent variable. If a `pandas.Series` is given
        its name will be used in `ylabel` if `ylabel` is None.
    func : function
        Anything accepted by `pandas.DataFrame.aggregate`. This is applied to
        the response variable grouped by the trace levels.
    ax : axes, optional
        Matplotlib axes instance
    plottype : str {'line', 'scatter', 'both'}, optional
        The type of plot to return. Can be 'l', 's', or 'b'
    xlabel : str, optional
        Label to use for `x`. Default is 'X'. If `x` is a `pandas.Series` it
        will use the series names.
    ylabel : str, optional
        Label to use for `response`. Default is 'func of response'. If
        `response` is a `pandas.Series` it will use the series names.
    colors : list, optional
        If given, must have length == number of levels in trace.
    markers : list, optional
        If given, must have length == number of levels in trace
    linestyles : list, optional
        If given, must have length == number of levels in trace.
    legendloc : {None, str, int}
        Location passed to the legend command.
    legendtitle : {None, str}
        Title of the legend.
    **kwargs
        These will be passed to the plot command used either plot or scatter.
        If you want to control the overall plotting options, use kwargs.

    Returns
    -------
    Figure
        The figure given by `ax.figure` or a new instance.

    Examples
    --------
    >>> import numpy as np
    >>> np.random.seed(12345)
    >>> weight = np.random.randint(1,4,size=60)
    >>> duration = np.random.randint(1,3,size=60)
    >>> days = np.log(np.random.randint(1,30, size=60))
    >>> fig = interaction_plot(weight, duration, days,
    ...             colors=['red','blue'], markers=['D','^'], ms=10)
    >>> import matplotlib.pyplot as plt
    >>> plt.show()

    .. plot::

       import numpy as np
       from statsmodels.graphics.factorplots import interaction_plot
       np.random.seed(12345)
       weight = np.random.randint(1,4,size=60)
       duration = np.random.randint(1,3,size=60)
       days = np.log(np.random.randint(1,30, size=60))
       fig = interaction_plot(weight, duration, days,
                   colors=['red','blue'], markers=['D','^'], ms=10)
       import matplotlib.pyplot as plt
       #plt.show()
    r   )Ú	DataFrameÚnameÚresponseÚ__name__z of ÚXÚTraceN)ÚxÚtracer   r   r   ú-ú.z(Must be a linestyle for each trace levelz%Must be a marker for each trace levelz$Must be a color for each trace levelÚbothÚb)ÚcolorÚmarkerÚlabelÚ	linestyleÚlineÚl)r   r   r   ÚscatterÚs)r   r   r   zPlot type %s not understood)ÚlocÚtitlegš™™™™™¹?)Úpandasr   ÚutilsÚcreate_mpl_axÚgetattrÚstrÚ
set_ylabelÚ
set_xlabelÚ
isinstanceÚnpÚuniquer   ÚlenÚ_recodeÚdictÚzipÚgroupbyÚ	aggregateÚreset_indexr   Ú
ValueErrorÚ	enumerateÚvaluesÚplotr   ÚlegendÚmarginsÚallÚ
set_xticksÚset_xticklabels)r   r   r   ÚfuncÚaxÚplottypeÚxlabelÚylabelÚcolorsÚmarkersÚ
linestylesÚ	legendlocÚlegendtitleÚkwargsr   ÚfigÚresponse_nameÚ	func_nameÚx_valuesÚx_levelsr   ÚdataÚ	plot_dataÚn_traceÚir/   Úgroupr   s                               údC:\Crop_Prediction\Backend\crop-ai-system\venv\Lib\site-packages\statsmodels/graphics/factorplots.pyÚinteraction_plotrL      s¸  € õd !Ü×!Ñ! "Ó%�G€CˆàÒCœg h°¸
ÓC€MÜ˜˜j¬#¨d«)Ó4€IØˆ{˜$˜}˜oÐ.€FØÒ.”w˜q &¨#Ó.€FØÒ@¤¨°¸Ó!@€Kà‡M�M�&ÔØ‡M�M�&ÔàÐ€HˆxÜ�!�A‘$œÔÜ!Ÿy™y¨›|Ö,˜!’AÐ,ˆÐ,Üœ#˜h›-Ó(ˆÜ�A”tœC ¨(Ó3Ó4Ó5ˆá”T˜A U°XÔ>Ó?€DØ—‘˜g s˜^Ó,×6Ñ6°tÓ<×HÑHÓJ€Iô �)˜GÑ$×+Ñ+Ó-Ó.€Gà$.Ð$6�#�˜’¸J€JØ!( ˆsˆe�gŠo°g€GØ!' ŒW�WÔ°V€Fä
ˆ:ƒ˜'Ò!ÜÐCÓDÐDÜ
ˆ7ƒ|�wÒÜÐ@ÓAÐAÜ
ˆ6ƒ{�gÒÜÐ?Ó@Ð@à�6Ò˜X¨š_Ü"+¨I×,=Ñ,=¸gÓ,FÓ"Gò 	7ÑˆA‰�˜ä˜˜g™×-Ñ-¨aÑ0Ó1ˆEØˆB�G‰G�E˜#‘J  jÑ 1ð 7¸À¹Ø" 1™:¨UØ(¨™mñ7à/5ó7ñ	7ð 
�VÒ	˜x¨3šÜ"+¨I×,=Ñ,=¸gÓ,FÓ"Gò 	DÑˆA‰�˜ä˜˜g™×-Ñ-¨aÑ0Ó1ˆEØˆB�G‰G�E˜#‘J  jÑ 1ð D¸À¹Ø¨:°a©=ñDØ<BóDñ	Dð
 
�YÒ	 (¨c¢/Ü"+¨I×,=Ñ,=¸gÓ,FÓ"Gò 	>ÑˆA‰�˜ä˜˜g™×-Ñ-¨aÑ0Ó1ˆEØˆB�J‰J�u˜S‘z 5¨Ñ#4ð >¸FÀ1¹IØ¨°©
ñ>Ø6<ó>ñ	>ô Ð6¸ÑAÓBÐBØ‡I�I�) ;€IÔ/Ø‡J�Jˆr„Nä
ˆH�hÐÔ Ø
�‰�hÔØ
×Ñ˜8Ô$Ø€Jùòe -s   Â?	M?c                 ó’  — ddl m} d}d}t        | |«      r$| j                  }| j                  }| j
                  } | j                  j                  t        j                  t        j                  fvrt        d«      ‚t        |t        «      st        d«      ‚t        j                  | «      t        j                  t        |j                  «       «      «      k(  j!                  «       st        d«      ‚t        j"                  | j$                  d   t&        ¬«      }|j)                  «       D ]  \  }}||| |k(  <   Œ |r ||||¬«      }|S )	a8   Recode categorial data to int factor.

    Parameters
    ----------
    x : array_like
        array like object supporting with numpy array methods of categorially
        coded data.
    levels : dict
        mapping of labels to integer-codings

    Returns
    -------
    out : instance numpy.ndarray
    r   )ÚSeriesNz<This is not a categorial factor. Array of str type required.z4This is not a valid value for levels. Dict required.z)The levels do not match the array values.)Údtype)r   Úindex)r   rN   r#   r   rP   r/   rO   Útyper$   Ústr_Úobject_r-   r(   r%   ÚlistÚkeysr3   ÚemptyÚshapeÚintÚitems)r   ÚlevelsrN   r   rP   ÚoutÚlevelÚcodings           rK   r'   r'   ¡   s  € õ Ø€DØ€Eä�!�VÔØ�v‰vˆØ—‘ˆØ�H‰Hˆà‡w�w‡|�|œBŸG™G¤R§Z¡ZÐ0Ñ0Üð 8ó 9ð 	9ô ˜¤Ô%Üð +ó ,ð 	,ô �i‰i˜‹lœbŸi™i¬¨V¯[©[«]Ó(;Ó<Ñ<×AÑAÔCÜÐDÓEÐEô �h‰h�q—w‘w˜q‘z¬Ô-ˆØ#Ÿ\™\›^ò 	%‰MˆE�6Ø$ˆC��U‘
ŠOð	%ñ Ù˜ 4¨uÔ5ˆCàˆ
ó    )
ÚmeanNr   NNNNNÚbestN)Ú__doc__Ústatsmodels.compat.pythonr   Únumpyr$   Ústatsmodels.graphics.plottoolsr   Ústatsmodels.graphics.utilsÚgraphicsr   rL   r'   © r^   rK   ú<module>rh      s4   ðñõ -ã å 2ß *Ð *ð ILØDHØDHóRój+r^   