This commit is contained in:
2023-07-26 00:46:01 +08:00
parent c7cbcd09af
commit 822fa7e626
212 changed files with 5687 additions and 5687 deletions

View File

@@ -0,0 +1,32 @@
import numpy as np
# import os
# os.chdir('D:/data') # 设置文件保存的位置
def main():
x = [4, 3, 5, 7]
y = [6, 1, 3, 2]
value = [3, 1, 10, 2]
Plot_2D_Scatter(x, y, value, title='Plot 2D Scatter')
def Plot_2D_Scatter(x, y, value, xlabel='x', ylabel='y', title='title', filename='a'):
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
plt.subplots_adjust(bottom=0.2, right=0.8, left=0.2)
for i in range(np.array(x).shape[0]):
ax.scatter(x[i], y[i], marker='o', s=100*value[i], c=[(1,0,0)])
ax.set_title(title, fontsize=20, fontfamily='Times New Roman')
ax.set_xlabel(xlabel, fontsize=20, fontfamily='Times New Roman')
ax.set_ylabel(ylabel, fontsize=20, fontfamily='Times New Roman')
ax.tick_params(labelsize=15) # 设置刻度值字体大小
labels = ax.get_xticklabels() + ax.get_yticklabels()
[label.set_fontname('Times New Roman') for label in labels] # 设置刻度值字体
# plt.savefig(filename+'.jpg', dpi=300)
plt.show()
plt.close('all')
if __name__ == '__main__':
main()

View File

@@ -0,0 +1,38 @@
import numpy as np
# import os
# os.chdir('D:/data') # 设置文件保存的位置
def main():
x = [1, 3, 5, 7]
y = [2, 4, 6, 8]
z = [2, 8, 6, 1]
value = [3, 1, 10, 2]
Plot_3D_Scatter(x, y, z, value, title='Plot 3D Scatter')
def Plot_3D_Scatter(x, y, z, value, xlabel='x', ylabel='y', zlabel='z', title='title', filename='a'):
import matplotlib.pyplot as plt
from matplotlib.ticker import LinearLocator
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
plt.subplots_adjust(bottom=0.1, right=0.8)
for i in range(np.array(x).shape[0]):
ax.scatter(x[i], y[i], z[i], marker='o', s=int(100*value[i]), c=[(1,0,0)])
ax.set_title(title, fontsize=20, fontfamily='Times New Roman')
ax.set_xlabel(xlabel, fontsize=20, fontfamily='Times New Roman')
ax.set_ylabel(ylabel, fontsize=20, fontfamily='Times New Roman')
ax.set_zlabel(zlabel, fontsize=20, fontfamily='Times New Roman')
# ax.set_zlim(0, 20)
# ax.zaxis.set_major_locator(LinearLocator(6)) # 设置z轴主刻度的个数
# ax.zaxis.set_major_formatter('{x:.0f}') # 设置z轴主刻度的格式
ax.tick_params(labelsize=15) # 设置刻度值字体大小
labels = ax.get_xticklabels() + ax.get_yticklabels() + ax.get_zticklabels()
[label.set_fontname('Times New Roman') for label in labels] # 设置刻度值字体
# plt.savefig(filename+'.jpg', dpi=300)
plt.show()
plt.close('all')
if __name__ == '__main__':
main()

View File

