相关矩阵图——Python实现

python 复制代码
import matplotlib.pyplot as plt
import numpy as np

# 创建一些正常分布的数据
mean = [0, 0]
cov = [[1, 1], [1, 2]]
x, y = np.random.multivariate_normal(mean, cov, 3000).T

# Set up the axes with gridspec
fig = plt.figure(figsize=(6, 6))
grid = plt.GridSpec(4, 4, hspace=0.2, wspace=0.2)
main_ax = fig.add_subplot(grid[:-1, 1:])
y_hist = fig.add_subplot(grid[:-1, 0], xticklabels=[], sharey=main_ax)
x_hist = fig.add_subplot(grid[-1, 1:], yticklabels=[], sharex=main_ax)

# scatter points on the main axes
main_ax.plot(x, y, 'ok', markersize=3, alpha=0.2)

# histogram on the attached axes
x_hist.hist(x, 40, histtype='stepfilled',
            orientation='vertical', color='gray')
x_hist.invert_yaxis()

y_hist.hist(y, 40, histtype='stepfilled',
            orientation='horizontal', color='gray')
y_hist.invert_xaxis()
python 复制代码
# Path: 子图.ipynb
mean = [0, 0]
cov = [[1, 1], [1, 2]]
x, y = np.random.multivariate_normal(mean, cov, 3000).T

fig = plt.figure(figsize=(6, 6))
grid = plt.GridSpec(4, 4, hspace=0.2, wspace=0.2)
main_ax = fig.add_subplot(grid[:-1, 1:])
y_hist = fig.add_subplot(grid[:-1, 3], xticklabels=[], sharey=main_ax)
x_hist = fig.add_subplot(grid[-1, 1:], yticklabels=[], sharex=main_ax)

main_ax.plot(x, y, 'ok', markersize=3, alpha=0.2)

x_hist.hist(x, 40, histtype='stepfilled',
            orientation='vertical', color='blue')
x_hist.invert_yaxis()

y_hist.hist(y, 40, histtype='stepfilled',
            orientation='horizontal', color='blue')
y_hist.invert_xaxis()
相关推荐
leoZ2311 分钟前
金仓老旧项目改造-10
开发语言·前端·人工智能·python·金仓
故事和你915 分钟前
洛谷-数据结构1-1-线性表2
开发语言·数据结构·算法·动态规划·图论
weixin_580614005 分钟前
PHP源码运行受主板供电影响吗_供电相数重要性说明【技巧】
jvm·数据库·python
2301_815279528 分钟前
c++怎么获取文件的Inode节点信息_stat结构体深度解析【详解】
jvm·数据库·python
小徐不徐说8 分钟前
面试C++易错点总结
开发语言·c++·面试·职场和发展·程序设计·工作
qq_2837200511 分钟前
Python模块精进: urllib 从入门到精通
网络·爬虫·python
weixin_5806140013 分钟前
如何在 Go 中使用 gocql 执行本地 CQL 脚本文件
jvm·数据库·python
lly20240614 分钟前
C语言中的循环结构:深入理解与高效应用
开发语言
异步的告白15 分钟前
链接脚本SECTIONS逐行深度解析
linux·开发语言
weixin_5806140017 分钟前
mysql权限表查询性能如何优化_MySQL系统权限缓存原理
jvm·数据库·python