{"id":1139970,"date":"2025-01-08T22:15:31","date_gmt":"2025-01-08T14:15:31","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1139970.html"},"modified":"2025-01-08T22:15:34","modified_gmt":"2025-01-08T14:15:34","slug":"python%e5%87%ba%e5%9b%be%e6%97%b6%e5%a6%82%e4%bd%95%e6%98%af%e9%81%8f%e5%88%b6%e5%9b%be%e7%89%87%e5%b0%ba%e5%af%b8","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1139970.html","title":{"rendered":"python\u51fa\u56fe\u65f6\u5982\u4f55\u662f\u904f\u5236\u56fe\u7247\u5c3a\u5bf8"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25103109\/362dc87c-38c4-4a6f-b872-3133f91ce461.webp\" alt=\"python\u51fa\u56fe\u65f6\u5982\u4f55\u662f\u904f\u5236\u56fe\u7247\u5c3a\u5bf8\" \/><\/p>\n<p><p> <strong>\u8981\u5728Python\u4e2d\u63a7\u5236\u751f\u6210\u56fe\u7247\u7684\u5c3a\u5bf8\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u4e2a\u56fe\u5f62\u5e93\uff0c\u5982Matplotlib\u3001Seaborn\u548cPillow\u3002<\/strong> \u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u8fd9\u4e9b\u5e93\u6765\u751f\u6210\u548c\u63a7\u5236\u56fe\u7247\u7684\u5c3a\u5bf8\uff0c\u5e76\u7ed9\u51fa\u4e00\u4e9b\u4e13\u4e1a\u7684\u5efa\u8bae\u548c\u6280\u5de7\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001Matplotlib\u5e93<\/h3>\n<\/p>\n<p><p><strong>Matplotlib<\/strong> \u662fPython\u4e2d\u6700\u5e38\u7528\u7684\u7ed8\u56fe\u5e93\u4e4b\u4e00\u3002\u901a\u8fc7\u8bbe\u7f6efigure\u5bf9\u8c61\u7684\u5927\u5c0f\uff0c\u6211\u4eec\u53ef\u4ee5\u5f88\u65b9\u4fbf\u5730\u63a7\u5236\u8f93\u51fa\u56fe\u7247\u7684\u5c3a\u5bf8\u3002<\/p>\n<\/p>\n<p><h4>1.1\u3001\u8bbe\u7f6efigure\u5927\u5c0f<\/h4>\n<\/p>\n<p><p>\u5728Matplotlib\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7<code>figure<\/code>\u51fd\u6570\u7684<code>figsize<\/code>\u53c2\u6570\u6765\u8bbe\u7f6e\u56fe\u7247\u7684\u5c3a\u5bf8\u3002<code>figsize<\/code>\u63a5\u53d7\u4e00\u4e2a\u5305\u542b\u5bbd\u5ea6\u548c\u9ad8\u5ea6\u7684\u5143\u7ec4\uff0c\u5355\u4f4d\u4e3a\u82f1\u5bf8\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u8bbe\u7f6efigure\u5927\u5c0f<\/strong><\/h2>\n<p>plt.figure(figsize=(10, 6))<\/p>\n<p>plt.plot([1, 2, 3, 4], [10, 20, 25, 30])<\/p>\n<p>plt.title(&#39;Sample Plot&#39;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>1.2\u3001\u4fdd\u5b58\u56fe\u7247\u65f6\u8bbe\u7f6e\u5927\u5c0f<\/h4>\n<\/p>\n<p><p>\u4f60\u8fd8\u53ef\u4ee5\u5728\u4fdd\u5b58\u56fe\u7247\u65f6\u63a7\u5236\u5176\u5c3a\u5bf8\u3002\u4f7f\u7528<code>savefig<\/code>\u51fd\u6570\u7684<code>dpi<\/code>\u53c2\u6570\u53ef\u4ee5\u63a7\u5236\u56fe\u7247\u7684\u5206\u8fa8\u7387\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.figure(figsize=(10, 6))<\/p>\n<p>plt.plot([1, 2, 3, 4], [10, 20, 25, 30])<\/p>\n<p>plt.title(&#39;Sample Plot&#39;)<\/p>\n<h2><strong>\u4fdd\u5b58\u56fe\u7247\u5e76\u8bbe\u7f6eDPI<\/strong><\/h2>\n<p>plt.savefig(&#39;sample_plot.png&#39;, dpi=300)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001Seaborn\u5e93<\/h3>\n<\/p>\n<p><p><strong>Seaborn<\/strong> \u662f\u57fa\u4e8eMatplotlib\u7684\u9ad8\u7ea7\u7ed8\u56fe\u5e93\u3002\u5b83\u63d0\u4f9b\u4e86\u66f4\u52a0\u7f8e\u89c2\u548c\u590d\u6742\u7684\u7edf\u8ba1\u56fe\u5f62\u3002Seaborn\u7684\u7ed8\u56fe\u4e5f\u53ef\u4ee5\u901a\u8fc7Matplotlib\u7684<code>figure<\/code>\u8fdb\u884c\u5c3a\u5bf8\u63a7\u5236\u3002<\/p>\n<\/p>\n<p><h4>2.1\u3001\u4f7f\u7528Seaborn\u7ed8\u5236\u56fe\u5f62<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import seaborn as sns<\/p>\n<p>import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u8bbe\u7f6efigure\u5927\u5c0f<\/strong><\/h2>\n<p>plt.figure(figsize=(10, 6))<\/p>\n<p>data = sns.load_dataset(&#39;iris&#39;)<\/p>\n<p>sns.scatterplot(data=data, x=&#39;sepal_length&#39;, y=&#39;sepal_width&#39;, hue=&#39;species&#39;)<\/p>\n<p>plt.title(&#39;Iris Sepal Length vs Sepal Width&#39;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2.2\u3001\u4fdd\u5b58Seaborn\u56fe\u5f62<\/h4>\n<\/p>\n<p><p>\u7c7b\u4f3c\u4e8eMatplotlib\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528<code>savefig<\/code>\u51fd\u6570\u6765\u4fdd\u5b58Seaborn\u751f\u6210\u7684\u56fe\u5f62\uff0c\u5e76\u8bbe\u7f6eDPI\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.figure(figsize=(10, 6))<\/p>\n<p>data = sns.load_dataset(&#39;iris&#39;)<\/p>\n<p>sns.scatterplot(data=data, x=&#39;sepal_length&#39;, y=&#39;sepal_width&#39;, hue=&#39;species&#39;)<\/p>\n<p>plt.title(&#39;Iris Sepal Length vs Sepal Width&#39;)<\/p>\n<h2><strong>\u4fdd\u5b58\u56fe\u7247\u5e76\u8bbe\u7f6eDPI<\/strong><\/h2>\n<p>plt.savefig(&#39;seaborn_plot.png&#39;, dpi=300)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001Pillow\u5e93<\/h3>\n<\/p>\n<p><p><strong>Pillow<\/strong> \u662fPython\u7684\u4e00\u4e2a\u56fe\u50cf\u5904\u7406\u5e93\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u56fe\u50cf\u5904\u7406\u529f\u80fd\uff0c\u5305\u62ec\u56fe\u50cf\u7684\u88c1\u526a\u3001\u8c03\u6574\u5927\u5c0f\u3001\u6ee4\u955c\u7b49\u3002<\/p>\n<\/p>\n<p><h4>3.1\u3001\u8c03\u6574\u56fe\u7247\u5927\u5c0f<\/h4>\n<\/p>\n<p><p>\u4f60\u53ef\u4ee5\u4f7f\u7528Pillow\u5e93\u4e2d\u7684<code>resize<\/code>\u65b9\u6cd5\u8c03\u6574\u56fe\u7247\u7684\u5c3a\u5bf8\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import Image<\/p>\n<h2><strong>\u6253\u5f00\u4e00\u4e2a\u56fe\u7247\u6587\u4ef6<\/strong><\/h2>\n<p>image = Image.open(&#39;example.jpg&#39;)<\/p>\n<h2><strong>\u8c03\u6574\u56fe\u7247\u5927\u5c0f<\/strong><\/h2>\n<p>new_image = image.resize((800, 600))<\/p>\n<p>new_image.save(&#39;resized_example.jpg&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3.2\u3001\u88c1\u526a\u56fe\u7247<\/h4>\n<\/p>\n<p><p>Pillow\u8fd8\u63d0\u4f9b\u4e86\u88c1\u526a\u56fe\u7247\u7684\u529f\u80fd\uff0c\u8fd9\u53ef\u4ee5\u5e2e\u52a9\u4f60\u5728\u751f\u6210\u56fe\u5f62\u524d\u5bf9\u56fe\u7247\u8fdb\u884c\u9884\u5904\u7406\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u6253\u5f00\u4e00\u4e2a\u56fe\u7247\u6587\u4ef6<\/p>\n<p>image = Image.open(&#39;example.jpg&#39;)<\/p>\n<h2><strong>\u88c1\u526a\u56fe\u7247<\/strong><\/h2>\n<p>box = (100, 100, 400, 400)<\/p>\n<p>cropped_image = image.crop(box)<\/p>\n<p>cropped_image.save(&#39;cropped_example.jpg&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u7ed3\u5408\u4f7f\u7528\u591a\u4e2a\u5e93<\/h3>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u9879\u76ee\u4e2d\uff0c\u6709\u65f6\u9700\u8981\u7ed3\u5408\u4f7f\u7528\u591a\u4e2a\u5e93\u6765\u8fbe\u5230\u6700\u4f73\u6548\u679c\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528Matplotlib\u751f\u6210\u56fe\u5f62\uff0c\u7136\u540e\u4f7f\u7528Pillow\u8fdb\u884c\u540e\u5904\u7406\u3002<\/p>\n<\/p>\n<p><h4>4.1\u3001\u751f\u6210\u56fe\u5f62\u5e76\u4fdd\u5b58<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>plt.figure(figsize=(10, 6))<\/p>\n<p>plt.plot([1, 2, 3, 4], [10, 20, 25, 30])<\/p>\n<p>plt.title(&#39;Sample Plot&#39;)<\/p>\n<p>plt.savefig(&#39;plot.png&#39;, dpi=300)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>4.2\u3001\u4f7f\u7528Pillow\u5904\u7406\u751f\u6210\u7684\u56fe\u5f62<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import Image<\/p>\n<h2><strong>\u6253\u5f00\u751f\u6210\u7684\u56fe\u5f62\u6587\u4ef6<\/strong><\/h2>\n<p>image = Image.open(&#39;plot.png&#39;)<\/p>\n<h2><strong>\u8c03\u6574\u56fe\u7247\u5927\u5c0f<\/strong><\/h2>\n<p>new_image = image.resize((800, 600))<\/p>\n<p>new_image.save(&#39;resized_plot.png&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u5176\u4ed6\u6280\u5de7\u548c\u5efa\u8bae<\/h3>\n<\/p>\n<p><h4>5.1\u3001\u4f7f\u7528\u5b50\u56fe<\/h4>\n<\/p>\n<p><p>\u6709\u65f6\u4f60\u9700\u8981\u5728\u4e00\u5f20\u56fe\u7247\u4e0a\u663e\u793a\u591a\u4e2a\u5b50\u56fe\u3002Matplotlib\u63d0\u4f9b\u4e86<code>subplot<\/code>\u529f\u80fd\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u521b\u5efa\u5b50\u56fe\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>plt.figure(figsize=(12, 8))<\/p>\n<h2><strong>\u7b2c\u4e00\u4e2a\u5b50\u56fe<\/strong><\/h2>\n<p>plt.subplot(2, 2, 1)<\/p>\n<p>plt.plot([1, 2, 3, 4], [10, 20, 25, 30])<\/p>\n<p>plt.title(&#39;Subplot 1&#39;)<\/p>\n<h2><strong>\u7b2c\u4e8c\u4e2a\u5b50\u56fe<\/strong><\/h2>\n<p>plt.subplot(2, 2, 2)<\/p>\n<p>plt.plot([1, 2, 3, 4], [30, 25, 20, 10])<\/p>\n<p>plt.title(&#39;Subplot 2&#39;)<\/p>\n<h2><strong>\u7b2c\u4e09\u4e2a\u5b50\u56fe<\/strong><\/h2>\n<p>plt.subplot(2, 2, 3)<\/p>\n<p>plt.plot([1, 2, 3, 4], [15, 15, 15, 15])<\/p>\n<p>plt.title(&#39;Subplot 3&#39;)<\/p>\n<h2><strong>\u7b2c\u56db\u4e2a\u5b50\u56fe<\/strong><\/h2>\n<p>plt.subplot(2, 2, 4)<\/p>\n<p>plt.plot([1, 2, 3, 4], [10, 5, 0, -5])<\/p>\n<p>plt.title(&#39;Subplot 4&#39;)<\/p>\n<p>plt.tight_layout()<\/p>\n<p>plt.savefig(&#39;subplots.png&#39;, dpi=300)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>5.2\u3001\u4f7f\u7528\u7f51\u683c\u5e03\u5c40<\/h4>\n<\/p>\n<p><p>\u4e3a\u4e86\u66f4\u597d\u5730\u63a7\u5236\u5b50\u56fe\u7684\u5e03\u5c40\uff0c\u53ef\u4ee5\u4f7f\u7528\u7f51\u683c\u5e03\u5c40\uff08GridSpec\uff09\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>import matplotlib.gridspec as gridspec<\/p>\n<p>fig = plt.figure(figsize=(12, 8))<\/p>\n<p>gs = gridspec.GridSpec(3, 3)<\/p>\n<p>ax1 = fig.add_subplot(gs[0, 0])<\/p>\n<p>ax1.plot([1, 2, 3, 4], [10, 20, 25, 30])<\/p>\n<p>ax1.set_title(&#39;Subplot 1&#39;)<\/p>\n<p>ax2 = fig.add_subplot(gs[0, 1:])<\/p>\n<p>ax2.plot([1, 2, 3, 4], [30, 25, 20, 10])<\/p>\n<p>ax2.set_title(&#39;Subplot 2&#39;)<\/p>\n<p>ax3 = fig.add_subplot(gs[1, :-1])<\/p>\n<p>ax3.plot([1, 2, 3, 4], [15, 15, 15, 15])<\/p>\n<p>ax3.set_title(&#39;Subplot 3&#39;)<\/p>\n<p>ax4 = fig.add_subplot(gs[1:, -1])<\/p>\n<p>ax4.plot([1, 2, 3, 4], [10, 5, 0, -5])<\/p>\n<p>ax4.set_title(&#39;Subplot 4&#39;)<\/p>\n<p>ax5 = fig.add_subplot(gs[-1, 0])<\/p>\n<p>ax5.plot([1, 2, 3, 4], [5, 10, 15, 20])<\/p>\n<p>ax5.set_title(&#39;Subplot 5&#39;)<\/p>\n<p>plt.tight_layout()<\/p>\n<p>plt.savefig(&#39;grid_spec_subplots.png&#39;, dpi=300)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516d\u3001\u4f18\u5316\u8f93\u51fa\u56fe\u5f62\u7684\u8d28\u91cf<\/h3>\n<\/p>\n<p><h4>6.1\u3001\u63d0\u9ad8\u5206\u8fa8\u7387<\/h4>\n<\/p>\n<p><p>\u5728\u4fdd\u5b58\u56fe\u5f62\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u589e\u52a0DPI\u6765\u63d0\u9ad8\u56fe\u5f62\u7684\u5206\u8fa8\u7387\uff0c\u4ece\u800c\u751f\u6210\u66f4\u6e05\u6670\u7684\u56fe\u7247\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.figure(figsize=(10, 6))<\/p>\n<p>plt.plot([1, 2, 3, 4], [10, 20, 25, 30])<\/p>\n<p>plt.title(&#39;High Resolution Plot&#39;)<\/p>\n<p>plt.savefig(&#39;high_res_plot.png&#39;, dpi=600)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>6.2\u3001\u4f7f\u7528\u5411\u91cf\u56fe\u5f62\u683c\u5f0f<\/h4>\n<\/p>\n<p><p>\u5bf9\u4e8e\u67d0\u4e9b\u5e94\u7528\uff0c\u4f7f\u7528\u5411\u91cf\u56fe\u5f62\u683c\u5f0f\uff08\u5982SVG\u3001PDF\uff09\u53ef\u4ee5\u4fdd\u8bc1\u56fe\u5f62\u5728\u653e\u5927\u65f6\u4e0d\u4f1a\u5931\u771f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.figure(figsize=(10, 6))<\/p>\n<p>plt.plot([1, 2, 3, 4], [10, 20, 25, 30])<\/p>\n<p>plt.title(&#39;Vector Graphics Plot&#39;)<\/p>\n<p>plt.savefig(&#39;vector_plot.svg&#39;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e03\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u63a7\u5236\u751f\u6210\u56fe\u7247\u7684\u5c3a\u5bf8\u662f\u4e00\u4e2a\u5e38\u89c1\u800c\u91cd\u8981\u7684\u4efb\u52a1\u3002\u901a\u8fc7\u4f7f\u7528Matplotlib\u3001Seaborn\u548cPillow\u7b49\u5e93\uff0c\u4f60\u53ef\u4ee5\u975e\u5e38\u7075\u6d3b\u5730\u751f\u6210\u548c\u63a7\u5236\u56fe\u5f62\u7684\u5c3a\u5bf8\u3002\u65e0\u8bba\u662f\u901a\u8fc7\u8c03\u6574figure\u7684\u5927\u5c0f\uff0c\u8fd8\u662f\u5728\u4fdd\u5b58\u56fe\u7247\u65f6\u8bbe\u7f6eDPI\uff0c\u6216\u8005\u4f7f\u7528\u66f4\u9ad8\u7ea7\u7684\u7f51\u683c\u5e03\u5c40\u548c\u5b50\u56fe\u529f\u80fd\uff0c\u8fd9\u4e9b\u65b9\u6cd5\u90fd\u80fd\u5e2e\u52a9\u4f60\u521b\u5efa\u4e13\u4e1a\u4e14\u7f8e\u89c2\u7684\u56fe\u5f62\u3002<\/p>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u9009\u62e9\u5408\u9002\u7684\u56fe\u5f62\u5e93\u548c\u65b9\u6cd5\uff0c\u7ed3\u5408\u9879\u76ee\u7684\u5177\u4f53\u9700\u6c42\uff0c\u53ef\u4ee5\u5927\u5927\u63d0\u9ad8\u56fe\u5f62\u7684\u8d28\u91cf\u548c\u53ef\u8bfb\u6027\u3002\u5e0c\u671b\u8fd9\u7bc7\u6587\u7ae0\u80fd\u4e3a\u4f60\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\u8bbe\u7f6e\u56fe\u50cf\u7684\u5927\u5c0f\u4ee5\u9002\u5e94\u7279\u5b9a\u9700\u6c42\uff1f<\/strong><br \/>\u5728\u4f7f\u7528Python\u8fdb\u884c\u56fe\u50cf\u7ed8\u5236\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7matplotlib\u5e93\u4e2d\u7684<code>figsize<\/code>\u53c2\u6570\u6765\u8bbe\u7f6e\u56fe\u50cf\u7684\u5c3a\u5bf8\u3002\u5177\u4f53\u65b9\u6cd5\u662f\u5728\u521b\u5efa\u56fe\u5f62\u65f6\u6307\u5b9a<code>figsize=(\u5bbd\u5ea6, \u9ad8\u5ea6)<\/code>\uff0c\u5355\u4f4d\u901a\u5e38\u662f\u82f1\u5bf8\u3002\u4f8b\u5982\uff0c<code>plt.figure(figsize=(10, 5))<\/code>\u5c06\u751f\u6210\u4e00\u4e2a\u5bbd10\u82f1\u5bf8\u3001\u9ad85\u82f1\u5bf8\u7684\u56fe\u50cf\u3002\u8fd9\u79cd\u65b9\u5f0f\u53ef\u4ee5\u6709\u6548\u63a7\u5236\u8f93\u51fa\u56fe\u50cf\u7684\u5c3a\u5bf8\uff0c\u6ee1\u8db3\u4e0d\u540c\u7684\u5c55\u793a\u9700\u6c42\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5982\u4f55\u4fdd\u6301\u56fe\u50cf\u7684\u7eb5\u6a2a\u6bd4\uff1f<\/strong><br \/>\u4fdd\u6301\u56fe\u50cf\u7684\u7eb5\u6a2a\u6bd4\u662f\u786e\u4fdd\u56fe\u50cf\u4e0d\u5931\u771f\u7684\u5173\u952e\u3002\u53ef\u4ee5\u4f7f\u7528<code>aspect<\/code>\u53c2\u6570\u6765\u63a7\u5236\u56fe\u50cf\u7684\u7eb5\u6a2a\u6bd4\uff0c\u4f8b\u5982<code>plt.gca().set_aspect(&#39;equal&#39;, adjustable=&#39;box&#39;)<\/code>\u3002\u8fd9\u79cd\u65b9\u5f0f\u4f1a\u8c03\u6574\u5750\u6807\u8f74\uff0c\u4f7f\u5f97\u5728\u8bbe\u7f6e\u5c3a\u5bf8\u65f6\uff0c\u56fe\u50cf\u7684\u5bbd\u9ad8\u6bd4\u4f8b\u4fdd\u6301\u4e00\u81f4\uff0c\u907f\u514d\u56e0\u5c3a\u5bf8\u8c03\u6574\u800c\u5bfc\u81f4\u7684\u56fe\u50cf\u53d8\u5f62\u3002<\/p>\n<p><strong>\u5982\u679c\u60f3\u8981\u5728\u8f93\u51fa\u56fe\u50cf\u65f6\u6539\u53d8\u5206\u8fa8\u7387\u8be5\u5982\u4f55\u64cd\u4f5c\uff1f<\/strong><br \/>\u5728\u4f7f\u7528matplotlib\u4fdd\u5b58\u56fe\u50cf\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7<code>dpi<\/code>\u53c2\u6570\u6765\u8bbe\u7f6e\u56fe\u50cf\u7684\u5206\u8fa8\u7387\u3002\u4f8b\u5982\uff0c\u4f7f\u7528<code>plt.savefig(&#39;filename.png&#39;, dpi=300)<\/code>\u53ef\u4ee5\u5c06\u56fe\u50cf\u4ee5300 DPI\u7684\u9ad8\u5206\u8fa8\u7387\u4fdd\u5b58\u3002\u8c03\u6574\u5206\u8fa8\u7387\u4e0d\u4ec5\u80fd\u5f71\u54cd\u56fe\u50cf\u7684\u6e05\u6670\u5ea6\uff0c\u8fd8\u80fd\u5728\u4e00\u5b9a\u7a0b\u5ea6\u4e0a\u5f71\u54cd\u6587\u4ef6\u5927\u5c0f\uff0c\u8fd9\u5bf9\u4e8e\u4e0d\u540c\u7684\u4f7f\u7528\u573a\u666f\u5341\u5206\u91cd\u8981\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u8981\u5728Python\u4e2d\u63a7\u5236\u751f\u6210\u56fe\u7247\u7684\u5c3a\u5bf8\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u4e2a\u56fe\u5f62\u5e93\uff0c\u5982Matplotlib\u3001Seaborn\u548cPillow [&hellip;]","protected":false},"author":3,"featured_media":1139980,"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\/1139970"}],"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=1139970"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1139970\/revisions"}],"predecessor-version":[{"id":1139984,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1139970\/revisions\/1139984"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1139980"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1139970"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1139970"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1139970"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}