79298731

Date: 2024-12-21 01:32:49
Score: 0.5
Natty:
Report link

Building on @JohanC's answer, here is code that works when kind='scatter'

import matplotlib.pyplot as plt
import seaborn as sns
from matplotlib.collections import PolyCollection

iris = sns.load_dataset('iris')
g = sns.jointplot(data=iris, x="petal_length", y="petal_width", hue='species', marginal_kws={'common_norm': False},)

# rescale the curves in the x direction
max_height = max([elt._paths[0]._vertices[:, 1].max() for elt in g.ax_marg_x.get_children() if isinstance(elt, PolyCollection)])
for elt in g.ax_marg_x.get_children():
    if isinstance(elt, PolyCollection):
        height = elt._paths[0]._vertices[:, 1].max()
        elt._paths[0]._vertices[:, 1] = elt._paths[0]._vertices[:, 1] / height * max_height
max_height = max([elt._paths[0]._vertices[:, 0].max() for elt in g.ax_marg_y.get_children() if isinstance(elt, PolyCollection)])
for elt in g.ax_marg_y.get_children():
    if isinstance(elt, PolyCollection):
        height = elt._paths[0]._vertices[:, 0].max()
        elt._paths[0]._vertices[:, 0] = elt._paths[0]._vertices[:, 0] / height * max_height

The resulting plot is the following: jointplot with normalized marginal heights

Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @JohanC's
  • Low reputation (1):
Posted by: cmcca