欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

解決matplotlib.pyplot在Jupyter notebook中不顯示圖像問題

 更新時間:2020年04月22日 14:54:25   作者:騎蝸牛前行  
這篇文章主要介紹了解決matplotlib.pyplot在Jupyter notebook中不顯示圖像問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

在代碼首行添加:

%matplotlib inline

即可。

補(bǔ)充知識:jupyter不能顯示Matplotlib 動畫

看莫煩老師的matplotlib教程中,有一段sinx函數(shù)動畫,用Jupyter跑卻不能顯示動畫效果。

解決方案:在前面加一句%matplotlib notebook

動畫代碼如下:

%matplotlib notebook
import tensorflow as tf 
import numpy as np 
import matplotlib.pyplot as plt
from matplotlib import animation
fig, ax = plt.subplots()
x =np.arange(0,2*np.pi,0.01)
# 返回的是個列表
line , = ax.plot(x,np.sin(x))
def animate(i):
  # xdata 保持不變, ydata 更新成另外一批數(shù)據(jù)
  # 將0-100都傳進(jìn)去更新一下,i變化時,y也會變化,更新圖像
  line.set_ydata(np.sin(x+i/10))
  return line,

def init():
  line.set_ydata(np.sin(x))
  return line,

# interval 是更新的頻率,隔多少毫秒更新一次,這里是隔20ms更新一次
# blit=True,只更新有變化的點(diǎn)
ani = animation.FuncAnimation(fig=fig,func=animate,frames =100,init_func=init,interval =20,blit=False)
plt.show()

以上這篇解決matplotlib.pyplot在Jupyter notebook中不顯示圖像問題就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論