# plot_who5.py3 parabaloid rotated import numpy as np from matplotlib import pyplot as plt from mpl_toolkits.mplot3d import Axes3D from math import sin, cos, pi import matplotlib.cm as cm print("plot_who5.py3 running") fig = plt.figure() ax = fig.add_subplot(111, projection='3d') #creating grid y = np.linspace(-1,1,200) x = np.linspace(-1,1,200) x,y = np.meshgrid(x,y) #set z values z0 = x**2+y**2 print("before rotated") print("x[0][0]=",x[0][0]) print("y[0][0]=",y[0][0]) print("z0[0][0]=",z0[0][0]) # rotate the samples by pi / 4 radians around y a = pi / 4 t = np.transpose(np.array([x,y,z0]), (1,2,0)) m = [[cos(a), 0, sin(a)],[0,1,0],[-sin(a), 0, cos(a)]] x,y,z = np.transpose(np.dot(t, m), (2,0,1)) # or `np.dot(t, m)` instead `t @ m` print("rotated") print("x[0][0]=",x[0][0]) print("y[0][0]=",y[0][0]) print("z[0][0]=",z[0][0]) #label axes ax.set_xlabel('x') ax.set_ylabel('y') ax.set_zlabel('z') ax.set_title('plot_who5.py3 rotated') #plot figure ax.plot_surface(x,y,z,linewidth=0, antialiased=False, shade = True, alpha = 0.5, facecolors=cm.viridis(z0)) plt.show() print("plot_who5.py3 finished")