- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to plot collections.Counter histogram using Matplotlib?
63 Lectures 6 hours
To plot a histogram, with collections.Counter, we can use bar() method. In bar() method, we can use collections.counter() to get the frequency for each element. Put the elements and their frequency as height.
- Set the figure size and adjust the padding between and around the subplots.
- Make a list of a data points.
- Get the dictionary, d, using collections.Counter().
- Make bar plot with d.keys() and d.values().
- To display the figure, use show() method.
import collections from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True data = [0, 1, 2, 4, 1, 3, 0, 4, 1, 4, 3, 5, 6, 5, 2] d = collections.Counter(data) plt.bar(d.keys(), d.values()) plt.show()
- How to plot hexbin histogram in Matplotlib?
- How to plot a 2D histogram in Matplotlib?
- How to center labels in a Matplotlib histogram plot?
- How to plot a histogram using Matplotlib in Python with a list of data?
- How to plot a line graph from histogram data in Matplotlib?
- Python - Plot a Histogram for Pandas Dataframe with Matplotlib?
- Plot a histogram with Y-axis as percentage in Matplotlib
- Plot a histogram with colors taken from colormap in Matplotlib
- How to save a histogram plot in Python?
- How to plot a wav file using Matplotlib?
- How to plot vectors in Python using Matplotlib?
- How to plot 3D graphs using Python Matplotlib?
- How to plot MFCC in Python using Matplotlib?
- How to plot events on time using Matplotlib?
- How to plot 2d FEM results using matplotlib?