np.histogram
:import numpy as np
from matplotlib import pyplot as plt
fig, ax = plt.subplots()
chisq = np.random.chisquare(3, 1000)
norm = np.random.normal(10, 4, 1000)
chisq_counts, chisq_bins = np.histogram(chisq, 50)
norm_counts, norm_bins = np.histogram(norm, 50)
ax.plot(chisq_bins[:-1], chisq_counts)
ax.plot(norm_bins[:-1], norm_counts)
plt.show()
对于你的数据这个具体情况,由于存在异常值,我们需要在绘图之前进行剪切:
clipped_df1 = np.clip(df1, 0, 100)
clipped_df2 = np.clip(df2, 0, 100)
# continue plotting
plt.show()
。 - gmdsrange=(0, 100)
的原因。我将编辑我的代码来纠正这个问题。 - gmds
data = plt.hist(...)
,您可以使用plt.plot(data[0])
。 - furas