473,395 Members | 1,386 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,395 software developers and data experts.

How to plot a histogram from an array

Dear All,

I am new to perl. I need your help with processing the grade.dat file. I have a file containing a list of students with their varying scores from different type of assignments and tests. I have calculated the final grade and need to know the score distribution in a simple histogram like this:
78 xxxxxxx
79 xxxxxxxx
80 xxxxx
81 xxx
where x indicates the number of students gaining the score that equals to the left string.
Thanks for your prompt response.

Regards,
Jang
Mar 16 '08 #1
5 4568
eWish
971 Expert 512MB
Please show us the code that you have done in tying to accomplish this on your own. Also, this sound like homework/coursework, is it?

--Kevin
Mar 16 '08 #2
Please show us the code that you have done in tying to accomplish this on your own. Also, this sound like homework/coursework, is it?

--Kevin
Yes, I've been working on my assignment (If this is not allowed, then I won't be asking questions anymore).
Well, to be frank, I haven't been able to compute the final score since I'm still trying to find a way to target a specific column. For example, the mid-test scores are at column 20 and final-test scores at 21 and I have to add them in to get the overall score of each student. Below is what I had in mind:

Expand|Select|Wrap|Line Numbers
  1. $mid = $i;
  2. for ($i = 20) {
  3.       $overall = $overall + $mid;
  4. }
  5. $final = $i;
  6. for ($i = 21) {
  7.      $overall = $overall + $final;
  8. }
Are they correct? Anyone willing to help?
Thanks.
Mar 18 '08 #3
eWish
971 Expert 512MB
Would you please show some sample data and the format of the file that the data is in?

When it comes to school work we will make suggestions, but not offer complete solutions. That way you will still learn.

--Kevin
Mar 18 '08 #4
Would you please show some sample data and the format of the file that the data is in?

When it comes to school work we will make suggestions, but not offer complete solutions. That way you will still learn.

--Kevin
00569, Cindy, 40, 40, 40 ,38, 40, 40, 20, 25, 25, 10, 8, 9, 8, 8, 7, 8, 66, 82, 92
00580, Melina, 40, 39, 38, 40, 37, 40, 25, 25, 25, 10, 9, 9, 9, 8, 9, 70, 83, 93

The data contain the ID, name, scores of projects, quizzes, exercises, mid and final terms. I have to add up all scores for every student by first counting the percentage of each element of scoring and then assign a letter grade like A, B, and etc. Then i have to display a histogram like this.

90 xxxx
91 xxx
92 x
93 x
which means four students got 90, 3 got 91 and so on.
I'd really appreciate you would give me some clue.
Thanks.
Mar 19 '08 #5
eWish
971 Expert 512MB
Expand|Select|Wrap|Line Numbers
  1. # This gets the last two elements the line.
  2. my ($mid, $final) = (split ', ')[-2,-1];
  3.  
  4. # This assumes that each line is the same fixed length.
  5. my ($mid, $final) = (split', ',)[19, 20];
Expand|Select|Wrap|Line Numbers
  1. open(my $FILE, '<', $file) || die "Can't open $file: $!\n";
  2.     while(<$FILE>) {
  3.         chomp;
  4.  
  5.             # This gets the last two elements the line.
  6.             my ($mid, $final) = (split ', ')[-2,-1];
  7.  
  8.             # Do something with $mid and $final
  9.             print "Mid: $mid\n";
  10.             print "Final: $final\n";
  11.  
  12. }
  13. close($FILE);
If you store each occurrence of the various grades in a hash you can access them like so.

Expand|Select|Wrap|Line Numbers
  1. # $keys are the grade and $values would be the number of occurrences.
  2. while (my ($keys, $values) = each %scores_count) {
  3.     print "$keys ", ('X' x $values), "\n";
  4. }
--Kevin
Mar 24 '08 #6

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...
30
by: nephish | last post by:
Hey there, i have tried about every graphing package for python i can get to work on my system. gnuplot, pychart, biggles, gdchart, etc.. (cant get matplot to work) so far, they all are working...
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...
11
by: c19h28o2 | last post by:
Hi, Guy's I know there are several posts about this, however I do not want to read them as answers are undoubtedly posted! Here is my attempt but I'm slightly stuck. I'm not looking for the...
0
by: toton | last post by:
Hi, for my project I needs a few plots to visualize the data (mostly x-y plot) . Most of the existing plotting library either copy the data and do plotting, or takes a data pointer to an 2d x-y...
2
by: Daniel Nogradi | last post by:
How does one do a histogram on only a part of an image? This is what I found in the PIL documentation about histogram( ): """ im.histogram(mask) =list Returns a histogram for those parts 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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.