Matplotlib未显示图形
这应该是个非常基础的问题:我正在尝试使用Matplotlib。这里是来自文档的基本示例。
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(0,5,0.1)
y = np.sin(x)
plt.plot(x,y)
我在ipython
、bpython
和默认的解释器(Ubuntu 10.10,64位)中都试过这个,但我得到的都是一些这样的消息:
[<matplotlib.lines.Line2D object at 0x3f14a90>]
我到底哪里做错了?
2 个回答
6
在默认设置下,matplotlib需要你告诉它去显示图形。这就是plt.show()的作用。
matplotlib还有一个互动模式,这在你需要实时查看绘图结果时非常有用。使用这个模式最简单的方法是打开一个带有-pylab选项的ipython会话。 http://matplotlib.sourceforge.net/users/shell.html
15
你忘了加 plt.show()
这行代码,它是用来告诉 matplotlib 显示一个窗口,里面有你画的图。