statsmodels.graphics.regressionplots.abline_plot¶
-
statsmodels.graphics.regressionplots.abline_plot(intercept=
None
, slope=None
, horiz=None
, vert=None
, model_results=None
, ax=None
, **kwargs)[source]¶ Plot a line given an intercept and slope.
- Parameters:¶
- intercept
float
The intercept of the line.
- slope
float
The slope of the line.
- horiz
float
or array_like Data for horizontal lines on the y-axis.
- vertarray_like
Data for verterical lines on the x-axis.
- model_results
statsmodels
results
instance
Any object that has a two-value params attribute. Assumed that it is (intercept, slope).
- ax
axes
,optional
Matplotlib axes instance.
- **kwargs
Options passed to matplotlib.pyplot.plt.
- intercept
- Returns:¶
Figure
The figure given by ax.figure or a new instance.
Examples
>>> import numpy as np >>> import statsmodels.api as sm
>>> np.random.seed(12345) >>> X = sm.add_constant(np.random.normal(0, 20, size=30)) >>> y = np.dot(X, [25, 3.5]) + np.random.normal(0, 30, size=30) >>> mod = sm.OLS(y,X).fit() >>> fig = sm.graphics.abline_plot(model_results=mod) >>> ax = fig.axes[0] >>> ax.scatter(X[:,1], y) >>> ax.margins(.1) >>> import matplotlib.pyplot as plt >>> plt.show()
(
Source code
,png
,hires.png
,pdf
)
Last update:
Nov 14, 2024