问题描述
所以我的代码是:
import numpy as np
import matplotlib.pyplot as plt
x = [1,2,3,4,5]
y = [2,6,8,10]
x1 = [1,5]
y1 = [1,9,14,25]
t = np.arange(0.0,2.0,0.01)
s1 = np.sin(2*np.pi*t)
s2 = np.sin(4*np.pi*t)
plt.figure(1)
plt.subplots(211)
plt.plot(x,y)
plt.subplots(212)
plt.plot(x1,y1)
plt.figure(2)
plt.subplot(211)
plt.plot(t,s1)
plt.subplot(212)
plt.plot(t,2*s1)
plt.show()
当我刚运行图2时,一切都很好,但是当我运行所有代码时,图变得嘈杂 也将取代图2来运行一个空的图num1 如你在pic1中看到的结果 pic
解决方法
您的代码中有一个小的错字。
在属于figure(1)
的图中,将您的subplots()
更改为subplot()
(删除结尾的s)