{"id":1079996,"date":"2025-01-08T12:26:06","date_gmt":"2025-01-08T04:26:06","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1079996.html"},"modified":"2025-01-08T12:26:10","modified_gmt":"2025-01-08T04:26:10","slug":"python%e5%a6%82%e4%bd%95%e7%94%bb%e4%b8%89%e7%bb%b4%e5%9b%be%e5%83%8f-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1079996.html","title":{"rendered":"python\u5982\u4f55\u753b\u4e09\u7ef4\u56fe\u50cf"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24182744\/689e2660-a297-4b74-bb25-dee63bd802d2.webp\" alt=\"python\u5982\u4f55\u753b\u4e09\u7ef4\u56fe\u50cf\" \/><\/p>\n<p><p> <strong>\u4f7f\u7528Python\u753b\u4e09\u7ef4\u56fe\u50cf\u7684\u65b9\u6cd5\u4e3b\u8981\u5305\u62ec\u4f7f\u7528Matplotlib\u5e93\u3001\u4f7f\u7528Mayavi\u5e93\u3001\u4f7f\u7528Plotly\u5e93\u3001\u4f7f\u7528VisPy\u5e93\u3002<\/strong> \u5176\u4e2d\uff0cMatplotlib\u662f\u6700\u5e38\u7528\u7684\u5e93\uff0c\u56e0\u4e3a\u5b83\u7b80\u5355\u6613\u7528\uff0c\u529f\u80fd\u5f3a\u5927\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528Matplotlib\u5e93\u6765\u7ed8\u5236\u4e09\u7ef4\u56fe\u50cf\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001MATPLOTLIB\u5e93<\/p>\n<\/p>\n<p><p>Matplotlib\u662fPython\u4e2d\u6700\u6d41\u884c\u7684\u7ed8\u56fe\u5e93\u4e4b\u4e00\uff0c\u5b83\u652f\u6301\u591a\u79cd\u7c7b\u578b\u7684\u56fe\u8868\uff0c\u5305\u62ec\u4e09\u7ef4\u56fe\u50cf\u3002\u4e3a\u4e86\u4f7f\u7528Matplotlib\u7ed8\u5236\u4e09\u7ef4\u56fe\u50cf\uff0c\u6211\u4eec\u9700\u8981\u5bfc\u5165<code>mpl_toolkits.mplot3d<\/code>\u6a21\u5757\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528Matplotlib\u7ed8\u5236\u4e09\u7ef4\u6563\u70b9\u56fe\u548c\u4e09\u7ef4\u66f2\u9762\u56fe\u3002<\/p>\n<\/p>\n<p><h3>1. \u5b89\u88c5\u548c\u5bfc\u5165Matplotlib\u5e93<\/h3>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5\u4e86Matplotlib\u5e93\u3002\u5982\u679c\u6ca1\u6709\u5b89\u88c5\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install matplotlib<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\uff0c\u5728Python\u811a\u672c\u4e2d\u5bfc\u5165\u76f8\u5173\u6a21\u5757\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>from mpl_toolkits.mplot3d import Axes3D<\/p>\n<p>import numpy as np<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2. \u7ed8\u5236\u4e09\u7ef4\u6563\u70b9\u56fe<\/h3>\n<\/p>\n<p><p>\u4e09\u7ef4\u6563\u70b9\u56fe\u7528\u4e8e\u663e\u793a\u6570\u636e\u70b9\u5728\u4e09\u7ef4\u7a7a\u95f4\u4e2d\u7684\u5206\u5e03\u60c5\u51b5\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u751f\u6210\u6570\u636e<\/p>\n<p>np.random.seed(0)<\/p>\n<p>x = np.random.rand(100)<\/p>\n<p>y = np.random.rand(100)<\/p>\n<p>z = np.random.rand(100)<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u56fe\u5f62\u5bf9\u8c61<\/strong><\/h2>\n<p>fig = plt.figure()<\/p>\n<p>ax = fig.add_subplot(111, projection=&#39;3d&#39;)<\/p>\n<h2><strong>\u7ed8\u5236\u4e09\u7ef4\u6563\u70b9\u56fe<\/strong><\/h2>\n<p>ax.scatter(x, y, z, c=&#39;r&#39;, marker=&#39;o&#39;)<\/p>\n<h2><strong>\u8bbe\u7f6e\u5750\u6807\u8f74\u6807\u7b7e<\/strong><\/h2>\n<p>ax.set_xlabel(&#39;X Label&#39;)<\/p>\n<p>ax.set_ylabel(&#39;Y Label&#39;)<\/p>\n<p>ax.set_zlabel(&#39;Z Label&#39;)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u5f62<\/strong><\/h2>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u751f\u6210\u4e00\u4e9b\u968f\u673a\u6570\u636e\uff0c\u7136\u540e\u4f7f\u7528<code>scatter<\/code>\u65b9\u6cd5\u7ed8\u5236\u4e09\u7ef4\u6563\u70b9\u56fe\u3002\u6211\u4eec\u8fd8\u8bbe\u7f6e\u4e86\u5750\u6807\u8f74\u7684\u6807\u7b7e\uff0c\u6700\u540e\u4f7f\u7528<code>show<\/code>\u65b9\u6cd5\u663e\u793a\u56fe\u5f62\u3002<\/p>\n<\/p>\n<p><h3>3. \u7ed8\u5236\u4e09\u7ef4\u66f2\u9762\u56fe<\/h3>\n<\/p>\n<p><p>\u4e09\u7ef4\u66f2\u9762\u56fe\u7528\u4e8e\u663e\u793a\u4e00\u4e2a\u51fd\u6570\u5728\u4e09\u7ef4\u7a7a\u95f4\u4e2d\u7684\u53d8\u5316\u60c5\u51b5\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u751f\u6210\u6570\u636e<\/p>\n<p>x = np.linspace(-5, 5, 100)<\/p>\n<p>y = np.linspace(-5, 5, 100)<\/p>\n<p>x, y = np.meshgrid(x, y)<\/p>\n<p>z = np.sin(np.sqrt(x&lt;strong&gt;2 + y&lt;\/strong&gt;2))<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u56fe\u5f62\u5bf9\u8c61<\/strong><\/h2>\n<p>fig = plt.figure()<\/p>\n<p>ax = fig.add_subplot(111, projection=&#39;3d&#39;)<\/p>\n<h2><strong>\u7ed8\u5236\u4e09\u7ef4\u66f2\u9762\u56fe<\/strong><\/h2>\n<p>ax.plot_surface(x, y, z, cmap=&#39;viridis&#39;)<\/p>\n<h2><strong>\u8bbe\u7f6e\u5750\u6807\u8f74\u6807\u7b7e<\/strong><\/h2>\n<p>ax.set_xlabel(&#39;X Label&#39;)<\/p>\n<p>ax.set_ylabel(&#39;Y Label&#39;)<\/p>\n<p>ax.set_zlabel(&#39;Z Label&#39;)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u5f62<\/strong><\/h2>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>meshgrid<\/code>\u65b9\u6cd5\u751f\u6210\u7f51\u683c\u6570\u636e\uff0c\u7136\u540e\u8ba1\u7b97\u51fd\u6570\u503c\u3002\u63a5\u7740\uff0c\u4f7f\u7528<code>plot_surface<\/code>\u65b9\u6cd5\u7ed8\u5236\u4e09\u7ef4\u66f2\u9762\u56fe\uff0c\u5e76\u4f7f\u7528<code>cmap<\/code>\u53c2\u6570\u6307\u5b9a\u989c\u8272\u6620\u5c04\u3002\u6700\u540e\uff0c\u8bbe\u7f6e\u5750\u6807\u8f74\u6807\u7b7e\u5e76\u663e\u793a\u56fe\u5f62\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001MAYAVI\u5e93<\/p>\n<\/p>\n<p><p>Mayavi\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u4e09\u7ef4\u6570\u636e\u53ef\u89c6\u5316\u5e93\uff0c\u9002\u7528\u4e8e\u9700\u8981\u9ad8\u7ea7\u53ef\u89c6\u5316\u529f\u80fd\u7684\u7528\u6237\u3002Mayavi\u5efa\u7acb\u5728VTK\uff08Visualization Toolkit\uff09\u4e4b\u4e0a\uff0c\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u4e09\u7ef4\u7ed8\u56fe\u529f\u80fd\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528Mayavi\u7ed8\u5236\u4e09\u7ef4\u56fe\u50cf\u3002<\/p>\n<\/p>\n<p><h3>1. \u5b89\u88c5\u548c\u5bfc\u5165Mayavi\u5e93<\/h3>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5b89\u88c5Mayavi\u5e93\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install mayavi<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\uff0c\u5728Python\u811a\u672c\u4e2d\u5bfc\u5165\u76f8\u5173\u6a21\u5757\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from mayavi import mlab<\/p>\n<p>import numpy as np<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2. \u7ed8\u5236\u4e09\u7ef4\u66f2\u9762\u56fe<\/h3>\n<\/p>\n<p><pre><code class=\"language-python\"># \u751f\u6210\u6570\u636e<\/p>\n<p>x, y = np.mgrid[-5:5:100j, -5:5:100j]<\/p>\n<p>z = np.sin(np.sqrt(x&lt;strong&gt;2 + y&lt;\/strong&gt;2))<\/p>\n<h2><strong>\u7ed8\u5236\u4e09\u7ef4\u66f2\u9762\u56fe<\/strong><\/h2>\n<p>mlab.surf(x, y, z, colormap=&#39;viridis&#39;)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u5f62<\/strong><\/h2>\n<p>mlab.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>mgrid<\/code>\u65b9\u6cd5\u751f\u6210\u7f51\u683c\u6570\u636e\uff0c\u7136\u540e\u8ba1\u7b97\u51fd\u6570\u503c\u3002\u63a5\u7740\uff0c\u4f7f\u7528<code>surf<\/code>\u65b9\u6cd5\u7ed8\u5236\u4e09\u7ef4\u66f2\u9762\u56fe\uff0c\u5e76\u4f7f\u7528<code>colormap<\/code>\u53c2\u6570\u6307\u5b9a\u989c\u8272\u6620\u5c04\u3002\u6700\u540e\uff0c\u4f7f\u7528<code>show<\/code>\u65b9\u6cd5\u663e\u793a\u56fe\u5f62\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001PLOTLY\u5e93<\/p>\n<\/p>\n<p><p>Plotly\u662f\u4e00\u4e2a\u7528\u4e8e\u521b\u5efa\u4ea4\u4e92\u5f0f\u56fe\u8868\u7684\u5f00\u6e90\u5e93\uff0c\u652f\u6301\u591a\u79cd\u7c7b\u578b\u7684\u56fe\u8868\uff0c\u5305\u62ec\u4e09\u7ef4\u56fe\u50cf\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528Plotly\u7ed8\u5236\u4e09\u7ef4\u6563\u70b9\u56fe\u548c\u4e09\u7ef4\u66f2\u9762\u56fe\u3002<\/p>\n<\/p>\n<p><h3>1. \u5b89\u88c5\u548c\u5bfc\u5165Plotly\u5e93<\/h3>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5b89\u88c5Plotly\u5e93\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install plotly<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\uff0c\u5728Python\u811a\u672c\u4e2d\u5bfc\u5165\u76f8\u5173\u6a21\u5757\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import plotly.graph_objects as go<\/p>\n<p>import numpy as np<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2. \u7ed8\u5236\u4e09\u7ef4\u6563\u70b9\u56fe<\/h3>\n<\/p>\n<p><pre><code class=\"language-python\"># \u751f\u6210\u6570\u636e<\/p>\n<p>np.random.seed(0)<\/p>\n<p>x = np.random.rand(100)<\/p>\n<p>y = np.random.rand(100)<\/p>\n<p>z = np.random.rand(100)<\/p>\n<h2><strong>\u521b\u5efa\u4e09\u7ef4\u6563\u70b9\u56fe<\/strong><\/h2>\n<p>fig = go.Figure(data=[go.Scatter3d(x=x, y=y, z=z, mode=&#39;markers&#39;)])<\/p>\n<h2><strong>\u8bbe\u7f6e\u5750\u6807\u8f74\u6807\u7b7e<\/strong><\/h2>\n<p>fig.update_layout(scene=dict(<\/p>\n<p>    xaxis_title=&#39;X Label&#39;,<\/p>\n<p>    yaxis_title=&#39;Y Label&#39;,<\/p>\n<p>    zaxis_title=&#39;Z Label&#39;<\/p>\n<p>))<\/p>\n<h2><strong>\u663e\u793a\u56fe\u5f62<\/strong><\/h2>\n<p>fig.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u751f\u6210\u4e00\u4e9b\u968f\u673a\u6570\u636e\uff0c\u7136\u540e\u4f7f\u7528<code>Scatter3d<\/code>\u65b9\u6cd5\u521b\u5efa\u4e09\u7ef4\u6563\u70b9\u56fe\u3002\u63a5\u7740\uff0c\u8bbe\u7f6e\u5750\u6807\u8f74\u6807\u7b7e\uff0c\u5e76\u4f7f\u7528<code>show<\/code>\u65b9\u6cd5\u663e\u793a\u56fe\u5f62\u3002<\/p>\n<\/p>\n<p><h3>3. \u7ed8\u5236\u4e09\u7ef4\u66f2\u9762\u56fe<\/h3>\n<\/p>\n<p><pre><code class=\"language-python\"># \u751f\u6210\u6570\u636e<\/p>\n<p>x = np.linspace(-5, 5, 100)<\/p>\n<p>y = np.linspace(-5, 5, 100)<\/p>\n<p>x, y = np.meshgrid(x, y)<\/p>\n<p>z = np.sin(np.sqrt(x&lt;strong&gt;2 + y&lt;\/strong&gt;2))<\/p>\n<h2><strong>\u521b\u5efa\u4e09\u7ef4\u66f2\u9762\u56fe<\/strong><\/h2>\n<p>fig = go.Figure(data=[go.Surface(z=z, x=x, y=y)])<\/p>\n<h2><strong>\u8bbe\u7f6e\u5750\u6807\u8f74\u6807\u7b7e<\/strong><\/h2>\n<p>fig.update_layout(scene=dict(<\/p>\n<p>    xaxis_title=&#39;X Label&#39;,<\/p>\n<p>    yaxis_title=&#39;Y Label&#39;,<\/p>\n<p>    zaxis_title=&#39;Z Label&#39;<\/p>\n<p>))<\/p>\n<h2><strong>\u663e\u793a\u56fe\u5f62<\/strong><\/h2>\n<p>fig.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>meshgrid<\/code>\u65b9\u6cd5\u751f\u6210\u7f51\u683c\u6570\u636e\uff0c\u7136\u540e\u8ba1\u7b97\u51fd\u6570\u503c\u3002\u63a5\u7740\uff0c\u4f7f\u7528<code>Surface<\/code>\u65b9\u6cd5\u521b\u5efa\u4e09\u7ef4\u66f2\u9762\u56fe\uff0c\u5e76\u8bbe\u7f6e\u5750\u6807\u8f74\u6807\u7b7e\u3002\u6700\u540e\uff0c\u4f7f\u7528<code>show<\/code>\u65b9\u6cd5\u663e\u793a\u56fe\u5f62\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001VISPY\u5e93<\/p>\n<\/p>\n<p><p>VisPy\u662f\u4e00\u4e2a\u9ad8\u6027\u80fd\u7684\u4ea4\u4e92\u5f0f\u53ef\u89c6\u5316\u5e93\uff0c\u9002\u7528\u4e8e\u9700\u8981\u9ad8\u6548\u6e32\u67d3\u7684\u7528\u6237\u3002VisPy\u5efa\u7acb\u5728OpenGL\u4e4b\u4e0a\uff0c\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u4e09\u7ef4\u7ed8\u56fe\u529f\u80fd\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528VisPy\u7ed8\u5236\u4e09\u7ef4\u56fe\u50cf\u3002<\/p>\n<\/p>\n<p><h3>1. \u5b89\u88c5\u548c\u5bfc\u5165VisPy\u5e93<\/h3>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5b89\u88c5VisPy\u5e93\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install vispy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\uff0c\u5728Python\u811a\u672c\u4e2d\u5bfc\u5165\u76f8\u5173\u6a21\u5757\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from vispy import scene<\/p>\n<p>from vispy import app<\/p>\n<p>import numpy as np<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2. \u7ed8\u5236\u4e09\u7ef4\u6563\u70b9\u56fe<\/h3>\n<\/p>\n<p><pre><code class=\"language-python\"># \u521b\u5efa\u753b\u5e03<\/p>\n<p>canvas = scene.SceneCanvas(keys=&#39;interactive&#39;, show=True)<\/p>\n<p>view = canvas.central_widget.add_view()<\/p>\n<h2><strong>\u751f\u6210\u6570\u636e<\/strong><\/h2>\n<p>np.random.seed(0)<\/p>\n<p>x = np.random.rand(100)<\/p>\n<p>y = np.random.rand(100)<\/p>\n<p>z = np.random.rand(100)<\/p>\n<h2><strong>\u521b\u5efa\u4e09\u7ef4\u6563\u70b9\u56fe<\/strong><\/h2>\n<p>scatter = scene.visuals.Markers()<\/p>\n<p>scatter.set_data(np.vstack((x, y, z)).T, edge_color=None, face_color=(1, 0, 0, 1), size=5)<\/p>\n<h2><strong>\u6dfb\u52a0\u5230\u89c6\u56fe<\/strong><\/h2>\n<p>view.add(scatter)<\/p>\n<h2><strong>\u8bbe\u7f6e\u89c6\u56fe\u5c5e\u6027<\/strong><\/h2>\n<p>view.camera = &#39;turntable&#39;<\/p>\n<p>view.camera.fov = 45<\/p>\n<h2><strong>\u663e\u793a\u56fe\u5f62<\/strong><\/h2>\n<p>if __name__ == &#39;__m<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n__&#39;:<\/p>\n<p>    app.run()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u521b\u5efa\u4e00\u4e2a\u753b\u5e03\uff0c\u7136\u540e\u751f\u6210\u4e00\u4e9b\u968f\u673a\u6570\u636e\u3002\u63a5\u7740\uff0c\u4f7f\u7528<code>Markers<\/code>\u65b9\u6cd5\u521b\u5efa\u4e09\u7ef4\u6563\u70b9\u56fe\uff0c\u5e76\u8bbe\u7f6e\u6570\u636e\u3002\u6700\u540e\uff0c\u6dfb\u52a0\u6563\u70b9\u56fe\u5230\u89c6\u56fe\uff0c\u5e76\u8bbe\u7f6e\u89c6\u56fe\u5c5e\u6027\uff0c\u4f7f\u7528<code>run<\/code>\u65b9\u6cd5\u663e\u793a\u56fe\u5f62\u3002<\/p>\n<\/p>\n<p><h3>3. \u7ed8\u5236\u4e09\u7ef4\u66f2\u9762\u56fe<\/h3>\n<\/p>\n<p><pre><code class=\"language-python\"># \u521b\u5efa\u753b\u5e03<\/p>\n<p>canvas = scene.SceneCanvas(keys=&#39;interactive&#39;, show=True)<\/p>\n<p>view = canvas.central_widget.add_view()<\/p>\n<h2><strong>\u751f\u6210\u6570\u636e<\/strong><\/h2>\n<p>x = np.linspace(-5, 5, 100)<\/p>\n<p>y = np.linspace(-5, 5, 100)<\/p>\n<p>x, y = np.meshgrid(x, y)<\/p>\n<p>z = np.sin(np.sqrt(x&lt;strong&gt;2 + y&lt;\/strong&gt;2))<\/p>\n<h2><strong>\u521b\u5efa\u4e09\u7ef4\u66f2\u9762\u56fe<\/strong><\/h2>\n<p>surface = scene.visuals.SurfacePlot(x=x, y=y, z=z, color=(0, 0.5, 1, 1))<\/p>\n<h2><strong>\u6dfb\u52a0\u5230\u89c6\u56fe<\/strong><\/h2>\n<p>view.add(surface)<\/p>\n<h2><strong>\u8bbe\u7f6e\u89c6\u56fe\u5c5e\u6027<\/strong><\/h2>\n<p>view.camera = &#39;turntable&#39;<\/p>\n<p>view.camera.fov = 45<\/p>\n<h2><strong>\u663e\u793a\u56fe\u5f62<\/strong><\/h2>\n<p>if __name__ == &#39;__main__&#39;:<\/p>\n<p>    app.run()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>meshgrid<\/code>\u65b9\u6cd5\u751f\u6210\u7f51\u683c\u6570\u636e\uff0c\u7136\u540e\u8ba1\u7b97\u51fd\u6570\u503c\u3002\u63a5\u7740\uff0c\u4f7f\u7528<code>SurfacePlot<\/code>\u65b9\u6cd5\u521b\u5efa\u4e09\u7ef4\u66f2\u9762\u56fe\uff0c\u5e76\u8bbe\u7f6e\u6570\u636e\u3002\u6700\u540e\uff0c\u6dfb\u52a0\u66f2\u9762\u56fe\u5230\u89c6\u56fe\uff0c\u5e76\u8bbe\u7f6e\u89c6\u56fe\u5c5e\u6027\uff0c\u4f7f\u7528<code>run<\/code>\u65b9\u6cd5\u663e\u793a\u56fe\u5f62\u3002<\/p>\n<\/p>\n<p><p>\u603b\u7ed3<\/p>\n<\/p>\n<p><p>Python\u63d0\u4f9b\u4e86\u591a\u79cd\u7ed8\u5236\u4e09\u7ef4\u56fe\u50cf\u7684\u5e93\uff0c\u5305\u62ecMatplotlib\u3001Mayavi\u3001Plotly\u548cVisPy\u3002\u6bcf\u4e2a\u5e93\u90fd\u6709\u5176\u4f18\u7f3a\u70b9\u548c\u9002\u7528\u573a\u666f\u3002Matplotlib\u9002\u7528\u4e8e\u7b80\u5355\u7684\u4e09\u7ef4\u7ed8\u56fe\u4efb\u52a1\uff0cMayavi\u9002\u7528\u4e8e\u9ad8\u7ea7\u53ef\u89c6\u5316\u9700\u6c42\uff0cPlotly\u9002\u7528\u4e8e\u521b\u5efa\u4ea4\u4e92\u5f0f\u56fe\u8868\uff0c\u800cVisPy\u9002\u7528\u4e8e\u9ad8\u6027\u80fd\u6e32\u67d3\u9700\u6c42\u3002\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u5e93\uff0c\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u66f4\u597d\u5730\u8fdb\u884c\u6570\u636e\u53ef\u89c6\u5316\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u7ed8\u5236\u4e09\u7ef4\u56fe\u50cf\uff1f<\/strong><br \/>\u5728Python\u4e2d\u7ed8\u5236\u4e09\u7ef4\u56fe\u50cf\u901a\u5e38\u4f7f\u7528Matplotlib\u5e93\u7684mplot3d\u6a21\u5757\u3002\u9996\u5148\uff0c\u786e\u4fdd\u5b89\u88c5\u4e86Matplotlib\u5e93\u3002\u7136\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528<code>Axes3D<\/code>\u521b\u5efa\u4e09\u7ef4\u5750\u6807\u8f74\uff0c\u5e76\u4f7f\u7528\u4e0d\u540c\u7684\u7ed8\u56fe\u51fd\u6570\uff08\u5982scatter\u3001plot_surface\u7b49\uff09\u6765\u7ed8\u5236\u6570\u636e\u3002\u4f8b\u5982\uff0c\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684\u4e09\u7ef4\u6563\u70b9\u56fe\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<pre><code class=\"language-python\">import matplotlib.pyplot as plt\nfrom mpl_toolkits.mplot3d import Axes3D\nimport numpy as np\n\nfig = plt.figure()\nax = fig.add_subplot(111, projection=&#39;3d&#39;)\nx = np.random.rand(100)\ny = np.random.rand(100)\nz = np.random.rand(100)\nax.scatter(x, y, z)\nplt.show()\n<\/code><\/pre>\n<p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u60a8\u53ef\u4ee5\u8f7b\u677e\u5730\u5728\u4e09\u7ef4\u7a7a\u95f4\u4e2d\u53ef\u89c6\u5316\u6570\u636e\u3002<\/p>\n<p><strong>\u6709\u54ea\u4e9bPython\u5e93\u53ef\u4ee5\u7528\u4e8e\u4e09\u7ef4\u53ef\u89c6\u5316\uff1f<\/strong><br \/>\u9664\u4e86Matplotlib\uff0cPython\u4e2d\u8fd8\u6709\u5176\u4ed6\u5e93\u53ef\u4ee5\u8fdb\u884c\u4e09\u7ef4\u53ef\u89c6\u5316\uff0c\u5982Mayavi\u3001Plotly\u548cVisPy\u7b49\u3002Mayavi\u9002\u5408\u5904\u7406\u79d1\u5b66\u8ba1\u7b97\u548c\u590d\u6742\u7684\u4e09\u7ef4\u573a\u666f\uff0cPlotly\u63d0\u4f9b\u4ea4\u4e92\u5f0f\u56fe\u8868\uff0c\u9002\u5408Web\u5e94\u7528\u7a0b\u5e8f\uff0c\u800cVisPy\u5219\u6ce8\u91cd\u9ad8\u6027\u80fd\u548c\u5b9e\u65f6\u6e32\u67d3\u3002\u6839\u636e\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u5e93\uff0c\u53ef\u4ee5\u66f4\u597d\u5730\u6ee1\u8db3\u53ef\u89c6\u5316\u7684\u8981\u6c42\u3002<\/p>\n<p><strong>\u5728\u7ed8\u5236\u4e09\u7ef4\u56fe\u50cf\u65f6\u5e94\u6ce8\u610f\u54ea\u4e9b\u4e8b\u9879\uff1f<\/strong><br \/>\u7ed8\u5236\u4e09\u7ef4\u56fe\u50cf\u65f6\uff0c\u9700\u8981\u8003\u8651\u5750\u6807\u8f74\u7684\u8303\u56f4\u3001\u89c6\u89d2\u4ee5\u53ca\u6570\u636e\u7684\u5206\u5e03\u60c5\u51b5\u3002\u8fd9\u4e9b\u56e0\u7d20\u4f1a\u5f71\u54cd\u56fe\u50cf\u7684\u53ef\u8bfb\u6027\u3002\u6b64\u5916\uff0c\u5408\u7406\u9009\u62e9\u989c\u8272\u548c\u6807\u8bb0\u6837\u5f0f\u4e5f\u662f\u91cd\u8981\u7684\uff0c\u4ee5\u4fbf\u6709\u6548\u533a\u5206\u4e0d\u540c\u7684\u6570\u636e\u70b9\u6216\u6570\u636e\u96c6\u3002\u4f7f\u7528\u5408\u9002\u7684\u6807\u9898\u548c\u6807\u7b7e\u53ef\u4ee5\u5e2e\u52a9\u89c2\u4f17\u66f4\u597d\u5730\u7406\u89e3\u56fe\u50cf\u6240\u8868\u8fbe\u7684\u4fe1\u606f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u4f7f\u7528Python\u753b\u4e09\u7ef4\u56fe\u50cf\u7684\u65b9\u6cd5\u4e3b\u8981\u5305\u62ec\u4f7f\u7528Matplotlib\u5e93\u3001\u4f7f\u7528Mayavi\u5e93\u3001\u4f7f\u7528Plotly\u5e93\u3001\u4f7f [&hellip;]","protected":false},"author":3,"featured_media":1080010,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1079996"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1079996"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1079996\/revisions"}],"predecessor-version":[{"id":1080011,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1079996\/revisions\/1080011"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1080010"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1079996"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1079996"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1079996"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}