def add_bands_wireframe_plot(axes3d: Axes3D, kpoints: numpy.ndarray, eigenvalues: numpy.ndarray, axis: int, layer: int, resolution: int, band_indices: Union[List[int], range, numpy.ndarray], offset: Union[List[float], numpy.ndarray] = None): x, y, zs = get_x_y_zs(kpoints, eigenvalues, axis, layer) if offset is not None: x += offset[0] y += offset[1] zs += offset[2] triang = tri.Triangulation(x, y) x_linspace = numpy.linspace(min(x), max(x), resolution) y_linspace = numpy.linspace(min(y), max(y), resolution) b_range = max(band_indices) - min(band_indices) if len( band_indices) > 1 else 1 for b in band_indices: interpolator = tri.LinearTriInterpolator(triang, zs[:, b]) x_meshgrid, y_meshgrid = numpy.meshgrid(x_linspace, y_linspace) z_mesggrid = interpolator(x_meshgrid, y_meshgrid) color = (max(band_indices) - b) / b_range / 1.5 axes3d.plot_wireframe(x_meshgrid, y_meshgrid, z_mesggrid, colors=(color, color, color))
def plotFigures(xSolid,ySolid,zSolid,xFFDDeform,yFFDDeform,zFFDDeform, xsolidInitial, ysolidInitial, zsolidInitial, xFFDInitial, yFFDInitial, zFFDInitial): fig = plt.figure() ax = fig.add_subplot(111, projection='3d') # Axes3D.plot_wireframe(ax, z, x, y) ax.set_xlabel('Z axis') ax.set_ylabel('X axis') ax.set_zlabel('Y axis') #Axes3D.scatter(ax, zSolid, xSolid, ySolid, s=10, c='b') Axes3D.plot_wireframe(ax, zSolid, xSolid, ySolid, rstride = 1, cstride = 1, color="b") Axes3D.scatter(ax, zFFDDeform, xFFDDeform, yFFDDeform, s=30, c='r') #Axes3D.scatter(ax, zsolidInitial, xsolidInitial, ysolidInitial, s=10, c='y') Axes3D.plot_wireframe(ax, zsolidInitial, xsolidInitial, ysolidInitial,rstride = 1, cstride = 1, color="y") Axes3D.scatter(ax, zFFDInitial, xFFDInitial, yFFDInitial, s=30, c='g') xZCross = [] yZCross = [] zZCross = [] #plot the points for the limits of each cross section for zCrossSect in GLOBAL_zCrossSectionObjects: zCrossSectionObject = GLOBAL_zCrossSectionObjects[zCrossSect] #add to the arrays, for a fixed z, the following combinations # (xmax, ymax) (xmax, ymin) (xmin, ymin) (xmin, ymax) # (xmax, ymax) xZCross.append(zCrossSectionObject.getXMax()) yZCross.append(zCrossSectionObject.getYMax()) zZCross.append(zCrossSect) #(xmax, ymin) xZCross.append(zCrossSectionObject.getXMax()) yZCross.append(zCrossSectionObject.getYMin()) zZCross.append(zCrossSect) #(xmin, ymin) xZCross.append(zCrossSectionObject.getXMin()) yZCross.append(zCrossSectionObject.getYMin()) zZCross.append(zCrossSect) #(xmin, ymax) xZCross.append(zCrossSectionObject.getXMin()) yZCross.append(zCrossSectionObject.getYMax()) zZCross.append(zCrossSect) #Axes3D.plot_wireframe(ax, zZCross, xZCross, yZCross) #Axes3D.set_ylim(ax, [-0.5,4.5]) #Axes3D.set_xlim(ax, [-0.5,4.5]) Axes3D.set_zlim(ax, [-0.7, 0.7]) plt.show(block=True)
def _draw_sphere(ax: Axes3D, sphere: Sphere, color: str, elem_num: int, alpha: float): u = np.linspace(-np.pi / 2, np.pi / 2, elem_num) v = np.linspace(0, 2 * np.pi, elem_num) xi, phy = np.meshgrid(v, u) x = sphere.center[0] + sphere.radius * np.sin(xi) * np.cos(phy) y = sphere.center[1] + sphere.radius * np.sin(xi) * np.sin(phy) z = sphere.center[2] + sphere.radius * np.cos(xi) ax.plot_wireframe(x, y, z, color=color, alpha=alpha)
def _draw_plane(self, axis: Axes3D) -> None: """Draw plane that is not perpendicular to z and x axes :param axis: where to draw :return: """ xx, zz = np.meshgrid(range(-150, 151, 50), range(-150, 151, 50)) a, b, c, d = self._plane yy = -(d + a * xx + c * zz) / b axis.plot_wireframe(xx, yy, zz)
def _draw_ellipse(ax: Axes3D, ellipse: Ellipse, color: str, elem_num: int, alpha: float): rx, ry, rz = ellipse.semi_axes u = np.linspace(0, np.pi, elem_num) v = np.linspace(0, 2 * np.pi, elem_num) xi, phy = np.meshgrid(u, v) x = ellipse.center[0] + rx * np.sin(xi) * np.cos(phy) y = ellipse.center[1] + ry * np.sin(xi) * np.sin(phy) z = ellipse.center[2] + rz * np.cos(xi) ax.plot_wireframe(x, y, z, color=color, alpha=alpha)
def graph2DFunction(lbound, ubound, resolution, function, functionName='', directory=None): ''' Parameters ---------- lbound: The lower bound value ubound: The upper bound value resolution: How small the spaces between the list of values function: 2D Function to be evaluated (BBOB object) Return ---------- Graphs the function given the X and Y and Resolution Source ---------- Implementation of PFlacco and Modea ''' #Convert BBOB function to act like a normal function def function_n(x, y): return function([x, y]) x = np.arange(lbound, ubound, resolution) y = np.arange(lbound, ubound, resolution) xx, yy = np.meshgrid(x, y, sparse=True) function_v = np.vectorize(function_n) Z = function_v(xx, yy) fig = plt.figure() ax = fig.add_subplot(111, projection='3d') fig.suptitle(functionName) Axes3D.plot_wireframe(ax, X=xx, Y=yy, Z=Z) if directory is None: plt.show() else: plt.savefig(directory)
def plotFiguresTemp(xSolid, ySolid, zSolid, xFFDDeform, yFFDDeform, zFFDDeform): fig = plt.figure() ax = fig.add_subplot(111, projection='3d') # Axes3D.plot_wireframe(ax, z, x, y) ax.set_xlabel('Z axis') ax.set_ylabel('X axis') ax.set_zlabel('Y axis') Axes3D.plot_wireframe(ax, zSolid, xSolid, ySolid, rstride = 1, cstride = 1, color="b") Axes3D.scatter(ax, zFFDDeform, xFFDDeform, yFFDDeform, s=30, c='r') #Axes3D.scatter(ax, zPointArray, xPointArray, yPointArray, s=30, c = 'r') # Axes3D.set_ylim(ax, [-0.5,4.5]) # Axes3D.set_xlim(ax, [-0.5,4.5]) Axes3D.set_zlim(ax, [-0.7, 0.7]) plt.show(block=True)
def MultPlot( x, data, fig=py.figure(), ax=None, pos=111, projection=None, sphere=False, title='', labels=(), xlabel='x', ylabel='y', zlabel='z', labelsize=17, linewidth = 1.5, styles = ('solid','solid','solid','solid','solid'), colors = ('blue','red','cyan', 'orange', 'yellow', 'green' ) ): """Plots multiple data sets on one set of axes (x). Breaks if dfferent lengths between x and elements of data. Can also handle inputs as meshgrids for 3d plotting (must set projection to '3d'). Can plot in spherical coordinates as well (set sphere to True).""" if ax is None: ax = fig.add_subplot( pos, projection=projection ) if projection == 'polar': #ax.set_theta_zero_location("N") #ax.set_rlabel_position(-30) ax.ticklabel_format(style='sci',scilimits=(-2,2),axis='y') ax.yaxis.set_offset_position('right') else: ax.ticklabel_format(style='sci',scilimits=(-2,2),axis='both') # ax.xaxis.major.formatter._useMathText = True # ax.yaxis.major.formatter._useMathText = True # Sets scientific notation if ax.get_title() == '': ax.set_title( title, loc='center' ) if type(data) is not tuple: data = ( data, ) for dat, lab, clr, stl in itertools.izip_longest( data, labels, colors, styles ) : if dat is None: break elif sphere is True: fig, ax = SpherePlot( x[0], x[1], dat, fig=fig, ax=ax, color=clr ) ax.zaxis.major.formatter._useMathText = True ax.set_zlabel( zlabel, size=labelsize ) elif projection == '3d': Axes3D.plot_wireframe( ax, x[0], x[1], dat, label=lab, linewidth=linewidth, color=clr ) ax.zaxis.major.formatter._useMathText = True ax.set_zlabel( zlabel, size=labelsize ) else: ax.plot( x[0], dat, label=lab, linewidth=linewidth, color=clr, ls=stl ) ax.set_xlabel( xlabel, size=labelsize ) ax.set_ylabel( ylabel, size=labelsize ) return fig, ax
def plotFFDPointsAndPlane(xsolidInitial,ysolidInitial, zsolidInitial, xFFDInitial, yFFDInitial, zFFDInitial, LeadingEdgeX, LeadingEdgeY, LeadingEdgeZ): fig = plt.figure() ax = fig.add_subplot(111, projection='3d') # Axes3D.plot_wireframe(ax, z, x, y) ax.set_xlabel('Z axis') ax.set_ylabel('X axis') ax.set_zlabel('Y axis') Axes3D.scatter(ax, zsolidInitial, xsolidInitial, ysolidInitial, s=10, c='y') #Axes3D.plot_wireframe(ax, zsolidInitial, xsolidInitial, ysolidInitial, rstride = 1, cstride = 1, color='y') #Axes3D.scatter(ax, LeadingEdgeZ, LeadingEdgeX, LeadingEdgeY, s=10, c='y') #Axes3D.plot_wireframe(ax, zSolid, xSolid, ySolid, rstride = 1, cstride = 1, color="b") Axes3D.scatter(ax, zFFDInitial, xFFDInitial, yFFDInitial, s=10, c='r') LeadingEdgeX1 = [] LeadingEdgeY1 = [] LeadingEdgeZ1 = [] #Find all the leading edge points: for element in solidBoundaryPointArray: if((element.getLabel() == "LeadingEdge") or (element.getLabel() == "TrailingEdge") or (element.getLabel() == "WingTip") or (element.getLabel() == "WingRoot")): LeadingEdgeX1.append(element.getX()) LeadingEdgeY1.append(element.getY()) LeadingEdgeZ1.append(element.getZ()) #Axes3D.scatter(ax, LeadingEdgeZ1, LeadingEdgeX1, LeadingEdgeY1, s=100, c='r') #plot the deformed wing and FFD point data xDeformed = [] yDeformed = [] zDeformed = [] xFFDDeformed = [] yFFDDeformed = [] zFFDDeformed = [] for element in solidBoundaryPointArray: xDeformed.append(element.getX()) yDeformed.append(element.getY()) zDeformed.append(element.getZ()) # filling the FFD arrays for i in range(CONST_nXFDD): for j in range(CONST_nYFDD): for k in range(CONST_nZFDD): element = FFDPointArray[i][j][k] xFFDDeformed.append(element.getX()) yFFDDeformed.append(element.getY()) zFFDDeformed.append(element.getZ()) """ Axes3D.plot_wireframe(ax, zDeformed, xDeformed, yDeformed, rstride =1, cstride = 1, color='b') """ Axes3D.scatter(ax, zDeformed, xDeformed, yDeformed, s=10, color='b') Axes3D.scatter(ax, zFFDDeformed, xFFDDeformed, yFFDDeformed, s=10, c='g') #takes a value for t,u,v. When a value is set to -1, then that parameter is free # to change while the one that is not set to -1 is the plane that needs to be drawn tuplesArray = plotIsoparametricLine(-1,-1,-1) xArray = [] yArray = [] zArray = [] for a in tuplesArray: xArray.append(a[0]) yArray.append(a[1]) zArray.append(a[2]) tuplesArray2 = plotIsoparametricLine(-1,-1,-1) xArray2 = [] yArray2 = [] zArray2 = [] for a in tuplesArray2: xArray2.append(a[0]) yArray2.append(a[1]) zArray2.append(a[2]) #Axes3D.scatter(ax, zArray, xArray, yArray, s=10, c='y') Axes3D.plot_wireframe(ax, zArray, xArray, yArray, rstride=1, cstride =1, color='g') Axes3D.plot_wireframe(ax, zArray2, xArray2, yArray2, rstride=1, cstride =1, color='g') #Axes3D.set_ylim(ax, [-0.5,4.5]) #Axes3D.set_xlim(ax, [-0.5,4.5]) Axes3D.set_zlim(ax, [-0.9, 0.9]) plt.show(block=True)
zN = np.cos(th) F20 = plt.figure(20) #F20=plt.subplot(1, 2, 1 ) Axes3D = plt.axes(projection='3d') Axes3D.scatter(xN, yN, zN, zdir='z', marker='o', s=10, c='r', depthshade=True) plt.title( 'Naključna začetna porazdelitev elektronov po enotski krogli ; N=' + str(N)) # draw sphere u, v = np.mgrid[0:2 * np.pi:30j, 0:np.pi:14j] x = np.cos(u) * np.sin(v) y = np.sin(u) * np.sin(v) z = np.cos(v) Axes3D.plot_wireframe(x, y, z, color='k', alpha=0.2) plt.xlim([-1.5, 1.5]) plt.ylim([-1.5, 1.5]) #plt.zlim([-1.2,1.2]) ###### ____ Th = res3.x[0:N] Fi = res3.x[N:2 * N] XN = np.sin(Th) * np.cos(Fi) YN = np.sin(Th) * np.sin(Fi) ZN = np.cos(Th) F10 = plt.figure(10)
from mpl_toolkits.mplot3d import Axes3D import scipy.constants as con def w(x, t): return np.sin(x + t) x = np.arange(1, 6, 0.1) t = np.arange(1, 6, 0.05) x, t = np.meshgrid(x, t) fig = plt.figure(1) ax = fig.add_subplot(111, projection='3d') z = w(x, t) Axes3D.plot_wireframe(ax, x, t, z, rstride=10, cstride=10) def v(x, t): return np.sin(x + t) + np.cos(2 * x + 2 * t) x = np.arange(1, 6, 0.1) t = np.arange(1, 6, 0.05) x, t = np.meshgrid(x, t) fig = plt.figure(2) ax = fig.add_subplot(111, projection='3d') z = v(x, t) Axes3D.plot_wireframe(ax, x, t, z, rstride=10, cstride=10) plt.show()
t_fft[i][j] = time() c_fft = fftmult(a, b) t_fft[i][j] = time() - t_fft[i][j] fig = plt.figure() ax = fig.add_subplot(111, projection='3d') X = [x[:] for x in [[0] * l] * l] Y = [x[:] for x in [[0] * l] * l] for i in range(l): for j in range(l): X[i][j] = i Y[i][j] = j Z = t_o Axes3D.plot_wireframe(X, Y, Z, rstride=2, cstride=2) Z = t_ttf Axes3D.plot_wireframe(X, Y, Z, rstride=2, cstride=2) plt.title('Time of Multiplying') plt.tight_layout() plt.show() ''' #X, Y, Z = axes3d.get_test_data(0.05) print(X) print(Y) #print(Z) ''' print(t_o) print('\n\n\n\n\n\n') print(t_fft)
def plotFFDPointsAndPlane(xsolidInitial, ysolidInitial, zsolidInitial, xFFDInitial, yFFDInitial, zFFDInitial, LeadingEdgeX, LeadingEdgeY, LeadingEdgeZ): fig = plt.figure() ax = fig.add_subplot(111, projection='3d') # Axes3D.plot_wireframe(ax, z, x, y) ax.set_xlabel('Z axis') ax.set_ylabel('X axis') ax.set_zlabel('Y axis') Axes3D.scatter(ax, zsolidInitial, xsolidInitial, ysolidInitial, s=10, c='y') #Axes3D.plot_wireframe(ax, zsolidInitial, xsolidInitial, ysolidInitial, rstride = 1, cstride = 1, color='y') #Axes3D.scatter(ax, LeadingEdgeZ, LeadingEdgeX, LeadingEdgeY, s=10, c='y') #Axes3D.plot_wireframe(ax, zSolid, xSolid, ySolid, rstride = 1, cstride = 1, color="b") Axes3D.scatter(ax, zFFDInitial, xFFDInitial, yFFDInitial, s=10, c='r') LeadingEdgeX1 = [] LeadingEdgeY1 = [] LeadingEdgeZ1 = [] #Find all the leading edge points: for element in solidBoundaryPointArray: if ((element.getLabel() == "LeadingEdge") or (element.getLabel() == "TrailingEdge") or (element.getLabel() == "WingTip") or (element.getLabel() == "WingRoot")): LeadingEdgeX1.append(element.getX()) LeadingEdgeY1.append(element.getY()) LeadingEdgeZ1.append(element.getZ()) #Axes3D.scatter(ax, LeadingEdgeZ1, LeadingEdgeX1, LeadingEdgeY1, s=100, c='r') #plot the deformed wing and FFD point data xDeformed = [] yDeformed = [] zDeformed = [] xFFDDeformed = [] yFFDDeformed = [] zFFDDeformed = [] for element in solidBoundaryPointArray: xDeformed.append(element.getX()) yDeformed.append(element.getY()) zDeformed.append(element.getZ()) # filling the FFD arrays for i in range(CONST_nXFDD): for j in range(CONST_nYFDD): for k in range(CONST_nZFDD): element = FFDPointArray[i][j][k] xFFDDeformed.append(element.getX()) yFFDDeformed.append(element.getY()) zFFDDeformed.append(element.getZ()) """ Axes3D.plot_wireframe(ax, zDeformed, xDeformed, yDeformed, rstride =1, cstride = 1, color='b') """ Axes3D.scatter(ax, zDeformed, xDeformed, yDeformed, s=10, color='b') Axes3D.scatter(ax, zFFDDeformed, xFFDDeformed, yFFDDeformed, s=10, c='g') #takes a value for t,u,v. When a value is set to -1, then that parameter is free # to change while the one that is not set to -1 is the plane that needs to be drawn tuplesArray = plotIsoparametricLine(-1, -1, -1) xArray = [] yArray = [] zArray = [] for a in tuplesArray: xArray.append(a[0]) yArray.append(a[1]) zArray.append(a[2]) tuplesArray2 = plotIsoparametricLine(-1, -1, -1) xArray2 = [] yArray2 = [] zArray2 = [] for a in tuplesArray2: xArray2.append(a[0]) yArray2.append(a[1]) zArray2.append(a[2]) #Axes3D.scatter(ax, zArray, xArray, yArray, s=10, c='y') Axes3D.plot_wireframe(ax, zArray, xArray, yArray, rstride=1, cstride=1, color='g') Axes3D.plot_wireframe(ax, zArray2, xArray2, yArray2, rstride=1, cstride=1, color='g') #Axes3D.set_ylim(ax, [-0.5,4.5]) #Axes3D.set_xlim(ax, [-0.5,4.5]) Axes3D.set_zlim(ax, [-0.9, 0.9]) plt.show(block=True)
x = np.zeros((N, N), dtype=float) y = np.zeros((N, N), dtype=float) z = np.zeros((N, N), dtype=float) print(z.shape) t = time.time() th_idx = 0 for th in th_arr: ph_idx = 0 max_reward = -10 for ph in ph_arr: env3d.force_reset(th, ph, d) env3d.render() [ob, reward, episode_over, j] = env3d.step(26) x[th_idx, ph_idx] = th y[th_idx, ph_idx] = ph z[th_idx, ph_idx] = reward ph_idx += 1 if (reward > max_reward): max_reward = reward #print(reward) print("Max reward for th =", th, "line was =", max_reward) th_idx += 1 print("d =", d, "took", time.time() - t, "secs") fig = plt.figure() ax = fig.add_subplot(111, projection='3d') Axes3D.plot_wireframe(ax, x, y, z) ax.plot(xs=[0.02, 0.02], ys=[0.02, 0.02], zs=[-1, 2], color='g') fig.show() input("Press something...")
for n in range(n_t): # loop over time u_past = u.copy() for i in range(1,n_x-1): #loop over space u[i] = u_past[i] - beta*((u_past[i+1])**2-(u_past[i-1])**2)*0.5 plot(x,u) U = np.vstack([U, u]) plot.show() plot.close() fig = plt.figure() Axes3D = fig.gca(projection='3d') X, T = numpy.meshgrid(x,t) Axes3D.plot_wireframe(X,T,U,rstride=20,cstride=10) plt.show() plt.close() print "La segunda parte" n_x = 200 c = 1.0 dx = 2.0/n_x beta = 0.05 dt = beta*dx n_t = int(0.15/dt) x = linspace(0, 2.0, n_x)