{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-10-01T03:58:43.566370Z","iopub.execute_input":"2022-10-01T03:58:43.567056Z","iopub.status.idle":"2022-10-01T03:58:43.599486Z","shell.execute_reply.started":"2022-10-01T03:58:43.566964Z","shell.execute_reply":"2022-10-01T03:58:43.598343Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from mpl_toolkits import mplot3d","metadata":{"execution":{"iopub.status.busy":"2022-10-01T03:58:48.301549Z","iopub.execute_input":"2022-10-01T03:58:48.302699Z","iopub.status.idle":"2022-10-01T03:58:48.308925Z","shell.execute_reply.started":"2022-10-01T03:58:48.302646Z","shell.execute_reply":"2022-10-01T03:58:48.307445Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nimport matplotlib.pyplot as plt","metadata":{"execution":{"iopub.status.busy":"2022-10-01T03:59:00.917029Z","iopub.execute_input":"2022-10-01T03:59:00.917472Z","iopub.status.idle":"2022-10-01T03:59:00.924776Z","shell.execute_reply.started":"2022-10-01T03:59:00.917437Z","shell.execute_reply":"2022-10-01T03:59:00.923317Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = plt.figure()\nax = plt.axes(projection='3d')","metadata":{"execution":{"iopub.status.busy":"2022-10-01T03:59:11.212411Z","iopub.execute_input":"2022-10-01T03:59:11.212786Z","iopub.status.idle":"2022-10-01T03:59:11.489869Z","shell.execute_reply.started":"2022-10-01T03:59:11.212756Z","shell.execute_reply":"2022-10-01T03:59:11.488984Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ax = plt.axes(projection='3d')\n\n# Data for a three-dimensional line\nzline = np.linspace(0, 15, 1000)\nxline = np.sin(zline)\nyline = np.cos(zline)\nax.plot3D(xline, yline, zline, 'gray')\n\n# Data for three-dimensional scattered points\nzdata = 15 * np.random.random(100)\nxdata = np.sin(zdata) + 0.1 * np.random.randn(100)\nydata = np.cos(zdata) + 0.1 * np.random.randn(100)\nax.scatter3D(xdata, ydata, zdata, c=zdata, cmap='Greens');","metadata":{"execution":{"iopub.status.busy":"2022-10-01T03:59:52.837184Z","iopub.execute_input":"2022-10-01T03:59:52.837677Z","iopub.status.idle":"2022-10-01T03:59:53.113288Z","shell.execute_reply.started":"2022-10-01T03:59:52.837632Z","shell.execute_reply":"2022-10-01T03:59:53.112340Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def f(x, y):\n    return np.sin(np.sqrt(x ** 2 + y ** 2))\n\nx = np.linspace(-6, 6, 30)\ny = np.linspace(-6, 6, 30)\n\nX, Y = np.meshgrid(x, y)\nZ = f(X, Y)","metadata":{"execution":{"iopub.status.busy":"2022-10-01T04:00:25.255779Z","iopub.execute_input":"2022-10-01T04:00:25.256190Z","iopub.status.idle":"2022-10-01T04:00:25.263466Z","shell.execute_reply.started":"2022-10-01T04:00:25.256156Z","shell.execute_reply":"2022-10-01T04:00:25.262340Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = plt.figure()\nax = plt.axes(projection='3d')\nax.contour3D(X, Y, Z, 50, cmap='binary')\nax.set_xlabel('x')\nax.set_ylabel('y')\nax.set_zlabel('z');","metadata":{"execution":{"iopub.status.busy":"2022-10-01T04:00:35.774484Z","iopub.execute_input":"2022-10-01T04:00:35.774993Z","iopub.status.idle":"2022-10-01T04:00:36.229825Z","shell.execute_reply.started":"2022-10-01T04:00:35.774955Z","shell.execute_reply":"2022-10-01T04:00:36.228757Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ax.view_init(60, 35)\nfig","metadata":{"execution":{"iopub.status.busy":"2022-10-01T04:00:46.700452Z","iopub.execute_input":"2022-10-01T04:00:46.701573Z","iopub.status.idle":"2022-10-01T04:00:46.972932Z","shell.execute_reply.started":"2022-10-01T04:00:46.701508Z","shell.execute_reply":"2022-10-01T04:00:46.971795Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = plt.figure()\nax = plt.axes(projection='3d')\nax.plot_wireframe(X, Y, Z, color='black')\nax.set_title('wireframe');","metadata":{"execution":{"iopub.status.busy":"2022-10-01T04:01:00.072234Z","iopub.execute_input":"2022-10-01T04:01:00.072651Z","iopub.status.idle":"2022-10-01T04:01:00.340788Z","shell.execute_reply.started":"2022-10-01T04:01:00.072610Z","shell.execute_reply":"2022-10-01T04:01:00.339685Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ax = plt.axes(projection='3d')\nax.plot_surface(X, Y, Z, rstride=1, cstride=1,\n                cmap='viridis', edgecolor='none')\nax.set_title('surface');","metadata":{"execution":{"iopub.status.busy":"2022-10-01T04:01:15.132637Z","iopub.execute_input":"2022-10-01T04:01:15.133154Z","iopub.status.idle":"2022-10-01T04:01:15.503479Z","shell.execute_reply.started":"2022-10-01T04:01:15.133100Z","shell.execute_reply":"2022-10-01T04:01:15.502045Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"r = np.linspace(0, 6, 20)\ntheta = np.linspace(-0.9 * np.pi, 0.8 * np.pi, 40)\nr, theta = np.meshgrid(r, theta)\n\nX = r * np.sin(theta)\nY = r * np.cos(theta)\nZ = f(X, Y)\n\nax = plt.axes(projection='3d')\nax.plot_surface(X, Y, Z, rstride=1, cstride=1,\n                cmap='viridis', edgecolor='none');","metadata":{"execution":{"iopub.status.busy":"2022-10-01T04:01:27.270432Z","iopub.execute_input":"2022-10-01T04:01:27.271229Z","iopub.status.idle":"2022-10-01T04:01:27.620998Z","shell.execute_reply.started":"2022-10-01T04:01:27.271191Z","shell.execute_reply":"2022-10-01T04:01:27.619850Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"theta = 2 * np.pi * np.random.random(1000)\nr = 6 * np.random.random(1000)\nx = np.ravel(r * np.sin(theta))\ny = np.ravel(r * np.cos(theta))\nz = f(x, y)","metadata":{"execution":{"iopub.status.busy":"2022-10-01T04:01:41.775504Z","iopub.execute_input":"2022-10-01T04:01:41.775976Z","iopub.status.idle":"2022-10-01T04:01:41.784431Z","shell.execute_reply.started":"2022-10-01T04:01:41.775939Z","shell.execute_reply":"2022-10-01T04:01:41.782861Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ax = plt.axes(projection='3d')\nax.scatter(x, y, z, c=z, cmap='viridis', linewidth=0.5);","metadata":{"execution":{"iopub.status.busy":"2022-10-01T04:01:54.003878Z","iopub.execute_input":"2022-10-01T04:01:54.004373Z","iopub.status.idle":"2022-10-01T04:01:54.296639Z","shell.execute_reply.started":"2022-10-01T04:01:54.004336Z","shell.execute_reply":"2022-10-01T04:01:54.295507Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ax = plt.axes(projection='3d')\nax.plot_trisurf(x, y, z,\n                cmap='viridis', edgecolor='none');","metadata":{"execution":{"iopub.status.busy":"2022-10-01T04:02:04.790086Z","iopub.execute_input":"2022-10-01T04:02:04.791042Z","iopub.status.idle":"2022-10-01T04:02:05.329156Z","shell.execute_reply.started":"2022-10-01T04:02:04.790986Z","shell.execute_reply":"2022-10-01T04:02:05.328042Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"theta = np.linspace(0, 2 * np.pi, 30)\nw = np.linspace(-0.25, 0.25, 8)\nw, theta = np.meshgrid(w, theta)","metadata":{"execution":{"iopub.status.busy":"2022-10-01T04:02:19.853989Z","iopub.execute_input":"2022-10-01T04:02:19.855172Z","iopub.status.idle":"2022-10-01T04:02:19.861842Z","shell.execute_reply.started":"2022-10-01T04:02:19.855095Z","shell.execute_reply":"2022-10-01T04:02:19.860753Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"phi = 0.5 * theta","metadata":{"execution":{"iopub.status.busy":"2022-10-01T04:02:30.381510Z","iopub.execute_input":"2022-10-01T04:02:30.381991Z","iopub.status.idle":"2022-10-01T04:02:30.387863Z","shell.execute_reply.started":"2022-10-01T04:02:30.381954Z","shell.execute_reply":"2022-10-01T04:02:30.386771Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# radius in x-y plane\nr = 1 + w * np.cos(phi)\n\nx = np.ravel(r * np.cos(theta))\ny = np.ravel(r * np.sin(theta))\nz = np.ravel(w * np.sin(phi))","metadata":{"execution":{"iopub.status.busy":"2022-10-01T04:02:39.582152Z","iopub.execute_input":"2022-10-01T04:02:39.582664Z","iopub.status.idle":"2022-10-01T04:02:39.589076Z","shell.execute_reply.started":"2022-10-01T04:02:39.582622Z","shell.execute_reply":"2022-10-01T04:02:39.588164Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# triangulate in the underlying parametrization\nfrom matplotlib.tri import Triangulation\ntri = Triangulation(np.ravel(w), np.ravel(theta))\n\nax = plt.axes(projection='3d')\nax.plot_trisurf(x, y, z, triangles=tri.triangles,\n                cmap='viridis', linewidths=0.2);\n\nax.set_xlim(-1, 1); ax.set_ylim(-1, 1); ax.set_zlim(-1, 1);","metadata":{"execution":{"iopub.status.busy":"2022-10-01T04:02:49.871532Z","iopub.execute_input":"2022-10-01T04:02:49.872027Z","iopub.status.idle":"2022-10-01T04:02:50.184898Z","shell.execute_reply.started":"2022-10-01T04:02:49.871989Z","shell.execute_reply":"2022-10-01T04:02:50.183769Z"},"trusted":true},"execution_count":null,"outputs":[]}]}