0

I have simplified code like this:

fig, axs = plt.subplots(1, 2)
axs[0].hist(x)
axs[1].hist(y)

and I need to add density curve to each plot. Anyone know reasonable simple way to do this? It could be using seaborn. Kindly help.

Funtion seaborn.displot() does not working in subplots.

paDU
  • 45
  • 5
  • Does this answer your question? [Add density curve on the histogram](https://stackoverflow.com/questions/64467644/add-density-curve-on-the-histogram) – Trenton McKinney Sep 19 '21 at 12:39
  • The question in the op is _I need to add density curve to each plot._ which is provided in the accepted answer of the duplicate (the same as is shown below), as `kde=True`. So it does answer the question. The accepted answer in the duplicate shows how to add a density curve for each of the seaborn plots that produce a histogram. – Trenton McKinney Sep 19 '21 at 15:46
  • 1
    You are right, I did not noticed that. Sorry, my mistake. You can close this post if you want. – paDU Sep 19 '21 at 15:50
  • 1
    Best regards, and happy coding. – Trenton McKinney Sep 19 '21 at 15:51

1 Answers1

1

You could use seaborn.histplot and pass kde parameter:

fig, axs = plt.subplots(1, 2)

sns.histplot(x, ax = axs[0], kde = True)
sns.histplot(y, ax = axs[1], kde = True)

enter image description here

Zephyr
  • 11,891
  • 53
  • 45
  • 80