在Python Matplotlib中绘制概要直方图

在Python Matplotlib中绘制概要直方图

在概要直方图中,每个箱包含其条目的平均值。为了在Python中绘制概要直方图,我们可以使用 Seaborn 中的 regplot 方法。

步骤

  • 设置图像大小并调整子图之间和周围的填充。

  • 使用numpy创建 xy 数据点。

  • 使用 seaborn.regplot 绘制数据和线性回归模型拟合。使用参数 x_bins 将x变量分成离散的箱。使用 fit_reg=True 来绘制 xy 变量之间的回归模型。

  • 使用 Show() 方法显示图形。

示例

import numpy as np
import seaborn as sns
from matplotlib import pyplot as plt

plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True

x = np.random.uniform(-5, 5, 1000)
y = np.random.normal(x**2, np.abs(x) + 1)

sns.regplot(x=x, y=y, x_bins=20, marker='o', fit_reg=True)

plt.show()
Python

输出

它将产生以下输出−

在Python Matplotlib中绘制概要直方图

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

登录

注册