Matplotlib没有显示图 [英] Matplotlib didn’t show the plot

查看:179
本文介绍了Matplotlib没有显示图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道为什么我的matplotlib不显示图,也没有错误.我认为我在安装上缺少了一些东西,因为在IPython笔记本中,使用%mayplotlib inline 指令的QtIpython没问题,但是从终端或脚本运行时却什么也没显示.有什么想法吗?

I don’t know why my matplotlib didn’t show plots, and no errors too. I thinks I missing something on its installation because when in IPython notebooks an QtIpython using %mayplotlib inline directive have no problems but when running from terminal or script didn’t show anything. Any ideas ??

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

for example, in QtIPython and Ipython notebook I run

%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()

什么都没显示

推荐答案

如果在IPython Notebook中内联使用matplotlib,则图将自动显示.如果在脚本中绘制图形,则必须在末尾放置 plt.show()才能真正显示该图.在终端中,您还可以使用 plt.ion()开启互动模式.

If you use matplotlib inline in IPython notebook, the plots are shown automatically. If you plot things in a script you have to put a plt.show() at the end to actually show the figure. In the terminal you can also use plt.ion() to switch on intreactive mode.

这篇关于Matplotlib没有显示图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