{"id":1128600,"date":"2025-01-08T20:22:09","date_gmt":"2025-01-08T12:22:09","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1128600.html"},"modified":"2025-01-08T20:22:12","modified_gmt":"2025-01-08T12:22:12","slug":"python%e7%94%bb%e7%9a%84%e4%b8%89%e7%bb%b4%e5%9b%be%e5%a6%82%e4%bd%95%e4%bf%9d%e5%ad%98","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1128600.html","title":{"rendered":"python\u753b\u7684\u4e09\u7ef4\u56fe\u5982\u4f55\u4fdd\u5b58"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25095242\/c397ea0d-1fff-4456-8f66-65745ce877ee.webp\" alt=\"python\u753b\u7684\u4e09\u7ef4\u56fe\u5982\u4f55\u4fdd\u5b58\" \/><\/p>\n<p><p> <strong>Python \u753b\u7684\u4e09\u7ef4\u56fe\u5982\u4f55\u4fdd\u5b58<\/strong>\uff1a<strong>\u4f7f\u7528Matplotlib\u7684savefig\u65b9\u6cd5\u3001\u4f7f\u7528Mayavi\u7684mlab.savefig\u65b9\u6cd5\u3001\u786e\u4fdd\u6b63\u786e\u8bbe\u7f6e\u6587\u4ef6\u8def\u5f84\u548c\u683c\u5f0f<\/strong>\u3002\u5728\u8be6\u7ec6\u63cf\u8ff0\u4e2d\uff0c\u6211\u4eec\u5c06\u63a2\u8ba8\u5982\u4f55\u4f7f\u7528Matplotlib\u548cMayavi\u8fd9\u4e24\u4e2a\u5e38\u7528\u5de5\u5177\u6765\u4fdd\u5b58\u4e09\u7ef4\u56fe\uff0c\u4ee5\u53ca\u4e00\u4e9b\u5728\u4fdd\u5b58\u8fc7\u7a0b\u4e2d\u9700\u8981\u6ce8\u610f\u7684\u6280\u5de7\u548c\u6700\u4f73\u5b9e\u8df5\u3002<\/p>\n<\/p>\n<hr>\n<p><h3>\u4e00\u3001\u4f7f\u7528Matplotlib\u7684savefig\u65b9\u6cd5<\/h3>\n<\/p>\n<p><p>Matplotlib \u662f Python \u4e2d\u975e\u5e38\u6d41\u884c\u7684\u7ed8\u56fe\u5e93\uff0c\u652f\u6301\u4e8c\u7ef4\u548c\u4e09\u7ef4\u56fe\u5f62\u7684\u7ed8\u5236\u3002\u8981\u4fdd\u5b58\u4e09\u7ef4\u56fe\u5f62\uff0c\u9996\u5148\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u4e09\u7ef4\u56fe\u5f62\uff0c\u7136\u540e\u4f7f\u7528 <code>savefig<\/code> \u65b9\u6cd5\u5c06\u5176\u4fdd\u5b58\u4e3a\u56fe\u50cf\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><h4>1.1 \u521b\u5efa\u4e09\u7ef4\u56fe\u5f62<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5bfc\u5165\u5fc5\u8981\u7684\u6a21\u5757\u5e76\u521b\u5efa\u4e00\u4e2a\u4e09\u7ef4\u56fe\u5f62\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\u4ee3\u7801\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>fig = plt.figure()<\/p>\n<p>ax = fig.add_subplot(111, projection=&#39;3d&#39;)<\/p>\n<h2><strong>\u521b\u5efa\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>\u7ed8\u5236\u56fe\u5f62<\/strong><\/h2>\n<p>ax.plot_surface(X, Y, Z, cmap=&#39;viridis&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>1.2 \u4f7f\u7528savefig\u65b9\u6cd5\u4fdd\u5b58\u56fe\u5f62<\/h4>\n<\/p>\n<p><p>\u5b8c\u6210\u4e09\u7ef4\u56fe\u5f62\u7ed8\u5236\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>savefig<\/code> \u65b9\u6cd5\u5c06\u5176\u4fdd\u5b58\u4e3a\u6587\u4ef6\u3002<code>savefig<\/code> \u65b9\u6cd5\u5141\u8bb8\u6307\u5b9a\u6587\u4ef6\u540d\u548c\u683c\u5f0f\uff0c\u4f8b\u5982 <code>.png<\/code>\u3001<code>.jpg<\/code> \u6216 <code>.pdf<\/code>\u3002\u4ee5\u4e0b\u662f\u4fdd\u5b58\u56fe\u5f62\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.savefig(&#39;3d_plot.png&#39;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>1.3 \u8bbe\u7f6e\u56fe\u5f62\u7684\u5206\u8fa8\u7387\u548c\u8d28\u91cf<\/h4>\n<\/p>\n<p><p>\u5728\u4fdd\u5b58\u56fe\u5f62\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7 <code>dpi<\/code> \u53c2\u6570\u8bbe\u7f6e\u56fe\u5f62\u7684\u5206\u8fa8\u7387\uff0c\u4ee5\u63d0\u9ad8\u56fe\u50cf\u7684\u8d28\u91cf\u3002\u6b64\u5916\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>bbox_inches<\/code> \u53c2\u6570\u6765\u786e\u4fdd\u56fe\u5f62\u7684\u8fb9\u754c\u88ab\u6b63\u786e\u4fdd\u5b58\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.savefig(&#39;3d_plot_high_res.png&#39;, dpi=300, bbox_inches=&#39;tight&#39;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528Mayavi\u7684mlab.savefig\u65b9\u6cd5<\/h3>\n<\/p>\n<p><p>Mayavi \u662f\u53e6\u4e00\u4e2a\u7528\u4e8e\u4e09\u7ef4\u6570\u636e\u53ef\u89c6\u5316\u7684\u5f3a\u5927\u5de5\u5177\uff0c\u5c24\u5176\u9002\u5408\u5904\u7406\u590d\u6742\u7684\u4e09\u7ef4\u56fe\u5f62\u3002Mayavi \u63d0\u4f9b\u4e86 <code>mlab.savefig<\/code> \u65b9\u6cd5\u6765\u4fdd\u5b58\u4e09\u7ef4\u56fe\u5f62\u3002<\/p>\n<\/p>\n<p><h4>2.1 \u521b\u5efa\u4e09\u7ef4\u56fe\u5f62<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5bfc\u5165\u5fc5\u8981\u7684\u6a21\u5757\u5e76\u521b\u5efa\u4e00\u4e2a\u4e09\u7ef4\u56fe\u5f62\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from mayavi import mlab<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u6570\u636e<\/strong><\/h2>\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\u56fe\u5f62<\/strong><\/h2>\n<p>mlab.figure(size=(800, 600))<\/p>\n<p>mlab.surf(x, y, z, colormap=&#39;viridis&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2.2 \u4f7f\u7528mlab.savefig\u65b9\u6cd5\u4fdd\u5b58\u56fe\u5f62<\/h4>\n<\/p>\n<p><p>\u5b8c\u6210\u4e09\u7ef4\u56fe\u5f62\u7ed8\u5236\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>mlab.savefig<\/code> \u65b9\u6cd5\u5c06\u5176\u4fdd\u5b58\u4e3a\u6587\u4ef6\u3002<code>mlab.savefig<\/code> \u65b9\u6cd5\u5141\u8bb8\u6307\u5b9a\u6587\u4ef6\u540d\u548c\u683c\u5f0f\uff0c\u4f8b\u5982 <code>.png<\/code> \u6216 <code>.jpg<\/code>\u3002\u4ee5\u4e0b\u662f\u4fdd\u5b58\u56fe\u5f62\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">mlab.savefig(&#39;mayavi_3d_plot.png&#39;)<\/p>\n<p>mlab.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2.3 \u8bbe\u7f6e\u56fe\u5f62\u7684\u5206\u8fa8\u7387\u548c\u8d28\u91cf<\/h4>\n<\/p>\n<p><p>\u5728\u4fdd\u5b58\u56fe\u5f62\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7 <code>size<\/code> \u53c2\u6570\u8bbe\u7f6e\u56fe\u5f62\u7684\u5206\u8fa8\u7387\uff0c\u4ee5\u63d0\u9ad8\u56fe\u50cf\u7684\u8d28\u91cf\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">mlab.savefig(&#39;mayavi_3d_plot_high_res.png&#39;, size=(1600, 1200))<\/p>\n<p>mlab.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u786e\u4fdd\u6b63\u786e\u8bbe\u7f6e\u6587\u4ef6\u8def\u5f84\u548c\u683c\u5f0f<\/h3>\n<\/p>\n<p><p>\u5728\u4fdd\u5b58\u56fe\u5f62\u65f6\uff0c\u786e\u4fdd\u6587\u4ef6\u8def\u5f84\u548c\u683c\u5f0f\u8bbe\u7f6e\u6b63\u786e\u975e\u5e38\u91cd\u8981\u3002\u8fd9\u4e0d\u4ec5\u80fd\u5e2e\u52a9\u4f60\u7ba1\u7406\u6587\u4ef6\uff0c\u8fd8\u80fd\u786e\u4fdd\u56fe\u50cf\u7684\u517c\u5bb9\u6027\u548c\u8d28\u91cf\u3002<\/p>\n<\/p>\n<p><h4>3.1 \u8bbe\u7f6e\u6587\u4ef6\u8def\u5f84<\/h4>\n<\/p>\n<p><p>\u5728\u4fdd\u5b58\u56fe\u5f62\u65f6\uff0c\u6587\u4ef6\u8def\u5f84\u53ef\u4ee5\u662f\u76f8\u5bf9\u8def\u5f84\u6216\u7edd\u5bf9\u8def\u5f84\u3002\u76f8\u5bf9\u8def\u5f84\u662f\u57fa\u4e8e\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\u7684\uff0c\u800c\u7edd\u5bf9\u8def\u5f84\u662f\u4ece\u6839\u76ee\u5f55\u5f00\u59cb\u7684\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u4f7f\u7528\u76f8\u5bf9\u8def\u5f84<\/p>\n<p>plt.savefig(&#39;.\/images\/3d_plot.png&#39;)<\/p>\n<h2><strong>\u4f7f\u7528\u7edd\u5bf9\u8def\u5f84<\/strong><\/h2>\n<p>plt.savefig(&#39;\/home\/user\/images\/3d_plot.png&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3.2 \u9009\u62e9\u5408\u9002\u7684\u6587\u4ef6\u683c\u5f0f<\/h4>\n<\/p>\n<p><p>\u4e0d\u540c\u7684\u6587\u4ef6\u683c\u5f0f\u6709\u4e0d\u540c\u7684\u7528\u9014\u548c\u4f18\u7f3a\u70b9\u3002\u5e38\u89c1\u7684\u6587\u4ef6\u683c\u5f0f\u5305\u62ec <code>.png<\/code>\u3001<code>.jpg<\/code>\u3001<code>.pdf<\/code> \u548c <code>.svg<\/code>\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u683c\u5f0f\u7684\u8bf4\u660e\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>PNG<\/strong>\uff1a\u65e0\u635f\u538b\u7f29\uff0c\u9002\u5408\u9ad8\u8d28\u91cf\u7684\u56fe\u50cf\u3002<\/li>\n<li><strong>JPG<\/strong>\uff1a\u6709\u635f\u538b\u7f29\uff0c\u9002\u5408\u7167\u7247\u548c\u8f83\u5c0f\u6587\u4ef6\u5927\u5c0f\u7684\u56fe\u50cf\u3002<\/li>\n<li><strong>PDF<\/strong>\uff1a\u9002\u5408\u77e2\u91cf\u56fe\u5f62\u548c\u9ad8\u8d28\u91cf\u6253\u5370\u3002<\/li>\n<li><strong>SVG<\/strong>\uff1a\u77e2\u91cf\u683c\u5f0f\uff0c\u9002\u5408\u7f51\u9875\u548c\u9ad8\u8d28\u91cf\u7684\u56fe\u5f62\u3002<\/li>\n<\/ul>\n<p><h3>\u56db\u3001\u6ce8\u610f\u4e8b\u9879\u548c\u6700\u4f73\u5b9e\u8df5<\/h3>\n<\/p>\n<p><p>\u5728\u4fdd\u5b58\u4e09\u7ef4\u56fe\u5f62\u65f6\uff0c\u6709\u4e00\u4e9b\u6ce8\u610f\u4e8b\u9879\u548c\u6700\u4f73\u5b9e\u8df5\u53ef\u4ee5\u5e2e\u52a9\u4f60\u83b7\u5f97\u66f4\u597d\u7684\u7ed3\u679c\u3002<\/p>\n<\/p>\n<p><h4>4.1 \u8c03\u6574\u56fe\u5f62\u7684\u89c6\u89d2\u548c\u5e03\u5c40<\/h4>\n<\/p>\n<p><p>\u5728\u4fdd\u5b58\u56fe\u5f62\u524d\uff0c\u786e\u4fdd\u8c03\u6574\u56fe\u5f62\u7684\u89c6\u89d2\u548c\u5e03\u5c40\uff0c\u4ee5\u83b7\u5f97\u6700\u4f73\u7684\u663e\u793a\u6548\u679c\u3002\u4f8b\u5982\uff0c\u5728 Matplotlib \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>view_init<\/code> \u65b9\u6cd5\u8c03\u6574\u89c6\u89d2\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">ax.view_init(elev=30, azim=45)<\/p>\n<p>plt.savefig(&#39;3d_plot_adjusted.png&#39;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728 Mayavi \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>mlab.view<\/code> \u65b9\u6cd5\u8c03\u6574\u89c6\u89d2\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">mlab.view(azimuth=45, elevation=30, distance=10)<\/p>\n<p>mlab.savefig(&#39;mayavi_3d_plot_adjusted.png&#39;)<\/p>\n<p>mlab.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>4.2 \u6dfb\u52a0\u6807\u9898\u548c\u6807\u7b7e<\/h4>\n<\/p>\n<p><p>\u4e3a\u56fe\u5f62\u6dfb\u52a0\u6807\u9898\u548c\u8f74\u6807\u7b7e\uff0c\u6709\u52a9\u4e8e\u63d0\u9ad8\u56fe\u5f62\u7684\u53ef\u8bfb\u6027\u548c\u4fe1\u606f\u91cf\u3002\u5728 Matplotlib \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>title<\/code>\u3001<code>xlabel<\/code> \u548c <code>ylabel<\/code> \u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">ax.set_title(&#39;3D Surface Plot&#39;)<\/p>\n<p>ax.set_xlabel(&#39;X Axis&#39;)<\/p>\n<p>ax.set_ylabel(&#39;Y Axis&#39;)<\/p>\n<p>ax.set_zlabel(&#39;Z Axis&#39;)<\/p>\n<p>plt.savefig(&#39;3d_plot_with_labels.png&#39;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728 Mayavi \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>mlab.title<\/code> \u548c <code>mlab.xlabel<\/code> \u7b49\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">mlab.title(&#39;3D Surface Plot&#39;)<\/p>\n<p>mlab.xlabel(&#39;X Axis&#39;)<\/p>\n<p>mlab.ylabel(&#39;Y Axis&#39;)<\/p>\n<p>mlab.zlabel(&#39;Z Axis&#39;)<\/p>\n<p>mlab.savefig(&#39;mayavi_3d_plot_with_labels.png&#39;)<\/p>\n<p>mlab.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>4.3 \u5904\u7406\u5927\u578b\u6570\u636e\u96c6<\/h4>\n<\/p>\n<p><p>\u5bf9\u4e8e\u5927\u578b\u6570\u636e\u96c6\uff0c\u7ed8\u5236\u548c\u4fdd\u5b58\u4e09\u7ef4\u56fe\u5f62\u53ef\u80fd\u4f1a\u8017\u8d39\u8f83\u591a\u7684\u5185\u5b58\u548c\u65f6\u95f4\u3002\u53ef\u4ee5\u901a\u8fc7\u51cf\u5c11\u6570\u636e\u70b9\u7684\u6570\u91cf\u6216\u4f7f\u7528\u66f4\u9ad8\u6548\u7684\u7b97\u6cd5\u6765\u4f18\u5316\u6027\u80fd\u3002\u4f8b\u5982\uff0c\u5728 Matplotlib \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>plot_wireframe<\/code> \u65b9\u6cd5\u800c\u4e0d\u662f <code>plot_surface<\/code> \u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">ax.plot_wireframe(X, Y, Z, color=&#39;black&#39;)<\/p>\n<p>plt.savefig(&#39;3d_wireframe_plot.png&#39;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728 Mayavi \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>mlab.pipeline.reduce_points<\/code> \u65b9\u6cd5\u51cf\u5c11\u6570\u636e\u70b9\u7684\u6570\u91cf\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plot = mlab.surf(x, y, z, colormap=&#39;viridis&#39;)<\/p>\n<p>plot.actor.property.point_size = 2<\/p>\n<p>mlab.savefig(&#39;mayavi_3d_plot_optimized.png&#39;)<\/p>\n<p>mlab.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>Python \u63d0\u4f9b\u4e86\u591a\u79cd\u5de5\u5177\u548c\u65b9\u6cd5\u6765\u4fdd\u5b58\u4e09\u7ef4\u56fe\u5f62\uff0c\u5305\u62ec Matplotlib \u548c Mayavi\u3002\u901a\u8fc7\u6b63\u786e\u4f7f\u7528\u8fd9\u4e9b\u5de5\u5177\u7684 <code>savefig<\/code> \u6216 <code>mlab.savefig<\/code> \u65b9\u6cd5\uff0c\u5e76\u786e\u4fdd\u6587\u4ef6\u8def\u5f84\u548c\u683c\u5f0f\u7684\u6b63\u786e\u8bbe\u7f6e\uff0c\u53ef\u4ee5\u8f7b\u677e\u4fdd\u5b58\u9ad8\u8d28\u91cf\u7684\u4e09\u7ef4\u56fe\u5f62\u3002\u6b64\u5916\uff0c\u8c03\u6574\u56fe\u5f62\u7684\u89c6\u89d2\u3001\u6dfb\u52a0\u6807\u9898\u548c\u6807\u7b7e\u3001\u4ee5\u53ca\u5904\u7406\u5927\u578b\u6570\u636e\u96c6\u7684\u6280\u5de7\uff0c\u4e5f\u80fd\u5e2e\u52a9\u4f60\u83b7\u5f97\u66f4\u597d\u7684\u7ed3\u679c\u3002\u5e0c\u671b\u672c\u6587\u6240\u63d0\u4f9b\u7684\u4fe1\u606f\u548c\u793a\u4f8b\u4ee3\u7801\u80fd\u4e3a\u4f60\u5728\u4fdd\u5b58\u4e09\u7ef4\u56fe\u5f62\u65f6\u63d0\u4f9b\u6709\u4ef7\u503c\u7684\u53c2\u8003\u548c\u5e2e\u52a9\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u4fdd\u5b58\u4e09\u7ef4\u56fe\u50cf\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528Matplotlib\u5e93\u7ed8\u5236\u4e09\u7ef4\u56fe\u50cf\uff0c\u5e76\u901a\u8fc7<code>savefig()<\/code>\u51fd\u6570\u5c06\u5176\u4fdd\u5b58\u4e3a\u591a\u79cd\u683c\u5f0f\uff0c\u5982PNG\u3001JPEG\u6216SVG\u3002\u5177\u4f53\u6b65\u9aa4\u5305\u62ec\uff1a\u521b\u5efa\u4e09\u7ef4\u7ed8\u56fe\u5bf9\u8c61\u3001\u7ed8\u5236\u56fe\u50cf\uff0c\u7136\u540e\u8c03\u7528<code>savefig(&#39;filename.png&#39;)<\/code>\u6765\u4fdd\u5b58\u56fe\u50cf\u3002\u786e\u4fdd\u5728\u4fdd\u5b58\u4e4b\u524d\u8bbe\u7f6e\u597d\u56fe\u50cf\u7684\u5927\u5c0f\u548c\u5206\u8fa8\u7387\uff0c\u4ee5\u4fbf\u83b7\u5f97\u6700\u4f73\u6548\u679c\u3002<\/p>\n<p><strong>\u4fdd\u5b58\u4e09\u7ef4\u56fe\u50cf\u65f6\u9700\u8981\u6ce8\u610f\u54ea\u4e9b\u53c2\u6570\uff1f<\/strong><br \/>\u4fdd\u5b58\u4e09\u7ef4\u56fe\u50cf\u65f6\uff0c\u91cd\u8981\u7684\u53c2\u6570\u5305\u62ec\u56fe\u50cf\u7684\u5206\u8fa8\u7387\uff08dpi\uff09\u3001\u56fe\u50cf\u5c3a\u5bf8\uff08figsize\uff09\uff0c\u4ee5\u53ca\u662f\u5426\u9700\u8981\u900f\u660e\u80cc\u666f\u3002\u53ef\u4ee5\u901a\u8fc7<code>plt.savefig(&#39;filename.png&#39;, dpi=300, transparent=True)<\/code>\u6765\u8bbe\u7f6e\u8fd9\u4e9b\u53c2\u6570\uff0c\u4ece\u800c\u4f18\u5316\u8f93\u51fa\u6548\u679c\u3002<\/p>\n<p><strong>\u6709\u6ca1\u6709\u5176\u4ed6\u5e93\u53ef\u4ee5\u7528\u6765\u4fdd\u5b58Python\u4e2d\u7684\u4e09\u7ef4\u56fe\u50cf\uff1f<\/strong><br \/>\u9664\u4e86Matplotlib\uff0c\u5176\u4ed6\u5e93\u5982Plotly\u548cMayavi\u4e5f\u53ef\u4ee5\u7528\u4e8e\u521b\u5efa\u548c\u4fdd\u5b58\u4e09\u7ef4\u56fe\u50cf\u3002Plotly\u63d0\u4f9b\u4e86\u4ea4\u4e92\u5f0f\u56fe\u5f62\uff0c\u80fd\u591f\u5bfc\u51fa\u4e3aHTML\u6216PNG\u683c\u5f0f\uff0c\u800cMayavi\u66f4\u9002\u5408\u8fdb\u884c\u590d\u6742\u7684\u4e09\u7ef4\u53ef\u89c6\u5316\u3002\u9009\u62e9\u5408\u9002\u7684\u5e93\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u7684\u9700\u6c42\u548c\u8f93\u51fa\u683c\u5f0f\u8fdb\u884c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python \u753b\u7684\u4e09\u7ef4\u56fe\u5982\u4f55\u4fdd\u5b58\uff1a\u4f7f\u7528Matplotlib\u7684savefig\u65b9\u6cd5\u3001\u4f7f\u7528Mayavi\u7684mlab.s [&hellip;]","protected":false},"author":3,"featured_media":1128610,"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\/1128600"}],"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=1128600"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1128600\/revisions"}],"predecessor-version":[{"id":1128613,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1128600\/revisions\/1128613"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1128610"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1128600"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1128600"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1128600"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}