相关矩阵图——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()
相关推荐
源码站~4 分钟前
基于Flask+Vue的豆瓣音乐分析与推荐系统
vue.js·python·flask·毕业设计·毕设·校园·豆瓣音乐
MessiGo9 分钟前
Python 爬虫实战 | 国家医保
python
我是唐青枫18 分钟前
C#.NET NLog 详解
开发语言·c#·.net
chanalbert25 分钟前
Spring 6 源码深度掘金:66+核心原理与高频面试攻坚指南
python·spring·面试
Mr_Xuhhh38 分钟前
网络基础(1)
c语言·开发语言·网络·c++·qt·算法
旺旺大力包42 分钟前
【JS笔记】JS 和 noodjs 的常见操作(十)
开发语言·javascript·node.js·ecmascript
都叫我大帅哥1 小时前
向量数据库Milvus:非结构化数据的救星,AI开发者的瑞士军刀
java·python
背影疾风1 小时前
C++之路:类基础、构造析构、拷贝构造函数
linux·开发语言·c++
Ting-yu2 小时前
Java中Stream流的使用
java·开发语言·windows
【ql君】qlexcel2 小时前
Notepad++ 复制宏、编辑宏的方法
开发语言·javascript·notepad++··宏编辑·宏复制