Learn Python

Learn Data Structure & Algorithm

Learn Numpy

Learn Pandas

Matplotlib Introduction

Matplotlib Bar Plot

Matplotlib Pie Chart

Matplotlib Hist Plot

Matplotlib Line Plot

Matplotlib Scatter Plot

Matplotlib Subplot

Matplotlib Save image

Learn Seaborn

Learn Statistics

Learn Math

Learn MATLAB

Learn Machine learning

Learn Github

Learn OpenCV

Learn Deep Learning

Learn MySQL

Learn MongoDB

Learn Web scraping

Learn Excel

Learn Power BI

Learn Tableau

Learn Docker

Learn Hadoop

Matplotlib subplot

What is subplot?

When you want to show multiple graphs on one page then you use a subplot. Suppose you have to plot two charts one line chart and the other is the pie chart. When you try to see a pie chart then you will not be able to see a line chart.
What subplot will do?
It will set the chart one by one in rows and columns. Here you have to define row and column number and also the position means in which position of row and column the graph should go.

How to create a subplot?

To create subplot write module_name.subplot(row,column,index) before each and every plot.
Suppose we write plt.subplot(2,2,1). It means maximum number of row is 2 and maximum number of column is 2. So we can say that here we can plot 4 plots and 1 means first position. Here first position means first row first column. Now If we write plt.subplot(4,2,3) then we will have 4 rows and 2 columns and 4 means second row first column. Here we can plot total 8 plots.

Input
import matplotlib.pyplot as plt
value1=[40,45,67,78,90]
value2=[55,70,81,88,100]
plt.subplot(3,1,1)
plt.plot(value1,value2,color="red",marker="o",linewidth="2.7",linestyle=":",markersize="5")
plt.title("Histogram for practice")
plt.xlabel("x axis value")
plt.ylabel("y axis value")
plt.grid(color="red",linewidth=2,linestyle=":")
plt.legend(["value1","value2"])
plt.show()

names=["python","javascript","HTML","CSS","SQL"]
users=[55,20,10,5,10]
explode_values=[0,0.3,0,0.2,0]
colors_value=["red","green","blue","gray","black"]
textproperty={"fontsize":15}
plt.subplot(3,1,2)
plt.pie(users,labels=names,explode=explode_values,colors=colors_value,
autopct="%0.2f%%",shadow=True,radius=1.3,textprops=textproperty)
plt.show()

names=["python","javascript","HTML","CSS","SQL"]
users_USA=[55,20,10,5,10]
users_UK=[50,10,5,15,20]
plt.subplot(3,1,3)
plt.bar(names,users_USA)
plt.bar(names,users_UK)
plt.grid(color="red",linewidth=2,linestyle=":")
plt.legend(["USA","UK"])
plt.show()

CodersAim is created for learning and training a self learner to become a professional from beginner. While using CodersAim, you agree to have read and accepted our terms of use, privacy policy, Contact Us

© Copyright All rights reserved www.CodersAim.com. Developed by CodersAim.