+/IBCS
git clone https://git.julia.blue/+/IBCS
c0ce159
master
1import numpy as np 2import matplotlib .pyplot as plt 3from mpl_toolkits .mplot3d import Axes3D 4import matplotlib .tri as mtri 5 6# u, v are parameterisation variables 7u = (np .linspace (0 ,2.0 * np .pi ,endpoint = True ,num = 50 )* np .ones ((10 ,1 ))).flatten () 8v = np .repeat (np .linspace (- 0.5 ,0.5 ,endpoint = True ,num = 10 ),repeats = 50 ).flatten () 9 10# This is the Mobius mapping, taking a u, v pair and returning an x, y, z 11# triple 12x = (1 + 0.5 * v * np .cos (u / 2.0 ))* np .cos (u ) 13y = (1 + 0.5 * v * np .cos (u / 2.0 ))* np .sin (u ) 14z = 0.5 * v * np .sin (u / 2.0 ) 15 16# Triangulate parameter space to determine the triangles 17tri = mtri .Triangulation (u ,v ) 18 19fig = plt .figure () 20ax = fig .add_subplot (1 ,1 ,1 ,projection = '3d' ) 21 22# The triangles in parameter space determine which x, y, z points are 23# connected by an edge 24ax .plot_trisurf (x ,y ,z ,triangles = tri .triangles ,cmap = plt .cm .Spectral ) 25 26ax .set_zlim (- 1 ,1 ) 27 28# First create the x and y coordinates of the points. 29n_angles = 36 30n_radii = 8 31min_radius = 0.25 32radii = np .linspace (min_radius ,0.95 ,n_radii ) 33 34angles = np .linspace (0 ,2 * np .pi ,n_angles ,endpoint = False ) 35angles = np .repeat (angles [...,np .newaxis ],n_radii ,axis = 1 ) 36angles [:,1 ::2 ]+= np .pi / n_angles 37 38x = (radii * np .cos (angles )).flatten () 39y = (radii * np .sin (angles )).flatten () 40z = (np .cos (radii )* np .cos (angles * 3.0 )).flatten () 41 42# Create the Triangulation; no triangles so Delaunay triangulation created. 43triang = mtri .Triangulation (x ,y ) 44 45# Mask off unwanted triangles. 46xmid = x [triang .triangles ].mean (axis = 1 ) 47ymid = y [triang .triangles ].mean (axis = 1 ) 48mask = np .where (xmid * xmid + ymid * ymid < min_radius * min_radius ,1 ,0 ) 49triang .set_mask (mask ) 50 51# tripcolor plot. 52fig = plt .figure () 53ax = fig .add_subplot (1 ,1 ,1 ,projection = '3d' ) 54ax .plot_trisurf (triang ,z ,cmap = plt .cm .CMRmap ) 55plt .show ()