473,839 Members | 1,439 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Plotting histograms

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

Oct 17 '06 #1
14 6760
am***********@g mail.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.pyla b 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

Oct 17 '06 #2
On 16 Oct 2006 20:49:10 -0700, am***********@g mail.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
Oct 17 '06 #3
In article <ma************ *************** ***********@pyt hon.org>,
Robert Kern <ro*********@gm ail.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.pyla b 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.
Oct 17 '06 #4
Lou Pecora wrote:
In article <ma************ *************** ***********@pyt hon.org>,
Robert Kern <ro*********@gm ail.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.pyla b 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?
Yes.
I always thought it was the other way
around. I have a similar view of numpy as part of scipy.
It is not.
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
The latter would definitely be bad form if it worked. numpy is a package all by
itself and should be imported by itself.
I know I've seen stuff like that, but I don't get it. The dependencies
are confusing to me.
pylab is a module provided with matplotlib that exposes a nice interface for
certain purposes. Somewhat confusingly, it is provided in two places, as its own
module:

import pylab

and as a submodule in the matplotlib package:

from matplotlib import pylab

Both do the same thing. You get to ask John Hunter if you want to know the whys
and wherefores.

numpy is a package all by itself. scipy is a package all by itself although it
depends on numpy being installed. You cannot import numpy from scipy. The
dependency of scipy on numpy does *not* entail that scipy will provide numpy in
its namespace.

Sometimes packages/modules are sloppy and accidentally expose the modules that
they import. For example, if you had a module foo.py like this:

import bar
def dostuff():
pass

then foo.py depends on bar.py. One *could* also do this:

from foo import bar

However, as I said, this would be bad form. It is an accident that the bar
module is exposed there. It should not be imported from the foo module.

Naturally, there are exceptions. Sometimes some other module is deliberately
imported and intended to be exposed in that place. Hopefully, there is a comment
to that effect explaining that it was intentional.
I did a search of the tutorial on 'import' but didn't find the answer.
It certainly doesn't answer your questions, but it should answer the OP's if my
presumptions are correct. Importing a module like so:

import mymodule
from mypackage import myothermodule

does not take all of symbols in mymodule and myothermodule and place them in the
current namespace.

http://docs.python.org/tut/node8.html

--
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

Oct 17 '06 #5
In article <ma************ *************** ***********@pyt hon.org>,
Robert Kern <ro*********@gm ail.comwrote:

Is pylab part of matplotlib?

Yes.
I always thought it was the other way
around. I have a similar view of numpy as part of scipy.

It is not.
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

The latter would definitely be bad form if it worked. numpy is a package all
by
itself and should be imported by itself.
I know I've seen stuff like that, but I don't get it. The dependencies
are confusing to me.

pylab is a module provided with matplotlib that exposes a nice interface for
certain purposes. Somewhat confusingly, it is provided in two places, as its
own
module:

import pylab

and as a submodule in the matplotlib package:

from matplotlib import pylab

Both do the same thing. You get to ask John Hunter if you want to know the
whys
and wherefores.
[cut]

Got it. Thanks, Robert, for the quick tutorial. It's a lot clearer now.

Now, to just remember it.

By the way, from what I have seen so far they are beautiful packages.

The only problem I'm having is getting ipython to run. Not installed in
/usr/local/bin (although all other IPython files look to be installed in
/Library/Framewaorks/python...blah/site-packages). I'm still searching
the web sites for answers.

But all else seems to run pretty smoothly.

-- Lou Pecora (my views are my own) REMOVE THIS to email me.
Oct 17 '06 #6
Lou Pecora wrote:
The only problem I'm having is getting ipython to run. Not installed in
/usr/local/bin (although all other IPython files look to be installed in
/Library/Framewaorks/python...blah/site-packages). I'm still searching
the web sites for answers.
Create a file ~/.pydistutils.cf g with the following section (unindented):

[install]
install-scripts=/usr/local/bin

Now install ipython again, and the ipython script should be installed to
/usr/local/bin/. You may need to be root to do so.

For more information on that configuration file:

http://docs.python.org/inst/config-syntax.html

--
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

Oct 17 '06 #7
In article <ma************ *************** ***********@pyt hon.org>,
Robert Kern <ro*********@gm ail.comwrote:
Lou Pecora wrote:
The only problem I'm having is getting ipython to run. Not installed in
/usr/local/bin (although all other IPython files look to be installed in
/Library/Framewaorks/python..blah/site-packages). I'm still searching
the web sites for answers.

Create a file ~/.pydistutils.cf g with the following section (unindented):

[install]
install-scripts=/usr/local/bin

Now install ipython again, and the ipython script should be installed to
/usr/local/bin/. You may need to be root to do so.

For more information on that configuration file:

http://docs.python.org/inst/config-syntax.html
I assume you are telling me to install ipython from a tar distribution
using setup etc. I originally installed it from the SciPy Super Pack
which apparently put in the site packages, but neglected the script in
/usr/local/bin. Sound right?

On the ipython web site for MacOS X it says to do the following after
the install using python setup.py etc. in the extracted directories,

python*setup.py *install_script s*--install-dir=/usr/local/bin

Is that what you are suggesting with the pydistutils.cfg ?

Sorry, if I'm dense on this, but I only partially grok the command line
install. Thanks for any help.

-- Lou Pecora (my views are my own) REMOVE THIS to email me.
Oct 17 '06 #8
Lou Pecora wrote:
In article <ma************ *************** ***********@pyt hon.org>,
Robert Kern <ro*********@gm ail.comwrote:
>Lou Pecora wrote:
>>The only problem I'm having is getting ipython to run. Not installed in
/usr/local/bin (although all other IPython files look to be installed in
/Library/Framewaorks/python..blah/site-packages). I'm still searching
the web sites for answers.
Create a file ~/.pydistutils.cf g with the following section (unindented):

