473,394 Members | 1,802 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Histogram-Please Help

Hello everyone,

I am trying to make a histogram for a project in my class and I really need some help. Here is the question that my instructor provided:

Create 1000 Random numbers between 0-100. Create a histogram of the values as a list. Make the bin range 10. Your book goes through a more complicated, but similar exercises.

Here is the code that I have so far:

import random
list = []
count = 0

for i in range(1000):
i = random.randrange(0, 101, 1)
print i
list = list + [i]
count = count + 1

print 'The total number of random numbers is: \t', count

Even with the help of my book I am unable to make the histogram.....can someone PLEASE help me...its driving me crazy.
Jun 24 '08 #1
1 4613
Hi,

Not really sure from you post what type of random number generator that you
need to use but just continuing on from what you were doing in your post with
'random.randrange' ... I put together this bit of code. You must have the
extra python packages 'scipy' and 'Gnuplot.py' installed ... depending on your
system?? you should be able to install these easily. Otherwise I guess you
can calculate you histogram bins yourself (should only be a few lines of code)
and you can always plot the histogram in an external package like Gnuplot
which is standard on most *nix machines.

Hope this helps you ...



Expand|Select|Wrap|Line Numbers
  1.  
  2. import random
  3. import Gnuplot
  4. import scipy
  5.  
  6. # Generate a list of random numbers
  7.  
  8. hist=[]
  9. i=0
  10. while i < 1000:
  11.     item = random.randrange(0,101,1)
  12.     hist.append(item)
  13.     i+=1
  14.  
  15. # Generate your histogram
  16.  
  17. (list,bins) = scipy.histogram(hist,bins=10)
  18.  
  19.  
  20. # Plot your histogram
  21.  
  22. plot = Gnuplot.Gnuplot(persist=1)
  23. plot('set terminal x11 1 enhanced')
  24. plot.xlabel("No. of Bins")
  25. plot.ylabel("Count")
  26. dat = Gnuplot.Data(bins,list, with="histeps")
  27. plot.plot(dat)
  28.  
  29.  
Jun 25 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Oracle3001 | last post by:
Hi All, I am trying to use JAI to build a histogram of an image i have. I have posted the code below, and the error I get at runtime. I have taken the code from the offical java examples, so I am...
1
by: bleh | last post by:
....to include a removeData(datatoremove) function, to mirror the existing addData(datatoadd) function. If anybody knows of somewhere where this has been done already, if you could point me in...
27
by: ext_u | last post by:
Ok I thought I would try to take the program one thing at a time. (If you remember my last post I am trying to make a histogram with data on the size of each word) Anways first .. I obviously...
5
by: firewoodtim | last post by:
I want to analyze a GIF file and retrieve the histogram data on the image (pixel quantity and color symbol for each color in the file.) Does anyone know how to use PHP to do this? I've looked...
12
by: KraftDiner | last post by:
Hi, I wrote a C++ class that implements an n dimensional histogram in C++, using stl maps and vectors. I want to code this up now in Python and would like some input from this group. The C++...
5
by: Enigma Curry | last post by:
I'm playing around with matplotlib for the first time. I'm trying to make a very simple histogram of values 1-6 and how many times they occur in a sequence. However, after about an hour of...
5
by: arnuld | last post by:
this is a programme that counts the "lengths" of each word and then prints that many of stars(*) on the output . it is a modified form of K&R2 exercise 1-13. the programme runs without any...
12
by: arnuld | last post by:
i was able to create a solution for a Horizontal-Histogram. i was completely unable to understand this Vertical-Histogram phenomenon. even though i have looked at the solution at this page: ...
0
by: Kurt Smith | last post by:
On Fri, Jul 25, 2008 at 5:02 PM, aditya shukla <adityashukla1983@gmail.comwrote: the 'bins' argument to pylab.hist() is supposed to be an integer or a list of the bins' lower edges. The default...
15
by: zaturn | last post by:
To student: The this the new assignment. Ex7 VERTICAL HISTOGRAM
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.