有人能看看这个密码吗?我必须做3个鼻窦轴的样本。
import matplotlib.pyplot as plt
import numpy as np
t = np.arange(0.0, 2.0, 0.01)
fig = plt.figure()
ax1 = fig.add_subplot(311)
y1 = np.sin(2*np.pi*t)
ax1.plot(t, y1);
ax1.grid(True)
ax1.set_ylabel('1 Hz');
ax2 = fig.add_subplot(312)
y2 = np.sin(4*np.pi*t)
ax2.plot(t, y2);
ax2.grid(True)
ax2.set_ylabel('4 Hz');
ax3 = fig.add_subplot(313)
y3 = np.sin(6*np.pi*t)
ax3.plot(t, y3);
ax3.grid(True)
ax3.set_ylabel('6 Hz');
plt.show()
有人能告诉我为什么这个密码什么都不做吗?我只看到“图1”,仅此而已。
发布于 2014-03-24 22:12:11
尝试在fig.canvas.draw()
之前添加plt.show()
。
传统上,fig.canvas.draw()
进行实际绘图,plt.show()
进入交互式事件循环。当使用IPython或交互式解释器时,ion()
和ioff()
在每个命令之后切换更新。
有趣的是,您的代码在我的计算机上也做了它应该做的事情(Debian不稳定)--可能是这种行为随着新的Matplotlib版本而改变了。
https://stackoverflow.com/questions/22612256
复制相似问题