0

I am trying to create a plot. I want to have a bi-variate histogram, which I successfully realized by using seaborn's sns.displot. Now I want to add some contour lines. However, these contours should not represent the density of data points in my grid, but some other expression, i.e. x*y. I succeeded creating those with contour, however only in an isolated, new graph. I need both in one graph (or "axis").

Displot:

import seaborn as sns
penguins = sns.load_dataset("penguins")
sns.displot(data=penguins, x="flipper_length_mm", y="bill_length_mm")

Displot

Contour:

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(-10, 10, .1)
y = np.arange(-10, 10, .1)
X, Y = np.meshgrid(x, y)
Z = X*Y
fig, ax = plt.subplots(figsize=(6,6))
ax.contour(X,Y,Z, levels=10)
plt.show()

Contour

What I am looking for: I want ONE plot with these kind of contours lines - representing e.g. the product of x and y - inside my "displot". Sidenode: I do not insist on seaborn or any lib. Just interested in the final result ;)

Thanks!

  • 1
    i switched from displot to histplot and was abled to achive what i wanted. UserWarning:1 `displot` is a figure-level function and does not accept the ax= paramter. You may wish to try histplot. – Schwarsey Sep 16 '22 at 12:37

0 Answers0