Python 为什么 matplotlib 给出错误 [<matplotlib.lines.Line2D object at 0x0392A9D0>]?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32774520/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
why matplotlib give the error [<matplotlib.lines.Line2D object at 0x0392A9D0>]?
提问by susansecret
I am using python 2.7.9 on win8. When I tried to plot using matplotlib, the following error showed up:
我在 win8 上使用 python 2.7.9。当我尝试使用 matplotlib 绘图时,出现以下错误:
from pylab import *
plot([1,2,3,4])[matplotlib.lines.Line2D object at 0x0392A9D0]
from pylab import *
plot([1,2,3,4])[matplotlib.lines.Line2D 对象在 0x0392A9D0]
I tried the test code "python simple_plot.py --verbose-helpful", and the following warning showed up:
我尝试了测试代码“python simple_plot.py --verbose-helpful”,出现了以下警告:
$HOME=C:\Users\XX matplotlib data path C:\Python27\lib\site-packages\matplotlib\mpl-data
You have the following UNSUPPORTED LaTeX preamble customizations:
Please do not ask for support with these customizations active.
loaded rc file C:\Python27\lib\site-packages\matplotlib\mpl-data\matplotlibrc matplotlib version 1.4.3 verbose.level helpful interactive is False platform is win32 CACHEDIR=C:\Users\XX.matplotlib Using fontManager instance from C:\Users\XX.matplotlib\fontList.cache backend TkAgg version 8.5 findfont: Matching :family=sans-serif:style=normal:variant=normal:weight=normal:stretch=normal:size=medium to Bitstream Vera Sans (u'C:\Python27\lib\site-packages\matplotlib\mpl-data\fonts\ttf\Vera.ttf') with score of 0.000000
$HOME=C:\Users\XX matplotlib 数据路径 C:\Python27\lib\site-packages\matplotlib\mpl-data
您有以下不受支持的 LaTeX 前导自定义:
请不要在这些自定义激活的情况下寻求支持。
加载的 rc 文件 C:\Python27\lib\site-packages\matplotlib\mpl-data\matplotlibrc matplotlib version 1.4.3 verbose.level 有用的交互是 False 平台是 win32 CACHEDIR=C:\Users\XX.matplotlib Using fontManager instance from C:\Users\XX.matplotlib\fontList.cache 后端 TkAgg 8.5 版 findfont: 匹配 :family=sans-serif:style=normal:variant=normal:weight=normal:stretch=normal:size=medium to Bitstream Vera Sans ( u'C:\Python27\lib\site-packages\matplotlib\mpl-data\fonts\ttf\Vera.ttf') 得分为 0.000000
What does this mean? How could I get matplotlib working?
这是什么意思?我怎样才能让 matplotlib 工作?
采纳答案by rayryeng
That isn't an error. That has created a plot object but you need to show the window. That's done using pyplot.show()
... so you seriously just have to do...
那不是错误。这已经创建了一个绘图对象,但您需要显示窗口。这是使用pyplot.show()
...完成的,所以你真的只需要做...
show()
If you don't believe me, here's a trace from IPython:
如果你不相信我,这里有一个来自 IPython 的跟踪:
In [9]: from pylab import *
In [10]: plot([1,2,3,4])
Out[10]: [<matplotlib.lines.Line2D at 0x123245290>]
In [11]: show()
We get:
我们得到:
As mentioned in the comments, you should avoid using pylab
. You should use matplotlib.pyplot
instead.... so:
正如评论中提到的,你应该避免使用pylab
. 你应该matplotlib.pyplot
改用......所以:
import matplotlib.pyplot as plt
plt.plot([1,2,3,4])
plt.show()
回答by Joe Wang
In Jupyter nodebook, you could just insert
在 Jupyter 节点簿中,您可以插入
%matplotlib inline
before you use matplotlib
.
在您使用之前matplotlib
。
回答by ??????? ????
Incase you're using jupyter notebook, you can run interactive plotting on command
如果您使用的是 jupyter notebook,则可以在命令上运行交互式绘图
ion()
离子()
before you plot anything. This will show the graph in notebook itself.
在你绘制任何东西之前。这将在笔记本本身中显示图形。
回答by Cam
I came across this same message in jupyter notebook.
我在 jupyter notebook 中遇到了同样的消息。
I just added %matplotlib notebook and my charts show up now.
我刚刚添加了 %matplotlib notebook,现在我的图表显示出来了。
I think %matplotlib inline should work also.
我认为 %matplotlib inline 也应该工作。
回答by Prantik Sarmah
Had this problem. You just have to use show()
function to show it in a window. Use pyplot.show()
有这个问题。您只需要使用show()
函数将其显示在窗口中即可。用pyplot.show()