如何从终端输出python图?

mlh*_*zan 1 python numpy matplotlib

我对 Python 很陌生。昨天刚刚在 Ubuntu 15.04 上安装了它。现在我试图从终端输出抛物线。据我所知,我无法在终端上输出任何图形,所以我如何才能看到图形?

我做了: sudo apt-get install python-numpy python-scipy python-matplotlib

我的代码是

import matplotlib.pyplot as plt
import numpy as np

# create 1000 equally spaced points between -10 and 10
x = np.linspace(-10, 10, 1000)

# calculate the y value for each element of the x vector
y = x**2 + 2*x + 2  

fig, ax = plt.subplots()
ax.plot(x, y)
Run Code Online (Sandbox Code Playgroud)

当我这样做python parabola.py但没有输出时它不显示错误:(

bla*_*mba 5

您需要在代码末尾添加 plt.show() 以显示抛物线。

http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.show