So i’m learning python and I am currently on making 3D plots of things. To keep things interesting I want to make a plot of Klein Bottle, but somehow it is not at all working. And i tried two parametrizations of the surface (one on Wolfram and one on a random website) both gave a torus-ish figure.
So I was wondering if maybe my code is wrong. Could anybody take a look and tell me if i am doing it right (and if you happen to know the parametrisation of a Klein bottle, then that is welcome too :P)
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
from matplotlib import cm
import numpy as np
def surf(u, v):
X = (3+(1+np.sin(v)) + 2*(1 - np.cos(v)/2)*np.cos(u))*np.cos(v)
Y = (4+2*(1 - np.cos(v)/2) * np.cos(u))*np.sin(v)
Z = -2*(1-np.cos(v)/2)*np.sin(u)
return X,Y,Z
ux, vx = np.meshgrid(np.linspace(0, 2*np.pi, 20),
np.linspace(0, 2*np.pi, 20))
x,y,z = surf(ux, vx)
fig = plt.figure()
ax = fig.gca(projection="3d")
plot = ax.plot_surface(x,y,z, rstride=1, cstride=1, cmap=cm.jet,
linewidth=0, antialiased=False)
plt.show()
Your Python code has the correct form, but it looks like there might be some error in the parametrization. Here is the Klein bottle produced by a different parametrization: