Originally, I have a bar data like this.
import pandas as pd
import matplotlib.pyplot as plt
import pandas
import numpy as np
x = np.array([1, 2, 3.1, 3.2, 4.1, 4.2, 4.3, 5, 6, 7])
y = np.random.rand(10)
s = pandas.Series(y, index=x)
1.0 0.895835
2.0 0.117966
3.1 0.397263
3.2 0.669877
4.1 0.330271
4.2 0.664608
4.3 0.006288
5.0 0.671697
6.0 0.587998
7.0 0.809034
dtype: float64
Then, I want to use this bar data create a histogram. So I add weight=s.values
to achieve sum in a same section.
plt.hist(s.index, weights=s.values, bins=7)
plt.show(
However I have no idea about how to bulit a kde in this figure.