0

I am not experienced with plotting in Python. But I have managed to plot a signle distribution plot with Seaborn.

example code:

sns.displot(SD_frame_A,kind="kde")

example plot: enter image description here

So I tryed to plot three of them in one graph:

example code:

sns.displot(SD_frame_A,kind="kde")
sns.displot(SD_frame_S,kind="kde")
sns.displot(SD_frame_D,kind="kde")
plt.show()

But this will only plot the three distribution separately. Does anyone how I can plot both 3 distribution in one plot?

Thanks for reading!

SimonDL
  • 186
  • 10

1 Answers1

2

You can't do that with displot because that is a figure-level function. But you can use kdeplot and provide an axes object:

ax = plt.axes()
sns.kdeplot(SD_frame_A, ax=ax)
sns.kdeplot(SD_frame_S, ax=ax)
sns.kdeplot(SD_frame_D, ax=ax)
plt.show()
LukasNeugebauer
  • 1,331
  • 7
  • 10
  • Thank you, but it returns the following error: ValueError: cannot reindex on an axis with duplicate labels – SimonDL May 25 '22 at 12:42
  • Are the frames pandas Series? Try transforming them to numpy arrays with `SD_frame_A.values`. – LukasNeugebauer May 25 '22 at 12:48
  • Yes they are in pandas series so I changed it to a dataframe which did not work either. I will try your option now – SimonDL May 25 '22 at 12:51
  • Sure, happy it worked! – LukasNeugebauer May 25 '22 at 12:57
  • Well it only worked for a "kdeplot", when I use the "displot" it still plots them separately. And it even becomes slower – SimonDL May 25 '22 at 13:01
  • And gives three time this message in the kernel: \lib\site-packages\seaborn\distributions.py:2211: UserWarning: `displot` is a figure-level function and does not accept the ax= paramter. You may wish to try kdeplot. warnings.warn(msg, UserWarning). So that makes sense :) – SimonDL May 25 '22 at 13:02
  • yes, `displot` is the wrong function for that. – LukasNeugebauer May 25 '22 at 13:04
  • But isn't the 'kdeplot' used for non normally distributed data? – SimonDL May 25 '22 at 13:07
  • I think `kdeplot` uses a Gaussian kernel, but I'm pretty sure that `displot(kind='kde')` uses `kdeplot` inside. If you want to fit a gaussian distribution (not a mixture of those), you'll have to do something different altogether – LukasNeugebauer May 25 '22 at 13:11