Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Seaborn pairwise matrix of hexbin jointplots

I am trying to produce a matrix of pairwise plots comparing distributions (something like this). Since I have many points I want to use a hexbin plot to reduce time and plot complexity.

import seaborn as sns
import matplotlib.pyplot as plt


tips = sns.load_dataset("tips")

g = sns.FacetGrid(tips, col="time", row="sex")
g.map(sns.jointplot, "total_bill", "tip", kind="hex")
plt.show()

Nevertheless, instead of creating the matrix of plots it creates several plots independently in various windows.

I also thought of using seaborn.pairplot to produce this but I can not pass "hex" as a value to kind.

like image 402
afrendeiro Avatar asked Mar 16 '23 10:03

afrendeiro


1 Answers

See the last example in the tutorial on using custom functions with FacetGrid, which I'll reproduce here:

def hexbin(x, y, color, **kwargs):
    cmap = sns.light_palette(color, as_cmap=True)
    plt.hexbin(x, y, gridsize=15, cmap=cmap, **kwargs)

g = sns.FacetGrid(tips, hue="time", col="time", size=4)
g.map(hexbin, "total_bill", "tip", extent=[0, 50, 0, 10])

enter image description here

like image 182
mwaskom Avatar answered Mar 24 '23 17:03

mwaskom