Graphs

The examples shown here use a simple library around matplotlib. Later, matplotlib can be used directly for much more control of how graphs are displayed.

The following values are some coins. The kinds of coins or amounts are pennies=1, nickes=5, dimes=10, and quarters = 15. They were added to the coinAmounts list as they were picked up.

The x and y labels are correct, but they don't mean much. There were 11 coins, so the x axis shows that there are 11 items numbered 0 to 10. The y axis is 0 to 25, so that is the coin amount. So improving the meaning of the labels gives the following.

This graph makes it easy to see that there are two coins that are 25 cents, and 1 coin that is 10 cents. How many 5 cent values are there? The number of 1 cent values is more difficult to count, because there are starting and ending points that all must be counted. For example, there is a 1 cent piece at index 1, 2 and some others.

To make it easier to count the coins, each coin can be shown as a point. Notice that the amounts are in the same place, but lines are not connecting them.

Python has an easy way to sort the values. This makes it easier to add the amounts together.

There is a different kind of graph that can show the count of each kind of coin. This graph shows that there are 5 one cent values, 2 five cent values, etc.

The "bins" are figured out automatically, but they don't work well for coins. In this case, it looks like the bins are about 2.5 wide.

The histogram works by figuring out which values go into each bin. For the following example, the bins are defined. The values between 0.5 and 1.5 will go into the second bin. Then there are zero values that are between 1.5 and 4.5 because the coin amounts jump from 1 cents to 5 cents.

More Complex Data

The first value in each pair (tuple) is the coin amount, then second value is the year it was made.

Instead of using 3 lines to get the amounts of the coins, the following line could be used.