Entering edit mode
5.4 years ago
laura_savana
▴
20
Hi, I have a question about how overlap more "kernel density estimations" in Python. I have 12 list of values and I plot for each of them kernel density estimation. I would overlap these 12 different kde in the same plot. Someone know how make this?
Thank you
Example data are always helpful. How To Ask Good Questions On Technical And Scientific Forums
Thank for your advice. I thought that wasn't necessary post also example code. So, I report the python script to plot a histogram with its kde. At bottom there is link to see the output.
import numpy as np
import pandas as pd
from scipy import stats
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline
"""array_1 contains 102 values each of which between 0 and 1"""
array_1 = [0.8, 0.9, 0.78, 0.97, 0.87, 0.78, 0.89, 0.83, 0.97, 0.95, 0.87, 0.95, 0.92, 0.78, 0.92, 0.92, 0.95, 0.92, 0.77, 0.74, 0.73, 0.76, 0.74, 0.93, 0.8, 0.83, 0.78, 0.79, 0.83, 0.82, 0.82, 0.77, 0.75, 0.79, 0.77, 0.74, 0.82 ...]
kde = stats.gaussian_kde(array_1)
xx = np.linspace(0, 1, 102)
plt, ax = plt.subplots(figsize = (10, 10))
ax.xaxis.set_tick_params(labelsize = 20)
ax.yaxis.set_tick_params(labelsize = 20)
ax.set_title('Score distribution', fontsize = 30)
ax.set_xlabel('Score', fontsize = 22)
ax.set_ylabel('Density', fontsize = 22)
ax.hist(array_1, bins = 20, range = (0, 1), color = '#86b300', density=True, edgecolor='black', linewidth=1.2)
ax.plot(xx, kde(xx), linewidth = 3, color = '#1a3300')
Consider that I would a unique plot with only kdes. I would overlap another 11 kdes to that already existing. Another 11 arrays are similar to what I have reported above (named 'array_1').
Thank you so much