• 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

      “not in” belongs to which type of operator in python?
      29 December, 2020

      “not in” belongs to the membership operator in python. Membership operator have two operators “in” and “not in”. They are used to test whether a value or variable is found in a sequence (string, list, tuple, set and dictionary). e.g., …

      What is the difference between Python 2 and 3
      8 December, 2020

      Python 2 and 3 got many differences between them. In this article, we will go through some important differences between them. While comparing these two, it is pretty clear that python 3 is much better than 2. Python 2 is …

      How To Check If A List Is Empty In Python
      7 December, 2020

      In this article, we will see how to check if a list is empty or not. A list is said to be empty when there are no elements in the list. Method 1: Output: Method 2: Output:

      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

      • How to get access to the course after purchase?
      • “not in” belongs to which type of operator in python?
      • What is the difference between Python 2 and 3
      • How To Check If A List Is Empty In Python
      • How to Change Line in Python
      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