Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib to plot a pairplot?

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.sstatic.net/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!

like image 824
Jorge Gill Avatar asked Jun 09 '26 01:06

Jorge Gill


1 Answers

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()

enter image description here 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})

enter image description here

like image 134
m13op22 Avatar answered Jun 11 '26 23:06

m13op22



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!