【发布时间】:2020-01-31 00:03:53
【问题描述】:
当我在 jupyter 中按顺序循环填充数组并使用 plt.plot 语句在数组增长时打印数组时,我可以单独打印出数组,但只能打印一个图。
import numpy as np
import matplotlib.pyplot as plt
import time
muarr = np.linspace(0,10,10)
print('muarray')
print(muarr)
z = np.linspace(0.0,1.0,10) # create an array
print('array z')
print(z)
def fillit(mu):
x = 10 # initial x value
for i in range(0,10): # fill n2-n1 iterations
z[i] = i * x * mu
return z # returning the array
for i in range(0,10):
mu = muarr[i] #for a specific horizontal axis location
print()
print('iteration '+ str(i))
print('muarray '+str(i))
print('mu = '+str(mu))
y=fillit(mu) # an array of 10 elements from 0 to 100*mu
print('array y is an array of 10 elements from 0 to 100*mu')
print (y)
x=y*0.0 + mu # dummy x value is all mu
print('array x is just all mu so that each x,y pt can be plotted')
print (x)
plt.plot(x,y,'ko',markersize=1) # k=black, plot small points
如图所示,我可以从控制台实时绘图 here 但这在 jupyter 中也不起作用。 当我从终端将该代码作为 python 脚本运行时,数组打印出来但根本没有绘图。
我希望绘图在生成数据时实时更新。这在jupyter中可能吗?
【问题讨论】:
-
那么您是否正在为 for 循环中的每个
plt.plot寻找多个绘图窗口?另外,我想知道为什么你的代码中没有plt.show()。 -
几乎重复:python - Get Jupyter notebook to display matplotlib figures in real-time - Stack Overflow——除了那个问题希望图表按顺序显示而不是替换。
标签: python matplotlib jupyter-notebook jupyter