如何绘制云图
RT。想实现类似于应力云图的效果,以一个四节点的单元为例简单的说,知道四个节点的应力数值,在整个单元范围之内根据已知四个点的应力数值绘制出云图效果。类似下面的图
import numpy as np from scipy.interpolate import griddata import matplotlib.pyplot as plt # 4 Point Sample Data #x=np.array([7.071067812,10,7.071067812,1.22515E-15]) #y=np.array([7.071067812,6.12574E-16,-7.071067812,-10]) #z=np.array([0.322,0.337,0.379,0.344]) # 8 Point Sample Data # x=np.array([7.071067812,10,7.071067812,1.22515E-15,-7.071067812,-10,-7.071067812,-2.4503E-15]) # y=np.array([7.071067812,6.12574E-16,-7.071067812,-10,-7.071067812,-1.83772E-15,7.071067812,10]) # z=np.array([0.322,0.337,0.379,0.344,0.328,0.331,0.435,0.386]) # 12 Point Sample Data x = np.array([5,8.660254038,10,8.660254038,5,1.22515E-15,-5,-8.660254038,-10,-8.660254038,-5,-2.4503E-15]) y = np.array([8.660254038,5,6.12574E-16,-5,-8.660254038,-10,-8.660254038,-5,-1.83772E-15,5,8.660254038,10]) z = np.array([0.006,0.021,0.063,0.028,0.012,0.015,0.119,0.07,0.071,0,0.003,0.054]) def plot_contour(x,y,z,resolution = 50,contour_method='linear'): resolution = str(resolution)+'j' X,Y = np.mgrid[min(x):max(x):complex(resolution), min(y):max(y):complex(resolution)] points = [[a,b] for a,b in zip(x,y)] Z = griddata(points, z, (X, Y), method=contour_method) return X,Y,Z X,Y,Z = plot_contour(x,y,z,resolution = 500,contour_method='cubic') with plt.style.context("seaborn-white"): fig, ax = plt.subplots(figsize=(13,13)) ax.scatter(x,y, color="Red", linewidth=1, edgecolor="ivory", s=50) ax.contourf(X, Y, Z, cmap="rainbow") fig.show()