0

I was assigned to write python function that gives the histogram of data. Each histogram element H(k) corresponds to the frequency of k in the data using if and for loop statements.

The data list A=[13, 15, 16, 19, 20, 20, 21, 25, 22, 25, 30, 33, 36, 40, 33, 25, 25, 35, 35, 35, 35, 45, 46, 22, 52, 70, 16]

Anyone can help?

Rena
  • 19
  • 2
  • create a [counter](https://www.tutorialspoint.com/count-frequencies-of-all-elements-in-array-in-python) that loops the items, then [plot](https://stackoverflow.com/questions/21195179/plot-a-histogram-from-a-dictionary) the resulting dictionary as a histogram – RJ Adriaansen Dec 23 '21 at 13:32

1 Answers1

0

To keep it simple you can start from this:

from matplotlib import pyplot as plt

A=[13, 15, 16, 19, 20, 20, 21, 25, 22, 25, 30, 33, 36, 40, 33, 25, 25, 35, 35, 35, 35, 45, 46, 22, 52, 70, 16]

plt.hist(A,10)

plt.show()
Kapil Musale
  • 223
  • 1
  • 4