How to create a pair plot in Python like the following: but with heat maps instead of points (or instead of a "hex bin" plot)? Having the possibility of instead displaying logarithmic heat map counts would be an added bonus. (Histograms on the diagonal would be perfectly fine.)
By "heat map", I mean a 2D histogram of the counts, displayed like Seaborn's or Wikipedia's heat maps:
Using Pandas, seaborn, or matplotlib would be great (maybe plot.ly).
I tried naive variations of the following, to no avail:
pairplot = sns.PairGrid(data) # sns = seaborn
pairplot.map_offdiag(sns.kdeplot) # Off-diagnoal heat map wanted instead!
pairplot.map_diag(plt.hist) # plt = matplotlib.pyplot
(the above uses a Kernel Density Estimator, which I do not want; a hex bin grid can also be obtained with Pandas, but I am looking instead for a "square" 2D histogram and Matplotlib's hist2d()
didn't work).
The Pair Plot helps us to visualize the distribution of single variables as well as relationships between two variables. They are a great method to identify trends between variables for follow-up analysis.
You can think of a heat map as a data-driven “paint by numbers” canvas overlaid on top of an image. In short, an image is divided into a grid and within each square, the heat map shows the relative intensity of values captured by your eye tracker by assigning each value a color representation.
A scatter plot matrix shows all pairwise scatter plots for many variables. If the variables tend to increase and decrease together, the association is positive. If one variable tends to increase as the other decreases, the association is negative. If there is no pattern, the association is zero.
Preparation:
%matplotlib inline #for jupyter notebook
import matplotlib.pyplot as plt
import seaborn as sns
iris = sns.load_dataset("iris")
New answer:
g = sns.PairGrid(iris)
g = g.map_upper(plt.scatter,marker='+')
g = g.map_lower(sns.kdeplot, cmap="hot",shade=True)
g = g.map_diag(sns.kdeplot, shade=True)
sns.plt.show()
Answer:
g = sns.PairGrid(iris)
g = g.map_upper(plt.scatter)
g = g.map_lower(sns.kdeplot, cmap="hot",shade=True)
g = g.map_diag(plt.hist)
sns.plt.show()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With