• Offers
    • RegisterLogin
      • Learn More
    PythonPoint.netPythonPoint.net
    • Offers
    • RegisterLogin
      • Learn More

      Python

      SKILL IS IMPORTANT THAN DEGREE Be skill full.
      • Home
      • Blog
      • Python
      • How to plot Histogram in Python

      How to plot Histogram in Python

      • Posted by Python Point Team
      • Categories Python
      • Date November 29, 2020
      • Comments 0 comment
      how to plot histogram in python

      In this article, we will see how to plot histogram in Python using Matplotlib.

      #1 : Install Matplotlib

      If you don’t have Matplotlib installed in your system, use following command to do so.

      pip install matplotlib

      #2 : Collect the data for the histogram

      For example, let’s say that you have the following data about the age of 100 individuals:

      Age
      1,1,2,3,3,5,7,8,9,10,
      10,11,11,13,13,15,16,17,18,18,
      18,19,20,21,21,23,23,24,25,25,
      25,25,26,26,26,27,27,27,27,27,
      29,30,30,31,33,34,34,34,35,36,
      36,37,37,38,38,38,40,41,41,42,
      43,44,45,45,46,47,48,48,49,50,
      51,52,53,54,55,55,55,57,58,60,
      61,62,64,65,66,68,70,71,72,74,
      75,77,81,83,84,85,89,90,90,99

      #3: Determine the number of bins

      Next determine the number of bins to be used for the histogram.

      For ease of understanding, let’s set the number of bins to 10.

      #4 : Plot the histogram in Python using matplotlib

      import matplotlib.pyplot as plt
      
      x = [1,1,2,3,3,5,7,8,9,10,
           10,11,11,13,13,15,16,17,18,18,
           18,19,20,21,21,23,23,24,25,25,
           25,25,26,26,26,27,27,27,27,27,
           29,30,30,31,33,34,34,34,35,36,
           36,37,37,38,38,38,40,41,41,42,
           43,44,45,45,46,47,48,48,49,50,
           51,52,53,54,55,55,55,57,58,60,
           61,62,64,65,66,68,70,71,72,74,
           75,77,81,83,84,85,89,90,90,99]
      
      plt.hist(x, bins=10)
      plt.show()

      Output:

      histogram
      • Share:
      author avatar
      Python Point Team

      Previous post

      How to remove special characters from a string in Python
      November 29, 2020

      Next post

      What is indentation error in Python
      November 29, 2020

      You may also like

      Introduction to Transfer Learning with Python: A Practical Guide
      31 December, 2022

      Introduction: Definition of transfer learning Overview of how transfer learning works in the context of machine learning Why transfer learning is useful and important Section 1: Transfer learning in Python with Keras In this section, we will explore how to …

      How to Check Type in Python
      31 December, 2022

      In this article, we will learn to check type in Python. The built-in function type() can be used to check the type of data in Python.

      How to make web crawler in python?
      31 December, 2022

      A web crawler is a systematic, well-defined process of extracting specific data about a topic. We have a library named as scrapy which helps in making web crawler. We can install scrapy by the following command:- Now we can easily …

      Subscribe
      Login
      Notify of
      Please login to comment
      0 Discussion
      Inline Feedbacks
      View all comments

      Latest Courses

      (Hindi) Ways to earn minimum 1 Lakh Per month as Programmer

      (Hindi) Ways to earn minimum 1 Lakh Per month as Programmer

      ₹10,000
      (HINDI) Full Stack Web Development In Python 3.8 And Django 3.1

      (HINDI) Full Stack Web Development In Python 3.8 And Django 3.1

      ₹25,000 ₹2,500

      Latest Posts

      • Introduction to Transfer Learning with Python: A Practical Guide
      • How to Check Type in Python
      • How to make web crawler in python?
      • Why was the language called “python”?
      • Why Python is so Popular
      Contact
      •   support@pythonpoint.com

      We get you the best Python Courses and Blogs aiming to provide skill.

      We Believe Skill is much more important than a Degree

      Company
      • About Us
      • Blog
      • Offers
      • Contact
      Useful Links
      • Courses
      Support
      • Need Support

      © 2020 ALL RIGHTS RESERVED​ PYTHONPOINT.NET

      PythonPoint

      • Terms of Use
      • Refund Policy
      • Privacy Policy

      Login with your site account

      Lost your password?

      Not a member yet? Register now

      Register a new account

      Are you a member? Login now

      wpDiscuz