如何在python中显示matplotlib图 [英] How to show matplotlib plots in python
本文介绍了如何在python中显示matplotlib图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我确信matplotlib for python的配置正确,因为我已经用它绘制了一些数字.
I am sure the configuration of matplotlib for python is correct since I have used it to plot some figures.
但是今天它由于某种原因而停止工作.我用非常简单的代码进行了测试,例如:
But today it just stop working for some reason. I tested it with really simple code like:
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(0, 5, 0.1)
y = np.sin(x)
plt.plot(x, y)
没有错误,但没有显示任何数字.
there's no error but just no figure shown up.
我正在Ubuntu上使用python 2.6,Eclipse
I am using python 2.6, Eclipse in Ubuntu
推荐答案
在matplotlib中,您有两个主要选择:
In matplotlib you have two main options:
-
创建图并在最后绘制它们:
Create your plots and draw them at the end:
import matplotlib.pyplot as plt
plt.plot(x, y)
plt.plot(z, t)
plt.show()
创建图并在创建后立即绘制它们:
Create your plots and draw them as soon as they are created:
import matplotlib.pyplot as plt
from matplotlib import interactive
interactive(True)
plt.plot(x, y)
raw_input('press return to continue')
plt.plot(z, t)
raw_input('press return to end')
这篇关于如何在python中显示matplotlib图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文