1 回答

TA贡献1772条经验 获得超6个赞
https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.fill_between.html的注释
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
sns.set()
x = np.random.uniform(45,60, 1000)
#With Seaborn
sns.distplot(x)
# fill square defined by x, y0, y1
# need to get pdf and bins generated by sns to do fill between here
## With numpy is easier for me
# density function
y, ybin = np.histogram(x, bins=np.arange(45,61), density=True)
x_points = np.arange(50,56)
x_point_inds = np.arange(5,11)
y0 = np.zeros(6)
y1 = y[x_point_inds]
#With Matplotlib
plt.hist(x,bins=ybin,density=True, zorder=1)
plt.fill_between(x_points, y0, y1, color='g', alpha=0.5, zorder=5)
添加回答
举报