![](/img/trans.png)
[英]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.