Visualization

One-line plotting functions built on matplotlib. Every function returns the matplotlib.axes.Axes object for further customization.

Scatter + fitted line — ravix.plot()

Accepts a formula + DataFrame, a fitted model, or a bare DataFrame.

ravix.plot("AAPL ~ SPY", df)

Scatter plot created with Ravix showing the fitted regression line

ravix.plot("SPY ~ AAPL + CAT + MSFT + XOM", data = df)

Ravix scatter plot with fitted line for a multiple regression model

ravix.plot(model)

Ravix scatter plot with fitted regression line generated directly from a fitted model

Residual histogram — ravix.hist()

ravix.hist(model, norm=True, bins=25)

Ravix residual histogram with a normal curve overlay

ravix.hist(df["AAPL"], bins=20)

Ravix histogram of a single dataset column

ravix.hist(df)

Ravix histogram grid for every column in the dataset

Boxplot — ravix.boxplot()

ravix.boxplot(df["AAPL"])

Ravix boxplot of a single dataset column

ravix.boxplot(df)

Ravix boxplot grid for every column in the dataset

Bar chart — ravix.barplot()

ravix.barplot(df)

Ravix bar chart of the dataset

Correlation plot — ravix.plot_cor()

ravix.plot_cor(df)

Ravix correlation heatmap

ravix.plot_cor(df, style = 2)

Ravix correlation plot, alternate style 2

ravix.plot_cor(df, style = 3)

Ravix correlation plot, alternate style 3

Add a regression line — ravix.abline()

ravix.plot("AAPL ~ SPY", df)
ravix.abline(a=0.0004, b=1.241)

Ravix scatter plot with a manually specified regression line added via ravix.abline()

ravix.plot("AAPL ~ SPY", df)
ravix.abline(model, color = "red")

Ravix scatter plot with a fitted model's regression line highlighted in red via ravix.abline()

Saving figures

import matplotlib.pyplot as plt

ax = ravix.plot("AAPL ~ SPY", df)
plt.savefig("fitted_line.png", dpi=150, bbox_inches="tight")

Ravix scatter plot with fitted line, saved to file with matplotlib's savefig()

Textbook reference: Visualization is covered in Chapter 2 of Applied Linear Regression for Business Analytics with Python.

On this page