因此,对于以下代码,jupyter笔记本中没有打印任何图形。如果我使用plt.scatter,那么它会生成图形。有什么建议吗?有什么问题吗?这可能是由数据引起的吗
import pandas as pd
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
def calc_gauss(df, index):
x=df.iloc[[index]]
mean = df.apply(lambda x: x.mean(), axis=1)
mu=mean.iloc[[index]]
std = df.std(axis=1)
sig=std.iloc[[index]]
dens = norm.pdf(x,mu,sig)
# build the plot
fig, ax = plt.subplots(figsize=(9,6))
plt.style.use('fivethirtyeight')
ax.plot(x, dens)
return plt.show()
calc_gauss(df_distance, 339)
而不是
使用
如果要在笔记本中显示图片,请在
show
命令之前计算的单元格中使用%matplotlib inline
注意问题在于阵列的形状(1,24)。plot只喜欢1D数组。用
ax.plot(x.reshape(-1), dens.reshape(-1))
替换ax.plot(x, dens)
解决了这个问题相关问题 更多 >
编程相关推荐