问题
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!
回答1:
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})
来源:https://stackoverflow.com/questions/56188305/matplotlib-to-plot-a-pairplot