matplotlib R的对的类似物 [英] matplotlib analog of R's `pairs`

查看:100
本文介绍了matplotlib R的对的类似物的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

R有一个有用的函数pairs,它提供数据集中变量之间成对连接的图的漂亮矩阵.生成的图与下图类似,是从此博客文章:

R has a useful function pairs that provides nice matrix of plots of pairwise connections between variables in a data set. The resulting plot looks similar to the following figure, copied from this blog post:

基于python matplolib的函数是否可以使用?我已经搜索了它的画廊,但是找不到与我需要的东西相似的东西.从技术上讲,这应该是一个简单的任务,但是正确处理所有可能的案例,标签,标题等非常繁琐.

Is there any ready to use function based on python's matplolib? I have searched its gallery, but couldn't find anything that resembles what I need. Technically, this should be a simple task, but proper handling of all the possible cases, labels, titles, etc is very tedious.

更新,下面是我的答案,并给出了快速而肮脏的近似值.

UPDATE see below my answer with a quick and dirty approximation.

推荐答案

Pandas 具有内置函数scatter_matrix( 源代码).

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt 

df = pd.DataFrame(np.random.randn(1000, 4), columns=['A','B','C','D'])
axes = pd.tools.plotting.scatter_matrix(df, alpha=0.2)
plt.tight_layout()
plt.savefig('scatter_matrix.png')

但是它是pandas特定的(但可以用作起点).

However it is pandas specific (but could be used as a starting point).

还有更多R像大熊猫一样的情节.看看 docs .

There are some more R like plots in pandas. Have a look at the docs.

这篇关于matplotlib R的对的类似物的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