绘制直方图 [英] Plotting histograms

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

问题描述

我有一些存储在矢量中的值(比如-a到a),我想要

来绘制这些值的直方图。我怎样才能在python中完成它。

我已经安装并导入了Matplotlib软件包但执行了

代码

[N,x ] = hist(eig,10)#make a histogram

我收到错误提示NameError:name''hist''不是

defined"。


有没有其他方法可以在给定范围内绘制直方图?


谢谢


Amit

解决方案

am*********** @ gmail.com 写道:


我有一些值(比如-a到a)存储在矢量中,我想要

来绘制这些值的直方图。我怎样才能在python中完成它。

我已经安装并导入了Matplotlib软件包但执行了

代码

[N,x ] = hist(eig,10)#make a histogram

我收到一条错误,上面写着NameError:name''hist''不是

defined。



我假设你做的是这样的:


来自matplotlib import pylab

[N,x] = hist(eig,10)


你真正想要的是:


来自matplotlib import pylab

[N,x] = pylab.hist(eig,10)


或者,如果您处于交互式提示符(但请记住,不建议使用

在模块中这样做):

来自matplotlib.pylab的
导入*

[N,x] = hist(eig, 10)


如果您不了解差异,您可能想要查看导入

模块的教程部分。


-

Robert Kern


我开始相信整个世界都是一个谜,一个无害的谜

由于我们疯狂地试图解释它而变得可怕,好像它有一个潜在的真相。

- Umberto Eco


2006年10月16日20:49:10 -0700, am ********** *@gmail.com

< am *********** @ gmail.comwrote:


hi,我有一些存储在向量中的值(比如-a到a),我想要

来绘制这些值的直方图。我怎样才能在python中完成它。

我已经安装并导入了Matplotlib软件包但执行了

代码

[N,x ] = hist(eig,10)#make a histogram

我收到一条错误,上面写着NameError:name''hist''不是

defined。



在程序开头使用来自pylab import *的语句。


其他当然,可能会发现它更有品味和Pythonic:


[N,x] = pylab.hist(eig,10)


ie ,使用包名称作为前缀。毕竟,不想让程序的

全局命名空间混乱。


祝你好运。我想我看到了高级线性

代数与''eig''(Eigen-?)的参考,我相信你明白比我更好

。 :)


- Theerasak


文章< ma ************* *****************************@python.o rg>,

Robert Kern< ro ***** **** @ gmail.com写道:


我假设你做的是这样的:

来自matplotlib import的
pylab

[N,x] = hist(eig,10)


你真正想要的是:

$ b来自matplotlib的$ b导入pylab

[N,x] = pylab.hist(eig,10)


或者,如果你在交互式提示(但请记住,这是不可取的



在模块中这样做):


来自matplotlib.pylab import *

[N,x] = hist(eig,10)


您可能希望查看有关导入的教程部分<如果您不理解这些差异,请使用
模块。



pylab是matplotlib的一部分吗?我一直认为这是另一种方式

左右。作为scipy的一部分,我对numpy有类似的看法。也许我是

对依赖项感到困惑。我发现在实例中有些令人困惑

有时当更大时包是导入的(例如scipy)然后是

"子包"也是进口的。像这样:


来自scipi import *

来自scipi import numpy


我知道我见过这样的东西,但我不明白。依赖关系

让我感到困惑。


我搜索了导入教程,但没有找到答案。< br $>

- Lou Pecora(我的观点是我自己的)删除它给我发电子邮件。


hi, I have some values(say from -a to a) stored in a vector and I want
to plot a histogram for those values. How can I get it done in python.
I have installed and imported the Matplotlib package but on executing
the code
[N,x]=hist(eig, 10) # make a histogram
I am getting an error saying "NameError: name ''hist'' is not
defined".

Is there any other way to plot histograms over a given range?

thanks

Amit

解决方案

am***********@gmail.com wrote:

hi, I have some values(say from -a to a) stored in a vector and I want
to plot a histogram for those values. How can I get it done in python.
I have installed and imported the Matplotlib package but on executing
the code
[N,x]=hist(eig, 10) # make a histogram
I am getting an error saying "NameError: name ''hist'' is not
defined".

I presume what you did was something like this:

from matplotlib import pylab
[N,x] = hist(eig, 10)

What you actually want is this:

from matplotlib import pylab
[N,x] = pylab.hist(eig, 10)

Or, if you''re at the interactive prompt (but remember that it is inadvisable to
do so in modules):

from matplotlib.pylab import *
[N,x] = hist(eig, 10)

You will probably want to review the section of the tutorial on importing
modules if you don''t understand the differences.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco


On 16 Oct 2006 20:49:10 -0700, am***********@gmail.com
<am***********@gmail.comwrote:

hi, I have some values(say from -a to a) stored in a vector and I want
to plot a histogram for those values. How can I get it done in python.
I have installed and imported the Matplotlib package but on executing
the code
[N,x]=hist(eig, 10) # make a histogram
I am getting an error saying "NameError: name ''hist'' is not
defined".

Use the statement ''from pylab import *'' in the beginning of your program.

Others, of course, may find it more tasteful and Pythonic to do:

[N,x]=pylab.hist(eig, 10)

i.e., prefix it with the package name. Wouldn''t want to clutter the
global namespace of your program after all.

Good luck with it then. I think I see a reference to advanced linear
algebra with ''eig'' (Eigen-?) and I''m sure you understand that better
than I. :)

-- Theerasak


In article <ma**************************************@python.o rg>,
Robert Kern <ro*********@gmail.comwrote:

I presume what you did was something like this:

from matplotlib import pylab
[N,x] = hist(eig, 10)

What you actually want is this:

from matplotlib import pylab
[N,x] = pylab.hist(eig, 10)

Or, if you''re at the interactive prompt (but remember that it is inadvisable
to
do so in modules):

from matplotlib.pylab import *
[N,x] = hist(eig, 10)

You will probably want to review the section of the tutorial on importing
modules if you don''t understand the differences.


Is pylab part of matplotlib? I always thought it was the other way
around. I have a similar view of numpy as part of scipy. Maybe I''m
confused on the dependencies. I find it confusing in the examples
sometimes when the "bigger" package is imported (e.g. scipy) and then a
"subpackage" is also imported. Like this:

from scipi import *
from scipi import numpy

I know I''ve seen stuff like that, but I don''t get it. The dependencies
are confusing to me.

I did a search of the tutorial on ''import'' but didn''t find the answer.

-- Lou Pecora (my views are my own) REMOVE THIS to email me.


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

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