Matplotlib Course For Beginners with Projects
In this course we are going to learn how to plot various graph in matplotlib.pyplot using python
Assumption:
Simple Test base on Matplotlib
Plot a Circle in Python
- You are using Jupyter Notebook
- You already have installed all dependencies used in this course (now by default all the dependecies are installed just in case if it not installed type pip install matplotlib in jupyter cell and run [note first try to run the code if its not work then try to install it]).
- You have basic knowledge of python
- Project list below (Mostly 2d and 3d project related to mechanical eginnering )
- Simple Graph Plottingimport matplotlib.pyplot as pltx = [1,5,6,7,8]y = [8,4,5,2,3]plt.plot(x,y)
- MultiLine Plotsimport matplotlib.pyplot as pltx = [1,2,3,4]y = [9,8,7,4]x1 = [4,5,6,7]y1 = [9,6,3,4]plt.plot(x,y,x1,y1)
- Grid , Axis and adding Labelsimport matplotlib.pyplot as pltx = [1,5,6,7,8]y = [8,4,5,2,3]plt.plot(x,y)plt.grid(True)import matplotlib.pyplot as pltx = [1,5,6,7,8]y = [8,4,5,2,3]plt.plot(x,y)plt.grid(True)plt.axis([-1,10,0,15])import matplotlib.pyplot as pltx = [1,5,6,7,8]y = [8,4,5,2,3]plt.plot(x,y)plt.xlabel("x-axis")plt.ylabel("y-axis")plt.title("Simple Graph")plt.grid(True)plt.axis([-1,10,0,15])
- Legend import matplotlib.pyplot as pltimport numpy as npt = np.linspace(1,10,10)plt.plot(t,t**2,label="square")plt.plot(t,t,label="linear")plt.legend()
- Styling in Graphimport matplotlib.pyplot as pltimport numpy as npt = np.linspace(1,10,10)plt.plot(t,t**2,'#E7429B',label="square")plt.plot(t,t,'b',label="linear")plt.legend()import matplotlib.pyplot as pltimport numpy as npt = np.linspace(1,10,10)plt.plot(t,t**2,'--',label="square")plt.plot(t,t,'-.',label="linear")plt.legend()
- Scatter Plotimport matplotlib.pyplot as pltimport numpy as npN = 100colors = np.random.rand(N)x = np.random.rand(N)y = np.random.rand(N)scale = (10*x*y)plt.scatter(x,y, s= scale , c = colors)
- Pie Chartimport matplotlib.pyplot as pltx = [20,30,50,60]y = ["milk","fish","cake","chips"]plt.pie(x,labels=y)import matplotlib.pyplot as pltx = [20,30,50,60]y = ["milk","fish","cake","chips"]explode = [0,0,0.3,0]plt.pie(x,labels=y ,explode = explode)
Simple Test base on Matplotlib
simple Sin Graph plotting
import matplotlib.pyplot as pltimport numpy as npplt.figure(figsize=(10,10))t = np.linspace(0,360,360)x = np.sin(np.radians(t))plt.grid('on')plt.plot(t,x)
Plot a Circle in Pythonimport matplotlib.pyplot as plt
import numpy as np
plt.figure(figsize=(10,10))
t = np.linspace(0,360,360)
x = np.sin(np.radians(t))
plt.grid('on')
plt.plot(t,x)
import matplotlib.pyplot as plt
import numpy as np
plt.figure(figsize=(10,10))
t = np.linspace(0,360,360) # theta
r = 10 # radius
x = r*np.sin(np.radians(t))
y = r*np.cos(np.radians(t))
plt.xlabel('x-axis')
plt.ylabel('y-axis')
plt.title('Circle ')
plt.grid('on')
plt.plot(x,y)
plt.axis('equal')
Simple Spiral Graph Plotting in Python matplotlib.pyplot
import matplotlib.pyplot as plt
import numpy as np
plt.figure(figsize=(10,10))
t = np.linspace(0,1080,360) # theta
r = np.linspace(0,1080,360) # radius
x = r*np.sin(np.radians(t))
y = r*np.cos(np.radians(t))
plt.grid('on')
plt.plot(x,y)
plt.axis('equal')
Project Code Link :
3d Graph animation Code Link : https://www.engineerknow.com/2021/09/3d-interactive-graph-animation-in.html
0 Comments
if you are not getting it then ask i am glad to help