@@ -0,0 +1,43 @@
import numpy as np
# import os
# os.chdir('D:/data') # 设置文件保存的位置
def main():
x = np.arange(-5, 5, 0.25)
y = np.arange(-5, 5, 0.25)
X, Y = np.meshgrid(x, y)
R = np.sqrt(X**2 + Y**2)
Z = np.sin(R)
Plot_3D_Surface(x,y,Z)
def Plot_3D_Surface(x,y,matrix,filename='a.jpg', titlename='Plot 3D Surface'):
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.ticker import LinearLocator
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
plt.subplots_adjust(bottom=0.1, right=0.65) # 调整位置
x, y = np.meshgrid(x, y)
surf = ax.plot_surface(x, y, matrix, cmap=cm.coolwarm, linewidth=0, antialiased=False) # Plot the surface.
ax.set_title(titlename, fontsize=20, fontfamily='Times New Roman')
ax.set_xlabel('x', fontsize=30, fontfamily='Times New Roman') # 坐标标签
ax.set_ylabel('y', fontsize=30, fontfamily='Times New Roman') # 坐标标签
ax.set_zlabel('z', fontsize=30, fontfamily='Times New Roman') # 坐标标签
# ax.set_zlim(-1, 1) # 设置z轴的范围
ax.zaxis.set_major_locator(LinearLocator(5)) # 设置z轴主刻度的个数
ax.zaxis.set_major_formatter('{x:.2f}') # 设置z轴主刻度的格式
ax.tick_params(labelsize=15) # 设置刻度值字体大小
labels = ax.get_xticklabels() + ax.get_yticklabels() + ax.get_zticklabels()
[label.set_fontname('Times New Roman') for label in labels] # 设置刻度值字体
cax = plt.axes([0.75, 0.15, 0.05, 0.75]) # color bar的位置 [左,下,宽度, 高度]
cbar = fig.colorbar(surf, cax=cax) # color bar
cbar.ax.tick_params(labelsize=15) # 设置color bar刻度的字体大小
[l.set_family('Times New Roman') for l in cbar.ax.yaxis.get_ticklabels()] # 设置color bar刻度的字体
# plt.savefig(filename, dpi=800) # 保存图片文件
plt.show()
plt.close('all') # 关闭所有plt防止循环画图时占用内存
if __name__ == '__main__':
main()

View File

@@ -0,0 +1,41 @@
import numpy as np
# import os
# os.chdir('D:/data') # 设置文件保存的位置
def main():
x = np.arange(-5, 5, 0.25)
y = np.arange(-5, 5, 0.25)
X, Y = np.meshgrid(x, y)
R = np.sqrt(X**2 + Y**2)
Z = np.sin(R)
Plot_Contour(x,y,Z)
def Plot_Contour(x,y,matrix,filename='a.jpg', titlename='Plot Contour'):
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.ticker import LinearLocator
fig, ax = plt.subplots()
plt.subplots_adjust(bottom=0.15, right=0.7) # 调整位置
x, y = np.meshgrid(x, y)
contour = ax.contourf(x,y,matrix,cmap='jet')
ax.set_title(titlename, fontsize=20, fontfamily='Times New Roman')
ax.set_xlabel('x', fontsize=30, fontfamily='Times New Roman') # 坐标标签
ax.set_ylabel('y', fontsize=30, fontfamily='Times New Roman') # 坐标标签
# plt.xlabel('x')
# plt.ylabel('y')
ax.tick_params(labelsize=15) # 设置刻度值字体大小
labels = ax.get_xticklabels() + ax.get_yticklabels()
[label.set_fontname('Times New Roman') for label in labels] # 设置刻度值字体
cax = plt.axes([0.75, 0.15, 0.08, 0.73]) # color bar的位置 [左,下,宽度, 高度]
cbar = fig.colorbar(contour, cax=cax) # color bar
cbar.ax.tick_params(labelsize=15) # 设置color bar刻度的字体大小
[l.set_family('Times New Roman') for l in cbar.ax.yaxis.get_ticklabels()] # 设置color bar刻度的字体
# plt.savefig(filename, dpi=800) # 保存图片文件
plt.show()
plt.close('all') # 关闭所有plt防止循环画图时占用内存
if __name__ == '__main__':
main()

View File

@@ -0,0 +1,30 @@
import numpy as np
# import os
# os.chdir('D:/data') # 设置文件保存的位置
def main():
x = np.arange(0.0, 2.0, 0.01)
y = 1 + np.sin(2 * np.pi * x)
Plot_Line(x,y)
def Plot_Line(x,y,filename='a.jpg', titlename='Plot Line'):
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
plt.subplots_adjust(bottom=0.20, left=0.16)
ax.plot(x, y, '-o')
ax.grid()
ax.set_title(titlename, fontsize=20, fontfamily='Times New Roman')
ax.set_xlabel('x', fontsize=30, fontfamily='Times New Roman') # 坐标标签
ax.set_ylabel('y', fontsize=30, fontfamily='Times New Roman') # 坐标标签
ax.tick_params(labelsize=20) # 设置刻度值字体大小
labels = ax.get_xticklabels() + ax.get_yticklabels()
[label.set_fontname('Times New Roman') for label in labels] # 设置刻度值字体
# plt.savefig(filename, dpi=800) # 保存图片文件
plt.show()
plt.close('all') # 关闭所有plt防止循环画图时占用内存
if __name__ == '__main__':
main()