Matplotlib – Make a Frequency histogram from a list with tuple elements in Python

MatplotlibPythonData Visualization

To make a frequency histogram from a list with tuple elements in Python, we can take the following steps −

  • Set the figure size and adjust the padding between and around the subplots.
  • Make a list of tuples, data.
  • Make lists of frequency and indices, after iterating the data.
  • Make a bar plot usig bar() method.
  • To display the figure, use show() method.


import matplotlib.pyplot as plt

plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True

data = [("a", 1), ("c", 3), ("d", 4), ("b", 2),
   ("e", 7), ("f", 3), ('g', 2)]
ind = []
fre = []
for item in data:
   fre.append(item[1]), fre)


It will produce the following output −

Updated on 20-Sep-2021 09:23:49