Python for循环中有多个'subplot2grid'
我试图画出两组不同的函数,一次通过一个双循环。我不知道如何让subplot2grid对第二个图形执行操作Python for循环中有多个'subplot2grid',python,matplotlib,plot,Python,Matplotlib,Plot,我试图画出两组不同的函数,一次通过一个双循环。我不知道如何让subplot2grid对第二个图形执行操作 import numpy as np from matplotlib import pyplot as plt t=np.linspace(0,1,100) fig1=plt.figure() for i in range(3): for j in range(3): plt.subplot2grid((3,3),(i,j)) plt.plot(t,n
import numpy as np
from matplotlib import pyplot as plt
t=np.linspace(0,1,100)
fig1=plt.figure()
for i in range(3):
for j in range(3):
plt.subplot2grid((3,3),(i,j))
plt.plot(t,np.sin((t*np.random.random()*10)))
fig2=plt.figure()
for i in range(3):
for j in range(3):
plt.subplot2grid((3,3),(i,j))
plt.plot(t,np.cos((t*np.random.random()*10)))
plt.show()
有没有办法只用一个循环就能做到这一点
您应该使用面向对象的界面。以下是一个例子:
import numpy as np
from matplotlib import pyplot as plt
t = np.linspace(0, 1, 100)
fig1, axes1 = plt.subplots(3, 3)
fig2, axes2 = plt.subplots(3, 3)
blue, red = "#1E90FF", "#FF6347"
for i in range(3):
for j in range(3):
axes1[i, j].plot(t, np.sin((t * np.random.random() * 10)), blue)
axes2[i, j].plot(t, np.cos((t * np.random.random() * 10)), red)
fig1.tight_layout()
fig2.tight_layout()
您应该使用面向对象的界面。以下是一个例子:
import numpy as np
from matplotlib import pyplot as plt
t = np.linspace(0, 1, 100)
fig1, axes1 = plt.subplots(3, 3)
fig2, axes2 = plt.subplots(3, 3)
blue, red = "#1E90FF", "#FF6347"
for i in range(3):
for j in range(3):
axes1[i, j].plot(t, np.sin((t * np.random.random() * 10)), blue)
axes2[i, j].plot(t, np.cos((t * np.random.random() * 10)), red)
fig1.tight_layout()
fig2.tight_layout()
我希望更吸引人的图片能给我带来更多的互联网点数。我希望更吸引人的图片能给我带来更多的互联网点数。