Pandas - Plotting Histogram from pandas Dataframes - onlinetutorialspoint

PROGRAMMINGJava ExamplesC Examples
Java Examples
C Examples
C Tutorials
aws
JAVAEXCEPTIONSCOLLECTIONSSWINGJDBC
EXCEPTIONS
COLLECTIONS
SWING
JDBC
JAVA 8
SPRING
SPRING BOOT
HIBERNATE
PYTHON
PHP
JQUERY
PROGRAMMINGJava ExamplesC Examples
Java Examples
C Examples
C Tutorials
aws
In this tutorial, we will learn about how to plot Histograms using the Pandas library.
Pandas library provides us with a way to plot different kinds of charts out of the data frames that are easy to understand and get insights about the data. Pandas library uses the matplotlib as default backend which is the most popular plotting module in python.
Histograms are a way to visualize the distribution of the data. This further tells us about how we can perform specific operations to get better and accurate insights from the data.
The first step is to import the required libraries and load the data that we will be working upon. For this tutorial, we will be using the popular Pima Indians Diabetes Database. See the code below to execute these steps. All the steps are performed in Jupyter Notebooks.
import pandas as pd
data = pd.read_csv("diabetes.csv")
data.head()
Output:
Below is the code to get the histograms of all columns of data as subplots of a single plot. We can achieve this by using the hist() method on a pandas data-frame. Also, We have set the total figure size as 10×10 and bins=10 which will divide the scale of a plot into the specified number of bins for better visualization.
data.hist(figsize=(10,10),bins=10)
Output:
We have the flexibility to set some label size and rotation attributes for the plot that we are plotting which are described below.
xlabelsize – The size of the x-axis labels in integer.
ylabelsize – The size of the y-axis labels in integer.
xrot – The clockwise rotation that is to be done on the labels on the x-axis.
yrot – The clockwise rotation that is to be done on the labels on the y-axis.
color = The colour of the plot.
See the code below to see the implementation of  attributes defined above
data.hist(column="Glucose", figsize=(8,8), 
 xlabelsize=20, ylabelsize=20,
 xrot=45, bins=5, color='orange')
Output:
We can also plot histograms of multiple columns inside a single plot by using the plot wrapper around the hist() method. Look at the code below to achieve this.
data1 = data[['BloodPressure','BMI']]
ax = data1.plot.hist(alpha=0.5, figsize=(10,10),bins=10, title = "BP VS BMI")
Output:
So, We have learned how to plot histograms out of data-frames by using only the Pandas library and matplotlib as backend. If you have any doubt, feel free to ask in the comment section below.
Pandas to_csv – Pandas Save Dataframe to CSV file
How to draw shapes using Graphics
Pandas read_excel – Read Excel files in Pandas
Happy Learning 🙂

Pandas to_excel – Pandas Save Dataframe to Excel File
Pandas read_excel – Read Excel files in Pandas
Pandas to_csv – Pandas Save Dataframe to CSV file
Pandas read_csv – Read CSV file in Pandas and prepare Dataframe
How to split Numpy Arrays ?
Different ways to use Lambdas in Python
How to push docker image to docker hub ?
What are Python default function parameters ?
Implementing Stack in Python
Python raw_input read input from keyboard
Indexing in NumPy Arrays
How to sort python dictionary by key ?
How to do Multiprocessing in Python
How to access for loop index in Python
Python Decorators – Classes and Functions

Pandas to_excel – Pandas Save Dataframe to Excel File
Pandas read_excel – Read Excel files in Pandas
Pandas to_csv – Pandas Save Dataframe to CSV file
Pandas read_csv – Read CSV file in Pandas and prepare Dataframe
How to split Numpy Arrays ?
Different ways to use Lambdas in Python
How to push docker image to docker hub ?
What are Python default function parameters ?
Implementing Stack in Python
Python raw_input read input from keyboard
Indexing in NumPy Arrays
How to sort python dictionary by key ?
How to do Multiprocessing in Python
How to access for loop index in Python
Python Decorators – Classes and Functions
 


Δ
 Python – Introduction
 Python – Features
 Python – Install on Windows
 Python – Modes of Program
 Python – Number System
 Python – Identifiers
 Python – Operators
 Python – Ternary Operator
 Python – Command Line Arguments
 Python – Keywords
 Python – Data Types
 Python – Upgrade Python PIP
 Python – Virtual Environment
 Pyhton – Type Casting
 Python – String to Int
 Python – Conditional Statements
 Python – if statement
 Python – *args and **kwargs
 Python – Date Formatting
 Python – Read input from keyboard
 Python – raw_input
 Python – List In Depth
 Python – List Comprehension
 Python – Set in Depth
 Python – Dictionary in Depth
 Python – Tuple in Depth
 Python – Stack Datastructure
 Python – Classes and Objects
 Python – Constructors
 Python – Object Introspection
 Python – Inheritance
 Python – Decorators
 Python – Serialization with Pickle
 Python – Exceptions Handling
 Python – User defined Exceptions
 Python – Multiprocessing
 Python – Default function parameters
 Python – Lambdas Functions
 Python – NumPy Library
 Python – MySQL Connector
 Python – MySQL Create Database
 Python – MySQL Read Data
 Python – MySQL Insert Data
 Python – MySQL Update Records
 Python – MySQL Delete Records
 Python – String Case Conversion
 Howto – Find biggest of 2 numbers
 Howto – Remove duplicates from List
 Howto – Convert any Number to Binary
 Howto  – Merge two Lists
 Howto – Merge two dicts
 Howto – Get Characters Count in a File
 Howto – Get Words Count in a File
 Howto – Remove Spaces from String
 Howto –  Read Env variables
 Howto – Read a text File
 Howto – Read a JSON File
 Howto –  Read Config.ini files
 Howto – Iterate Dictionary
 Howto – Convert List Of Objects to CSV
 Howto – Merge two dict in Python
 Howto – create Zip File
 Howto – Get OS info
 Howto – Get size of Directory
 Howto – Check whether a file exists
 Howto –  Remove key from dictionary
 Howto – Sort Objects
 Howto – Create or Delete Directories
 Howto – Read CSV File
 Howto – Create Python Iterable class
 Howto – Access for loop index
 Howto – Clear all elements from List
 Howto – Remove empty lists from a List
 Howto – Remove special characters from String
 Howto – Sort dictionary by key
 Howto – Filter a list