因此,对于下面的代码,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)发布于 2020-04-24 04:56:57
而不是
return plt.show()使用
fig.show()如果要在笔记本中显示图片,请在%matplotlib inline命令之前计算的单元格中使用show。
注意事项问题是数组是形状的(1,24)。只喜欢一维数组。用ax.plot(x, dens)代替ax.plot(x.reshape(-1), dens.reshape(-1))解决了这个问题。
https://stackoverflow.com/questions/61401389
复制相似问题