1 Replies - 5761 Views - Last Post: 20 March 2012 - 02:16 AM Rate Topic: -----

#1 juyew   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 10-March 12

How to plot Histogram

Posted 20 March 2012 - 12:42 AM

Mod Edit: Please don't reopen an ancient topic to ask another question.
Split to a new topic. See this link for the original topic.

View PostNickDMax, on 11 March 2007 - 02:14 PM, said:

Well lets say we will use text graphics so our histogram looks like this:

00-09: *
10-19: **
20-29: ***
30-39: ****
40-49: *****
50-59: ****
60-69: ***
70-79: **
80-89: *
90-99: *

We will need to create an array of 10 integers (our bins).
Next loop though the data and sorting it into our bins:
if (data =>0 && data <10) {bin[0]++; }
else if (data =>10 && data <20) {bin[1]++; }
else if (data =>20 && data <30) {bin[2]++; }
	  .
	  .
	  .
// or put it into a loop:
for (i=0; i<10;i++)
{ if ((data[j] >= 10*i) && (data[j] < 10*i+9)) {bin[i]++; } }



Then we can make a little output function to display the histogram:
cout << "00-09: ";
for (i=0;i<bin[j];i++) {cout << "*"; }



This is of course only one way to do it...


erm, how to do the bin???izzit :

int bin[10]=0;



as i going to draw a histogram for the case as attached file, which show the number of a value be generated, same way as ur teach?

This post has been edited by jimblumberg: 20 March 2012 - 07:03 AM


Is This A Good Question/Topic? 0
  • +

Replies To: How to plot Histogram

#2 Karel-Lodewijk   User is offline

  • D.I.C Addict
  • member icon

Reputation: 455
  • View blog
  • Posts: 864
  • Joined: 17-March 11

Re: How to plot Histogram

Posted 20 March 2012 - 02:16 AM

Is within C++ truly a requirement ?

If I want a histogram of some data in C++, I usually just write the values to some file (one per line). Then I'll open the file in matlab or octave and use that to make a histogram.

load filename
hist(filename, 100)



does the trick to make a histogram with a 100 bins, nice and graphical.

This is of course not the only option, gnuplot will have some similar command or even excel (you might have to put commas between the numbers for that).

This post has been edited by Karel-Lodewijk: 20 March 2012 - 02:16 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1