[英]Why does matplotlib require setting log scale before plt.scatter() but not plt.plot()?
[英]plt.show() does not print plt.plot only plt.scatter
因此,对于以下代码,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)
代替
return plt.show()
利用
fig.show()
如果要在笔记本中显示图片,请在show
命令之前评估的单元格中使用%matplotlib inline
请注意,问题是 arrays 的形状为 (1,24)。 plot 只喜欢 1D arrays。 用ax.plot(x.reshape(-1), dens.reshape(-1))
替换ax.plot(x, dens)
) 解决了这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.