Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pair plot with heat maps (possibly logarithmic)?

How to create a pair plot in Python like the following: enter image description here 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:

enter image description here

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

like image 794
Eric O Lebigot Avatar asked May 11 '17 19:05

Eric O Lebigot


People also ask

What does a pair plot tell you?

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.

How do you analyze heatmap data?

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.

How do you interpret a pairwise scatter plot?

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.


1 Answers

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

enter image description here

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

enter image description here

like image 58
Konstantin Purtov Avatar answered Oct 04 '22 19:10

Konstantin Purtov