0 Bewertungen0% fanden dieses Dokument nützlich (0 Abstimmungen)
13 Ansichten8 Seiten
The purpose of this project was to demonstrate our group’s understanding of how to do a computational using python. More specifically, our project demonstrates how to make a histogram using the matplotlib library, and alo shows multiple modifications which you can make to your histogram. The modifications we will show in our examples are how to change the color of the bars displayed in the histogram, how to set the number of bins on the histogram, changing the edges of the histogram, and changing the range displayed on the histogram. Lastly we demonstrated how to make our code use an array of data which it read from a file rather than the original data listen.
The purpose of this project was to demonstrate our group’s understanding of how to do a computational using python. More specifically, our project demonstrates how to make a histogram using the matplotlib library, and alo shows multiple modifications which you can make to your histogram. The modifications we will show in our examples are how to change the color of the bars displayed in the histogram, how to set the number of bins on the histogram, changing the edges of the histogram, and changing the range displayed on the histogram. Lastly we demonstrated how to make our code use an array of data which it read from a file rather than the original data listen.
The purpose of this project was to demonstrate our group’s understanding of how to do a computational using python. More specifically, our project demonstrates how to make a histogram using the matplotlib library, and alo shows multiple modifications which you can make to your histogram. The modifications we will show in our examples are how to change the color of the bars displayed in the histogram, how to set the number of bins on the histogram, changing the edges of the histogram, and changing the range displayed on the histogram. Lastly we demonstrated how to make our code use an array of data which it read from a file rather than the original data listen.
Introduction The purpose of this project was to demonstrate our groups understanding of how to do a computational using python. More specifically, our project demonstrates how to make a histogram using the matplotlib library, and alo shows multiple modifications which you can make to your histogram. The modifications we will show in our examples are how to change the color of the bars displayed in the histogram, how to set the number of bins on the histogram, changing the edges of the histogram, and changing the range displayed on the histogram. Lastly we demonstrated how to make our code use an array of data which it read from a file rather than the original data listen.
The first example shown above shows how to change the color of the bars displayed on the histogram. We did this by changing the face color equal to y which codes for yellow bars. The bars could also be set to: r=red g=green b=blue k=black c=cyan m=magenta y=yellow w=white
The second example shown above shows how to set the bin number on the histogram. When making a histogram you are essentially making a bar chart that shows how many data points fit within a certain range. The amount of ranges you have is technically the amount of bins you need. For instance if you were counting the number of people in a building per hour. You might plot it as 10-15, 16-20, 21-25, and 26-30. In this case your bin width would be 5, and you would want to set the bin number at least 4 to display this amount of bars. In the example above the bin number is set to 23 (hist(t, bins=23)). Although there are only 13 bars shown there is room for 23 to be shown and therefore it is indeed possible for bins to be empty. It is very important to choose an appropriate bin number in order for the histogram to show how the events are distributed well.
The example above shows how to change the edges of the histogram. The hist function returns the number of events in each bin, the edges of the bins, and the patches of the histogram. These values can bet set by providing three variable names for them using: events, edges, patches, =hist(t).
The example shown above shows how to change the range displayed on the histogram. In this example we set the range to (t, range=(-1.0,12.0)), and as you see on the x axis this range is displayed. It is important to set an appropriate range for your data so all of it can be displayed. In this example note that the array of data provided all fit within this given range.
The last example shows how to make the code read from a file rather than the array of data it was using before. The file we used is called list.txt as shown above. The list read from the file is shown by the part of the code which saying (print(list)) and the numbers included in our file are shown on the output screen shot. This could be very useful for creating a histogram on an arrangement of data which already exists, as you could just save this data to a file and use this same code to pull the data from that given file.
Conclusion After completing this project our group now has a better understanding of how to do a computational using Python. This project helped to show the various ways the use of the matplotlib library can be useful in evaluating data. The use of bins to group data will be very helpful in the future for instances when comparing measurements made numerous times. Our group was very impressed by the different modifications that can be made to a histogram using the functions from pylab import*. We also found the last example to be very useful as it allows you to apply this code to different data sets without having to manually create an array of data. We did find that is important to be prcised in determining values such as the bin number and edges as setting these to an inappropriate setting can really alter the distribution displayed on the histogram.