Cara menggunakan shapely figures python

Bismillah…
Halo semuanya, berikut merupakan tutorial yang lumayan berguna untuk temen-temen yang ingin melakukan plot multiple figures menggunakan Library Matplotlib (Python 2).
Check this out! 🙂

1. Percobaan Pertama
Plot multiple figures sederhana
Code :

# Source :
# https://www.youtube.com/watch?v=LY03ufpxTCU
# https://www.tutorialspoint.com/python/list_max.htm

# importing the required modules 
import matplotlib.pyplot as plt 
import numpy as np 
from numpy import pi,linspace,sin,cos,tan
  
#Multiple figures
x1 = x2 = x3 = linspace(0, 4*pi, 100)
y1 = sin(x1)
y2 = cos(x2)
y3 = tan(x1)

plt.figure(1)
plt.plot(x1,y1,"b-", label = "line 1")
SingularPoint = 2*pi
xs = [SingularPoint,SingularPoint]
ys = [min(y1),max(y1)]
plt.plot( xs, ys, marker='', color='olive', linewidth=2, linestyle='dashed', label="singularity boundary")
plt.xlim(max(x1), min(x1))
plt.ylim(max(y1), min(y1))

# naming the x axis 
plt.xlabel('x [m]') 
# naming the y axis 
plt.ylabel('q [deg]')
# plotting the line 1 points  
plt.title('Singularity Robustness Test')
# show a legend on the plot 
plt.legend() 

plt.figure(2)
plt.plot(x2,y2,"r-h",label = "line 2")
SingularPoint = 2*pi
xs = [SingularPoint,SingularPoint]
ys = [min(y2),max(y2)]
plt.plot( xs, ys, marker='', color='olive', linewidth=2, linestyle='dashed', label="singularity boundary")
plt.xlim(max(x2), min(x2))
plt.ylim(max(y2), min(y2))
# naming the x axis 
plt.xlabel('x [m]') 
# naming the y axis 
plt.ylabel('q [deg]')
# plotting the line 1 points  
plt.title('Singularity Robustness Test')
# show a legend on the plot 
plt.legend() 

plt.figure(3)
plt.plot(x3,y3,"k-p",label = "line 3")
SingularPoint = 2*pi
xs = [SingularPoint,SingularPoint]
ys = [min(y3),max(y3)]
plt.plot( xs, ys, marker='', color='olive', linewidth=2, linestyle='dashed', label="singularity boundary")
plt.xlim(max(x3), min(x3))
plt.ylim(max(y3), min(y3))
# naming the x axis 
plt.xlabel('x [m]') 
# naming the y axis 
plt.ylabel('q [deg]')
# plotting the line 1 points  
plt.title('Singularity Robustness Test')
# show a legend on the plot 
plt.legend() 

# function to show the plot 
plt.show() 

Output :

Cara menggunakan shapely figures python
Gambar 1. Output Program

2. Percobaan Kedua
Percobaan plot multiple figures dengan beberapa modifikasi, seperti penambahan arrow, mengganti nama figure, menambahkan text, dan sebagainya.

Code:

# Source :
# https://www.youtube.com/watch?v=LY03ufpxTCU
# https://www.tutorialspoint.com/python/list_max.htm
# https://matplotlib.org/3.1.0/tutorials/text/text_intro.html
# https://stackoverflow.com/questions/25761717/matplotlib-simple-and-two-head-arrows

# importing the required modules 
import matplotlib.pyplot as plt 
import numpy as np 
from numpy import pi,linspace,sin,cos,tan
  
#Multiple figures
x1 = x2 = x3 = linspace(0, 4*pi, 100)
y1 = sin(x1)
y2 = cos(x2)
y3 = tan(x1)

