使用matplotlib

时间:2019-02-12 23:30:32

标签: python matplotlib scipy

我试图添加一条“线”以显示均值在我的代码中的位置,然后在该线左右两侧的区域中加一个标准差。

到目前为止,我所拥有的是法线曲线和直方图。我在弄清楚如何正确使用fill_between时遇到了麻烦。

正常dist和hist的工作代码如下,但我想添加阴影。

import numpy as np
import pandas as pd
from scipy.stats import norm
import matplotlib.pyplot as plt

df = pd.read_csv(r'c:\Work\my_data.csv')
df = df.dropna()

instructor_scores = df['Score Field']
sigma = instructor_scores.std()
mu = instructor_scores.mean()

fit = norm.pdf(instructor_scores, mu, sigma)

plt.plot(instructor_scores, fit, '-0')
plt.hist(instructor_scores, density=True)

plt.show()

我认为fill_between是正确的方法,但是我太新了,无法确定。如果我使用,看起来会怎样?我在这里看到了几个答案:fill_between,但是我认为我不完全理解如何使用它,而且我看到的答案对于我要寻找的内容来说太高级了。当我进行绘图时,最终在图形上方显示一个蓝色条。我不知道要添加什么参数才能在绘图中获得基本的fill_between。

0 个答案:

没有答案