jupyter-notebook matplotlib python jupyter

# python - 如何在Jupyter中实时绘制

``````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
``````

aquagremlin

80
Noki 2020-02-03 15:42

``````%matplotlib notebook
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

fig = plt.figure()
plt.ion()

fig.show()
fig.canvas.draw()

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)
ax.plot(x,y,'ko',markersize=1)
fig.canvas.draw()
time.sleep(1)
``````

``````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
plt.show()
``````