statsmodels.graphics.factorplots.interaction_plot
-
statsmodels.graphics.factorplots.interaction_plot(x, trace, response, func=, ax=None, plottype='b', xlabel=None, ylabel=None, colors=[], markers=[], linestyles=[], legendloc='best', legendtitle=None, **kwargs)[source] -
Interaction plot for factor level statistics.
Note. If categorial factors are supplied levels will be internally recoded to integers. This ensures matplotlib compatiblity.
uses pandas.DataFrame to calculate an
aggregatestatistic for each level of the factor or group given bytrace.Parameters: x : array-like
The
xfactor levels constitute the x-axis. If apandas.Seriesis given its name will be used inxlabelifxlabelis None.trace : array-like
The
tracefactor levels will be drawn as lines in the plot. Iftraceis apandas.Seriesits name will be used as thelegendtitleiflegendtitleis None.response : array-like
The reponse or dependent variable. If a
pandas.Seriesis given its name will be used inylabelifylabelis None.func : function
Anything accepted by
pandas.DataFrame.aggregate. This is applied to the response variable grouped by the trace levels.plottype : str {?line?, ?scatter?, ?both?}, optional
The type of plot to return. Can be ?l?, ?s?, or ?b?
ax : axes, optional
Matplotlib axes instance
xlabel : str, optional
Label to use for
x. Default is ?X?. Ifxis apandas.Seriesit will use the series names.ylabel : str, optional
Label to use for
response. Default is ?func of response?. Ifresponseis apandas.Seriesit will use the series names.colors : 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.
markers : list, optional
If given, must have length == number of lovels in trace
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: fig : Figure
The figure given by
ax.figureor 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()
(Source code, png, hires.png, pdf)

Please login to continue.