3 Replies - 78917 Views - Last Post: 11 March 2007 - 02:14 PM Rate Topic: ****- 1 Votes

#1 SK-II_Maple   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 20
  • Joined: 09-March 07

How to plot Histogram by using C++?

Posted 11 March 2007 - 07:44 AM

Do someone know how to plot the histogram by uisng the simple C++ codes?

Actually i dont have any idea to start it..so hope that you all can help to solve it...

thanks..
Is This A Good Question/Topic? 0
  • +

Replies To: How to plot Histogram by using C++?

#2 NickDMax   User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2255
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: How to plot Histogram by using C++?

Posted 11 March 2007 - 08:26 AM

Well you don't give us much to go on here. Histogram of what? What kind of plot are you looking for?

if I wanted a histogram of pixel colors in a 256 color bitmap I would create an array of 256 integers, then loop though the bitmap and add 1 to the value in my integer array which corresponded to the current color. THEN, I would find the maximum and minimum values in the array, normalize it, and then plot it onto a bitmap...

Basicly you don't give us enough to go on here. What are you trying to do? what have you tried so far?
Was This Post Helpful? 0
  • +
  • -

#3 SK-II_Maple   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 20
  • Joined: 09-March 07

Re: How to plot Histogram by using C++?

Posted 11 March 2007 - 09:23 AM

Erm...actually i really dont know how i gonna to start it..

Let said i have a set of data (in attachment) then i would like to plot the histogram (eg. in attachment) by using C++..

Then the output will show the histogram... just a simple histogram..no need involve any graphic function..just print it in the "black box" only...

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

#7 NickDMax   User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2255
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: How to plot Histogram by using C++?

Posted 11 March 2007 - 02:14 PM

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...
Was This Post Helpful? 2

Page 1 of 1