Different plotting using pandas and matplotlib Last Updated : 12 May, 2021 Comments Improve Suggest changes 1 Likes Like Report We have different types of plots in matplotlib library which can help us to make a suitable graph as you needed. As per the given data, we can make a lot of graph and with the help of pandas, we can create a dataframe before doing plotting of data. Let's discuss the different types of plot in matplotlib by using Pandas. Use these commands to install matplotlib, pandas and numpy: pip install matplotlib pip install pandas pip install numpy Types of Plots:Basic plotting: In this basic plot we can use the randomly generated data to plot graph using series and matplotlib. Python3 # import libraries import matplotlib.pyplot as plt import pandas as pd import numpy as np ts = pd.Series(np.random.randn(1000), index = pd.date_range( '1/1/2000', periods = 1000)) ts = ts.cumsum() ts.plot() plt.show() Output: Plot of different data: Using more than one list of data in a plot. Python3 # importing libraries import matplotlib.pyplot as plt import pandas as pd import numpy as np ts = pd.Series(np.random.randn(1000), index = pd.date_range( '1/1/2000', periods = 1000)) df = pd.DataFrame(np.random.randn(1000, 4), index = ts.index, columns = list('ABCD')) df = df.cumsum() plt.figure() df.plot() plt.show() Output: Plot on given axis: We can explicitly define the name of axis and plot the data on the basis of this axis. Python3 # importing libraries import matplotlib.pyplot as plt import pandas as pd import numpy as np ts = pd.Series(np.random.randn(1000), index = pd.date_range( '1/1/2000', periods = 1000)) df = pd.DataFrame(np.random.randn(1000, 4), index = ts.index, columns = list('ABCD')) df3 = pd.DataFrame(np.random.randn(1000, 2), columns =['B', 'C']).cumsum() df3['A'] = pd.Series(list(range(len(df)))) df3.plot(x ='A', y ='B') plt.show() Output: Bar plot using matplotlib: Find different types of bar plot to clearly understand the behaviour of given data. Python3 # importing libraries import matplotlib.pyplot as plt import pandas as pd import numpy as np ts = pd.Series(np.random.randn(1000), index = pd.date_range( '1/1/2000', periods = 1000)) df = pd.DataFrame(np.random.randn(1000, 4), index = ts.index, columns = list('ABCD')) df3 = pd.DataFrame(np.random.randn(1000, 2), columns =['B', 'C']).cumsum() df3['A'] = pd.Series(list(range(len(df)))) df3.iloc[5].plot.bar() plt.axhline(0, color ='k') plt.show() Output: Histograms: Python3 # importing libraries import matplotlib.pyplot as plt import pandas as pd import numpy as np df4 = pd.DataFrame({'a': np.random.randn(1000) + 1, 'b': np.random.randn(1000), 'c': np.random.randn(1000) - 1}, columns =['a', 'b', 'c']) plt.figure() df4.plot.hist(alpha = 0.5) plt.show() Output: Box plot using Series and matplotlib: Use box to plot the data of dataframe. Python3 # importing libraries import matplotlib.pyplot as plt import pandas as pd import numpy as np df = pd.DataFrame(np.random.rand(10, 5), columns =['A', 'B', 'C', 'D', 'E']) df.plot.box() plt.show() Output: Density plot: Python3 # importing libraries import matplotlib.pyplot as plt import pandas as pd import numpy as np df = pd.DataFrame(np.random.rand(10, 5), columns =['A', 'B', 'C', 'D', 'E']) ser = pd.Series(np.random.randn(1000)) ser.plot.kde() plt.show() Output: Area plot using matplotlib: Python3 # importing libraries import matplotlib.pyplot as plt import pandas as pd import numpy as np df = pd.DataFrame(np.random.rand(10, 5), columns =['A', 'B', 'C', 'D', 'E']) df.plot.area() plt.show() Output: Scatter plot: Python3 # importing libraries import matplotlib.pyplot as plt import pandas as pd import numpy as np df = pd.DataFrame(np.random.rand(500, 4), columns =['a', 'b', 'c', 'd']) df.plot.scatter(x ='a', y ='b') plt.show() Output: Hexagonal Bin Plot: Python3 # importing libraries import matplotlib.pyplot as plt import pandas as pd import numpy as np df = pd.DataFrame(np.random.randn(1000, 2), columns =['a', 'b']) df['a'] = df['a'] + np.arrange(1000) df.plot.hexbin(x ='a', y ='b', gridsize = 25) plt.show() Output: Pie plot: Python3 # importing libraries import matplotlib.pyplot as plt import pandas as pd import numpy as np series = pd.Series(3 * np.random.rand(4), index =['a', 'b', 'c', 'd'], name ='series') series.plot.pie(figsize =(4, 4)) plt.show() Output: Create Quiz Comment J jitender_1998 Follow 1 Improve J jitender_1998 Follow 1 Improve Article Tags : Python Python pandas-plotting Python-matplotlib Explore Python FundamentalsPython Introduction 2 min read Input and Output in Python 4 min read Python Variables 4 min read Python Operators 4 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 5 min read Python Functions 5 min read Recursion in Python 4 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 4 min read Python Tuples 4 min read Python Dictionary 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 5 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 3 min read Python MySQL 9 min read Python Packages 10 min read Python Modules 3 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 4 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 3 min read StatsModel Library - Tutorial 3 min read Learning Model Building in Scikit-learn 6 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 6 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 5 min read Build a REST API using Flask - Python 3 min read Building a Simple API with Django REST Framework 3 min read Python PracticePython Quiz 1 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like