h. regplot

This file shows the usage of regplot() function.

# sphinx_gallery_thumbnail_number = -2

import numpy as np
from easy_mpl import regplot
import matplotlib.pyplot as plt
from easy_mpl.utils import version_info

version_info()
{'easy_mpl': '0.21.4', 'matplotlib': '3.8.0', 'numpy': '1.26.1', 'pandas': '2.1.1', 'scipy': '1.11.3'}
rng = np.random.default_rng(313)

x = rng.uniform(0, 10, size=100)
y = x + rng.normal(size=100)
_ = regplot(x, y)
reg plot

customizing marker style

_ = regplot(x, y, marker_color='white',
            scatter_kws={'marker':"D", 'edgecolors':'black'})
reg plot

another example by increasing the marker size

_ = regplot(x, y, marker_color='crimson', marker_size=35,
           scatter_kws={'marker':"o", 'edgecolors':'black'})
reg plot

customizing line style

_ = regplot(x, y, marker_color='dodgerblue', marker_size=35,
           scatter_kws={'marker':"o"},
            line_color='dimgrey', line_style='--',
            line_kws={'linewidth':3})
reg plot

customizing fill color

_ = regplot(x, y, marker_color='crimson', marker_size=40,
           scatter_kws={'marker':"o", 'edgecolors':'black'},
            fill_color='teal')
reg plot

hiding confidence interval

_ = regplot(x, y, marker_color='crimson', marker_size=40,
           scatter_kws={'marker':"o", 'edgecolors':'black'},
            ci=None, line_color='olive')
reg plot

multiple regression lines with customized marker, line and fill style

cov = np.array(
    [[1.0, 0.9, 0.7],
     [0.9, 1.2, 0.8],
     [0.7, 0.8, 1.4]]
)
data = rng.multivariate_normal(np.zeros(3),
                               cov, size=100)

ax = regplot(data[:, 0], data[:, 1], line_color='orange',
             marker_color='orange', marker_size=35, fill_color='orange',
             scatter_kws={'edgecolors':'black', 'linewidth':0.8, 'alpha': 0.8},
             show=False, label="data 1")
_ = regplot(data[:, 0], data[:, 2], line_color='royalblue', ax=ax,
                marker_color='royalblue', marker_size=35, fill_color='royalblue',
             scatter_kws={'edgecolors':'black', 'linewidth':0.8, 'alpha': 0.8},
             show=False, label="data 2", ax_kws=dict(legend_kws=dict(loc=(0.1, 0.8))))
plt.show()
reg plot

Total running time of the script: (0 minutes 2.664 seconds)

Gallery generated by Sphinx-Gallery