Matplotlib没有显示情节

时间:2015-11-26 19:09:10

标签: python matplotlib ipython

我不知道为什么我的matplotlib没有显示情节,也没有错误。我认为我在安装时遗漏了一些东西,因为在IPython笔记本中使用%mayplotlib inline指令的QtIpython没有问题但是从终端或脚本运行时没有显示任何内容。任何想法??

例如,在QtIPython和Ipython笔记本中我运行

%matplotlib inline
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111, aspect='equal')
ax.plot([1,2,3,4,5,6,7,8,9,0],[2,3,4,5,6,7,8,9,0,11], '-r')
ax.grid()
plt.show()

,情节显示确定!

但是使用

的简单脚本
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111, aspect='equal')
ax.plot([1,2,3,4,5,6,7,8,9,0],[2,3,4,5,6,7,8,9,0,11], '-r')
ax.grid()
plt.show()

没有显示任何内容

1 个答案:

答案 0 :(得分:2)

如果您在IPython笔记本中使用matplotlib内联,则会自动显示这些图。如果您在脚本中绘制内容,则必须在末尾放置Student[] students = new Student[x]; int i = students.length; while(--i != -1) { // Adds students to the array students[i] = new Student(); } students[0].name = "you"; students[0].grade = 1; students[1].name = "stackoverflow"; students[1].grade = Integer.MAX_VALUE; 以实际显示该图。在终端中,您还可以使用plt.show()打开非活动模式。