Matplotlib 绘制配对图? [英] Matplotlib to plot a pairplot?

查看:57
本文介绍了Matplotlib 绘制配对图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

昨天我发布了此信息:我不确定您为什么不想使用Seaborn,但是您可以通过执行以下操作轻松地完成相同的操作

 #使用Seaborn绘制sns.pairplot(df,diag_kws = {'bins':10})

Yesterday I posted this: Correlation scatter plot using DataFrame matrix?

Because my English is not so good on the technical side, it was hard for me to explain what was my problem.

I'm trying to be able to plot a pairplot using this correlation data:

https://i.stack.imgur.com/uJvG1.png

ozone,radiation,temperature,wind,
1.0,0.3483416929936026,0.6985414096486389,-0.6129507522144628
0.3483416929936026,1.0,0.2940876437245132,-0.12736562398818144
0.6985414096486389,0.2940876437245132,1.0,-0.49714591092004284
-0.6129507522144628,-0.12736562398818144,-0.49714591092004284,1.0

I tried with pandas but I had poor results, plus I'd prefer to plot it with matplotlib if necessary. I've been trying to find solutions online for this question but I haven't been successful. Please help!

解决方案

Based on the link in my comment, you can do

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

df = pd.DataFrame({'ozone': [1.0, 0.3483416929936026, 0.6985414096486389, -0.6129507522144628],
               'radiation': [0.3483416929936026, 1.0, 0.2940876437245132, -0.12736562398818144],
               'temperature':[0.6985414096486389, 0.2940876437245132, 1.0, -0.49714591092004284],
               'wind': [-0.6129507522144628, -0.12736562398818144, -0.49714591092004284, 1.0]})

g = pd.plotting.scatter_matrix(df, figsize=(10,10), marker = 'o', hist_kwds = {'bins': 10}, s = 60, alpha = 0.8)

plt.show()

I'm not sure why you don't want to use Seaborn, but you can do the same thing easily by doing

# Plot using Seaborn
sns.pairplot(df, diag_kws={'bins': 10})

这篇关于Matplotlib 绘制配对图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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