Lecture_TWP_Python_A05_1a_2D_Graphics
Lecture_TWP_Python_A05_1a_2D_Graphics
Nirjhar Dhang
√
Version : 1.732 : 3
Created on : August 11, 2016
Last revision : January 11, 2025
Together With Python
Computation, Visualization and Reporting
Part A-5 : 2D Graphics
Nirjhar Dhang
√
Version : 1.732 : 3
Created on : August 11, 2016
Last revision : January 11, 2025
Overview
1 Two-dimensional Graphics
3 Building Frame
4 Summary
5 References
Two-dimensional Graphics
Two-dimensional Graphics
import numpy as np
import matplotlib.pyplot as plt
def function(t):
return np.exp(-t) * np.cos(2*np.pi*t)
plt.figure(1)
plt.plot(tvec, function(tvec))
plt.show()
Two-dimensional Graphics using matplotlib
Two-dimensional Graphics using matplotlib
import numpy as np
import matplotlib.pyplot as plt
def function(t):
return np.exp(-t) * np.cos(2*np.pi*t)
plt.figure(1)
plt.plot(tvec1, function(tvec1), ’k’, tvec2, function
(tvec2), ’ro’)
plt.show()
Two-dimensional Graphics using matplotlib
Building Frame
Building Frame
import matplotlib.pyplot as plt
plt.plot([0,0],[0,4],’b’)
plt.plot([0,0],[4,8],’b’)
plt.plot([5,5],[0,4],’r’)
plt.plot([5,5],[4,8],’r’)
plt.plot([10,10],[0,4],’b’)
plt.plot([10,10],[4,8],’b’)
plt.plot([0,5],[4,4],’k’)
plt.plot([5,10],[4,4],’k’)
plt.plot([0,5],[8,8],’m’)
plt.plot([5,10],[8,8],’m’)
plt.plot([0,5],[4,4],’k’)
plt.plot([5,10],[4,4],’k’)
plt.plot([0,5],[8,8],’m’)
plt.plot([5,10],[8,8],’m’)
plt.axis(’off’)
plt.show()
Building Frame
Building Frame
fig = plt.figure()
ax = fig.add_subplot(111)
plt.plot([0,0],[0,4],’b’)
plt.plot([0,0],[4,8],’b’)
plt.plot([5,5],[0,4],’r’)
plt.plot([5,5],[4,8],’r’)
plt.plot([10,10],[0,4],’b’)
plt.plot([10,10],[4,8],’b’)
plt.plot([0,5],[4,4],’k’)
plt.plot([5,10],[4,4],’k’)
plt.plot([0,5],[8,8],’m’)
Building Frame
ax.text(4,-1,’Plane Frame’)
ax.text(-0.5,0,’1’)
ax.text(-0.5,4,’4’)
ax.text(-0.5,8,’7’)
ax.text(5.1,0.25,’2’)
ax.text(5.1,4.25,’5’)
ax.text(5,8.25,’8’)
ax.text(10.25,0,’3’)
ax.text(10.25,4,’6’)
ax.text(10.25,8,’9’)
plt.axis(’off’)
Building Frame
Building Frame
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
fig = plt.figure()
ax = fig.add_subplot(111)
plt.plot([0,0],[0,4],’b’)
plt.plot([0,0],[4,8],’b’)
plt.plot([5,5],[0,4],’r’)
plt.plot([5,5],[4,8],’r’)
plt.plot([10,10],[0,4],’b’)
plt.plot([10,10],[4,8],’b’)
plt.plot([0,5],[4,4],’k’)
plt.plot([5,10],[4,4],’k’)
plt.plot([0,5],[8,8],’m’)
plt.plot([5,10],[8,8],’m’)
Building Frame
ax.text(4,-1,’Plane Frame’)
ax.text(-0.5,0,’1’)
ax.text(-0.5,4,’4’)
ax.text(-0.5,8,’7’)
ax.text(5.1,0.25,’2’)
ax.text(5.1,4.25,’5’)
ax.text(5,8.25,’8’)
ax.text(10.25,0,’3’)
ax.text(10.25,4,’6’)
ax.text(10.25,8,’9’)
Building Frame
p1=mpatches.Circle((-0.2,2),0.2,color=’k’,fill=False)
ax.add_patch(p1)
ax.text(-0.3,1.9,’1’)
p2=mpatches.Circle((-0.2,6),0.2,color=’k’,fill=False)
ax.add_patch(p2)
ax.text(-0.3,5.9,’2’)
p3=mpatches.Circle((4.8,2),0.2,color=’k’,fill=False)
ax.add_patch(p3)
ax.text(4.7,1.9,’3’)
p4=mpatches.Circle((4.8,6),0.2,color=’k’,fill=False)
ax.add_patch(p4)
ax.text(4.7,5.9,’4’)
Building Frame
p5=mpatches.Circle((9.8,2),0.2,color=’k’,fill=False)
ax.add_patch(p5)
ax.text(9.7,1.9,’5’)
p6=mpatches.Circle((9.8,6),0.2,color=’k’,fill=False)
ax.add_patch(p6)
ax.text(9.7,5.9,’6’)
p7=mpatches.Circle((2.3,4.3),0.2,color=’k’,fill=False
)
ax.add_patch(p7)
ax.text(2.2,4.2,’7’)
p8=mpatches.Circle((7.3,4.3),0.2,color=’k’,fill=False
)
ax.add_patch(p8)
ax.text(7.2,4.2,’8’)
Building Frame
p9=mpatches.Circle((2.3,8.3),0.2,color=’k’,fill=False
)
ax.add_patch(p9)
ax.text(2.2,8.2,’9’)
p10=mpatches.Circle((7.35,8.3),0.25,color=’k’,fill=Fa
lse)
ax.add_patch(p10)
ax.text(7.2,8.2,’10’)
plt.axis(’off’)
plt.show()
Building Frame
Summary
Summary