[install]
install-scripts=/usr/local/bin

Now install ipython again, and the ipython script should be installed to
/usr/local/bin/. You may need to be root to do so.

For more information on that configuration file:

http://docs.python.org/inst/config-syntax.html

I assume you are telling me to install ipython from a tar distribution
using setup etc. I originally installed it from the SciPy Super Pack
which apparently put in the site packages, but neglected the script in
/usr/local/bin. Sound right?
Indeed. The SuperPack is broken and does not contain the ipython script. It also
puts the documentation in the wrong place.

ipython is a pure-Python package and easy to install from source.
On the ipython web site for MacOS X it says to do the following after
the install using python setup.py etc. in the extracted directories,

python�setup. py�install_sc ripts�--install-dir=/usr/local/bin

Is that what you are suggesting with the pydistutils.cfg ?
Yes, it does the same thing, only it will apply to all packages (probably what
you want) and you only have to do it once instead of remembering to do it every
time.

--
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

Oct 17 '06 #9
In article <ma************ *************** ***********@pyt hon.org>,
Robert Kern <ro*********@gm ail.comwrote:

I assume you are telling me to install ipython from a tar distribution
using setup etc. I originally installed it from the SciPy Super Pack
which apparently put in the site packages, but neglected the script in
/usr/local/bin. Sound right?

Indeed. The SuperPack is broken and does not contain the ipython script. It
also
puts the documentation in the wrong place.

ipython is a pure-Python package and easy to install from source.
Bingo! Now it is clear why I am having problems. I will install from
source as you suggest. Looks pretty straightforward .

Sorry to hear the SuperPack is broken. It's a nice idea for us users.
Other packages seem to be working fine. Any chance it will be fixed?
On the ipython web site for MacOS X it says to do the following after
the install using python setup.py etc. in the extracted directories,

python?setup.py ?install_script s?--install-dir=/usr/local/bin

Is that what you are suggesting with the pydistutils.cfg ?

Yes, it does the same thing, only it will apply to all packages (probably
what
you want) and you only have to do it once instead of remembering to do it
every
time.
Robert, thanks for the insight and the solution.

-- Lou Pecora (my views are my own) REMOVE THIS to email me.
Oct 17 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2013
by: srijit | last post by:
Hi, I am looking for a good plotting package (preferably with 3D plotting capabilities) based on Python 2.3 (Windows 98). Unfortunately Dislin does not exist for Python 2.3. I look forward to suggestions from members. Regards, Srijit
3
5062
by: Erik Lechak | last post by:
Hello All, I am creating a visual programming environment for python (similar to Matlab's simulink, but for python). For several reasons I have decided not to go with OGL. I am writing a wxOGL replacement library for wxPython. My first thought was to create an exact drop in replacement for OGL, but the more I look at the OGL api the more I hesitate to do it.
6
4465
by: Gerrit Holl | last post by:
Hi, I have a dictionairy containing DateTime objects as keys and integers as values. What would be the easiest way to create a simple plot of these, with a number axis versus a time axis? What library is the most suitable for this? 'plot' on parnassus yields 18 hits, but since I have zero experience, I don't know where to start. What makes it difficult is that I have a time axis instead of a simple integer x-axis. Gnuplot doesn't seem...
9
12804
by: Dr. Colombes | last post by:
What is the easiest way to generate some plots and graphs in Python ? Specifically interested in simple histograms and scatter plots with circles and regression lines. Thanks for your suggestions.
7
2829
by: Rolf Wester | last post by:
Hi, I have a Python console application that is intended to be used interactively and I have to add plotting capabilities (multiple XY plots and if possible 2D-surface plots). I'm loocking for a reasonably fast plotting library (not GPL'ed, needs not be for free) that can be used under Windows. An alternative would also be a standalone application that can be controlled via TCP/IP from my Python application. I tried matplotlib but this...
0
2198
by: lnd | last post by:
A few question regarding PostgreSQL handling of queries: - Is each query submitted parsed and planned even if it is identical to a query submitted before? For example, 10 queries "select * from animals where id=:b1" with possibly different bind variable :b1 values will be fully processed (parsed and planned) 10 times? - does it make difference for postgreSQL performance if bind variables are used or not?
16
5038
by: simpleeshelbee | last post by:
Hey all, This is my first post. I am really hoping that someone out there has a solution to my C++ coding problem... This is my code and what I have to do... I think it is rows of 1 - 10 and then back ******************************************************************************************** //These histograms are supposed to print beside eachother like this:
1
7075
by: T. Crane | last post by:
Hi, I am looking for a good plotting library. I intend to do 3D surface plots, 2D contour, 3D waterfall, etc. Right now I have access to National Instruments' Measurement Studio, and it's supposed to provide some plotting classes, but I've never used it. Does anyone have any experience with NI's Meas. Studio? Can someone suggest a good plotting library that I might want to use instead of Meas. Studio? Is there a community standard?
0
1936
by: Helmut Michels | last post by:
Dear C/C++ programmers, I am pleased to announce version 9.4 of the data plotting software DISLIN. DISLIN is a high-level and easy to use plotting library for displaying data as curves, bar graphs, pie charts, 3D-colour plots, surfaces, contours and maps. Several output formats are supported such as X11, VGA, PostScript, PDF, CGM, WMF, HPGL, TIFF, GIF, PNG, BMP and SVG.
0
9856
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
10914
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10597
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9434
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7834
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7022
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5872
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3136
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.