from numpy import * import matplotlib.pyplot as plt # 3D plott av en ellipsoide x=linspace(-5,3,20) y=linspace(-5,3,20) X,Y=meshgrid(x,y) ax = plt.axes(projection ='3d') ax.plot_surface( X, Y, (X+1)**2/1.5**2 + (Y+1)**2/3**2 ) plt.show() # 2D Contour plott av ellipsoiden plt.contour(X,Y,(X+1)**2/1.5**2 + (Y+1)**2/3**2) plt.axis('equal') plt.show() # 3D contour plott av ellipsoiden ax = plt.axes(projection ='3d') ax.contour3D(X,Y,(X+1)**2/1.5**2 + (Y+1)**2/3**2) plt.show() # 3D plott av en paraboloide theta = linspace(0,2*pi,50) r = linspace(0,2,50) rv,thetav = meshgrid(r,theta) ax = plt.axes(projection ='3d') ax.plot_surface(rv*cos(thetav),rv*sin(thetav), rv**2) plt.show() # Halvkule med radius 2 phi = linspace(0,pi/2,50) theta = linspace(0,2*pi,50) phiv,thetav = meshgrid(phi,theta) ax = plt.axes(projection ='3d') ax.plot_surface(2*cos(thetav)*sin(phiv),2*sin(thetav)*sin(phiv), 2*cos(phiv)) plt.show() # 2D vektorfelt plott x=linspace(-1,1,10) y=x X,Y=meshgrid(x,y) plt.quiver(X,Y,-X/(X**2+Y**2)**(3/2), -Y/(X**2+Y**2)**(3/2)) plt.show() # 3D vektorfelt plott x=linspace(-1,1,10) y=x; z= x; X,Y,Z=meshgrid(x,y,z) ax = plt.axes(projection ='3d') ax.quiver(X,Y,Z,-X/(X**2+Y**2+Z**2)**(3/2), -Y/(X**2+Y**2+Z**2)**(3/2), -Z/(X**2+Y**2+Z**2)**(3/2)) plt.show() # 2D str?mlinjeplott x=linspace(-1,1,10) y=x X,Y=meshgrid(x,y) plt.streamplot(X,Y,-X/(X**2+Y**2)**(3/2), -Y/(X**2+Y**2)**(3/2)) plt.show() # 3D plott av en torus theta=linspace(0,2*pi,100) phi=linspace(0,2*pi,100) thetav,phiv=meshgrid(theta,phi) ax = plt.axes(projection ='3d') ax.plot_surface( (3+cos(phiv))*cos(thetav), (3+cos(phiv))*sin(thetav), sin(phiv)) plt.show()