plt.figure("Gambar Pertama")
plt.plot(x1,y1,"b-", label = "line 1")
SingularPoint = 3*pi
xs = [SingularPoint,SingularPoint]
ys = [min(y1),max(y1)]
plt.plot( xs, ys, marker='', color='olive', linewidth=2, linestyle='dashed', label="singularity boundary")
plt.xlim(min(x1),max(x1))
plt.ylim(min(y1),max(y1))
plt.text(SingularPoint+(max(x1)-SingularPoint)/2, max(y1)*3/4, "Singular", fontsize=10, horizontalalignment='center')
plt.text(SingularPoint/2, max(y1)*3/4, "Non Singular", fontsize=10, horizontalalignment='center')
plt.annotate(s='', xy=(min(x1), max(y1)*5/6), xytext=(SingularPoint,max(y1)*5/6), arrowprops=dict(arrowstyle='<->'))
plt.annotate(s='', xy=(SingularPoint, max(y1)*5/6), xytext=(max(x1),max(y1)*5/6), arrowprops=dict(arrowstyle='<->'))
plt.xlabel('x [m]') 
plt.ylabel('q [deg]')
plt.title('Singularity Robustness Test 1')
plt.legend() 

plt.figure("Gambar Kedua")
plt.plot(x2,y2,"r-h",label = "line 2")
SingularPoint = 2*pi
xs = [SingularPoint,SingularPoint]
ys = [min(y2),max(y2)]
plt.plot( xs, ys, marker='', color='olive', linewidth=2, linestyle='dashed', label="singularity boundary")
plt.xlim(min(x2),max(x2))
plt.ylim(min(y2),max(y2))
plt.text(SingularPoint+(max(x2)-SingularPoint)/2, max(y2)*3/4, "Singular", fontsize=10, horizontalalignment='center')
plt.text(SingularPoint/2, max(y2)*3/4, "Non Singular", fontsize=10, horizontalalignment='center')
plt.annotate(s='', xy=(min(x2), max(y2)*5/6), xytext=(SingularPoint,max(y2)*5/6), arrowprops=dict(arrowstyle='<->'))
plt.annotate(s='', xy=(SingularPoint, max(y2)*5/6), xytext=(max(x2),max(y2)*5/6), arrowprops=dict(arrowstyle='<->'))
plt.xlabel('x [m]') 
plt.ylabel('q [deg]')
plt.title('Singularity Robustness Test 2')
plt.legend() 

plt.figure("Gambar Ketiga")
plt.plot(x3,y3,"k-p",label = "line 3")
SingularPoint = 1*pi
xs = [SingularPoint,SingularPoint]
ys = [min(y3),max(y3)]
plt.plot( xs, ys, marker='', color='olive', linewidth=2, linestyle='dashed', label="singularity boundary")
plt.xlim(min(x3),max(x3))
plt.ylim(min(y3),max(y3))
plt.text(SingularPoint+(max(x3)-SingularPoint)/2, max(y3)*3/4, "Singular", fontsize=10, horizontalalignment='center')
plt.text(SingularPoint/2, max(y3)*3/4, "Non Singular", fontsize=10, horizontalalignment='center')
plt.annotate(s='', xy=(min(x3), max(y3)*5/6), xytext=(SingularPoint,max(y3)*5/6), arrowprops=dict(arrowstyle='<->'))
plt.annotate(s='', xy=(SingularPoint, max(y3)*5/6), xytext=(max(x3),max(y3)*5/6), arrowprops=dict(arrowstyle='<->'))
plt.xlabel('x [m]') 
plt.ylabel('q [deg]')
plt.title('Singularity Robustness Test 3')
plt.legend() 

# function to show the plot 
plt.show() 

Output :

Cara menggunakan shapely figures python
Gambar 2. Output program

Source:
-https://www.youtube.com/watch?v=LY03ufpxTCU
-https://www.tutorialspoint.com/python/list_max.htm

Diterbitkan oleh sobirin1709

Penulis merupakan salah satu mahasiswa teknik elektro di bandung. Lihat semua pos dari sobirin1709