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