{"id":1111773,"date":"2025-01-08T17:32:22","date_gmt":"2025-01-08T09:32:22","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1111773.html"},"modified":"2025-01-08T17:32:25","modified_gmt":"2025-01-08T09:32:25","slug":"python%e5%a6%82%e4%bd%95%e6%8a%8a%e7%94%bb%e5%87%ba%e6%9d%a5%e7%9a%84%e5%9b%be%e5%8f%98%e5%a4%a7","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1111773.html","title":{"rendered":"python\u5982\u4f55\u628a\u753b\u51fa\u6765\u7684\u56fe\u53d8\u5927"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25074102\/edac5f4a-b76c-4c5a-9eb4-f1ef72d3b300.webp\" alt=\"python\u5982\u4f55\u628a\u753b\u51fa\u6765\u7684\u56fe\u53d8\u5927\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\uff0c\u8c03\u6574\u753b\u51fa\u6765\u7684\u56fe\u7684\u5927\u5c0f\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u6cd5\u5b9e\u73b0\uff0c\u4e3b\u8981\u5305\u62ec\uff1a\u8bbe\u7f6e\u56fe\u5f62\u7684\u5927\u5c0f\u53c2\u6570\u3001\u6539\u53d8\u56fe\u5f62\u7684\u5206\u8fa8\u7387\u3001\u8c03\u6574\u5b50\u56fe\u7684\u5e03\u5c40\u7b49\u3002<\/strong>\u5176\u4e2d\uff0c\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u662f\u901a\u8fc7 <code>matplotlib<\/code> \u5e93\u4e2d\u7684 <code>figure<\/code> \u51fd\u6570\u6765\u8bbe\u7f6e\u56fe\u5f62\u7684\u5927\u5c0f\u53c2\u6570\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u4e9b\u65b9\u6cd5\u4e2d\u7684\u4e00\u79cd\uff0c\u5e76\u5728\u540e\u7eed\u90e8\u5206\u8be6\u7ec6\u8bb2\u89e3\u5176\u4ed6\u65b9\u6cd5\u548c\u76f8\u5173\u6280\u5de7\u3002<\/p>\n<\/p>\n<p><h3>\u4f7f\u7528 <code>matplotlib<\/code> \u8bbe\u7f6e\u56fe\u5f62\u5927\u5c0f<\/h3>\n<\/p>\n<p><p>\u5728 <code>matplotlib<\/code> \u5e93\u4e2d\uff0c\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u662f\u901a\u8fc7 <code>figure<\/code> \u51fd\u6570\u7684 <code>figsize<\/code> \u53c2\u6570\u6765\u8bbe\u7f6e\u56fe\u5f62\u7684\u5927\u5c0f\u3002<code>figsize<\/code> \u53c2\u6570\u63a5\u53d7\u4e00\u4e2a\u5305\u542b\u5bbd\u5ea6\u548c\u9ad8\u5ea6\u7684\u5143\u7ec4\uff0c\u5355\u4f4d\u4e3a\u82f1\u5bf8\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u8bbe\u7f6e\u56fe\u5f62\u5927\u5c0f\u4e3a12x8\u82f1\u5bf8<\/strong><\/h2>\n<p>plt.figure(figsize=(12, 8))<\/p>\n<p>plt.plot([1, 2, 3, 4], [1, 4, 9, 16])<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e00\u3001\u8bbe\u7f6e\u56fe\u5f62\u7684\u5927\u5c0f\u53c2\u6570<\/h3>\n<\/p>\n<ol>\n<li>\n<p><strong>\u901a\u8fc7 <code>figure<\/code> \u51fd\u6570\u8bbe\u7f6e\u56fe\u5f62\u5927\u5c0f<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528 <code>matplotlib<\/code> \u5e93\u7684 <code>figure<\/code> \u51fd\u6570\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u8bbe\u7f6e\u56fe\u5f62\u7684\u5927\u5c0f\u3002<code>figsize<\/code> \u53c2\u6570\u63a5\u53d7\u4e00\u4e2a\u5305\u542b\u5bbd\u5ea6\u548c\u9ad8\u5ea6\u7684\u5143\u7ec4\uff0c\u5355\u4f4d\u4e3a\u82f1\u5bf8\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u8bbe\u7f6e\u56fe\u5f62\u5927\u5c0f\u4e3a12x8\u82f1\u5bf8<\/strong><\/h2>\n<p>plt.figure(figsize=(12, 8))<\/p>\n<p>plt.plot([1, 2, 3, 4], [1, 4, 9, 16])<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u53ef\u4ee5\u76f4\u63a5\u63a7\u5236\u56fe\u5f62\u7684\u5bbd\u5ea6\u548c\u9ad8\u5ea6\uff0c\u4ece\u800c\u8c03\u6574\u56fe\u5f62\u7684\u6574\u4f53\u5927\u5c0f\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u901a\u8fc7 <code>set_size_inches<\/code> \u65b9\u6cd5\u8bbe\u7f6e\u56fe\u5f62\u5927\u5c0f<\/strong><\/p>\n<\/p>\n<p><p>\u5982\u679c\u5df2\u7ecf\u521b\u5efa\u4e86\u4e00\u4e2a\u56fe\u5f62\u5bf9\u8c61\uff08\u5373 <code>Figure<\/code> \u5bf9\u8c61\uff09\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>set_size_inches<\/code> \u65b9\u6cd5\u6765\u8bbe\u7f6e\u56fe\u5f62\u7684\u5927\u5c0f\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>fig, ax = plt.subplots()<\/p>\n<p>fig.set_size_inches(12, 8)<\/p>\n<p>ax.plot([1, 2, 3, 4], [1, 4, 9, 16])<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u5728\u56fe\u5f62\u521b\u5efa\u540e\u9700\u8981\u52a8\u6001\u8c03\u6574\u56fe\u5f62\u5927\u5c0f\u7684\u60c5\u51b5\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u4e8c\u3001\u6539\u53d8\u56fe\u5f62\u7684\u5206\u8fa8\u7387<\/h3>\n<\/p>\n<ol>\n<li>\n<p><strong>\u901a\u8fc7 <code>dpi<\/code> \u53c2\u6570\u8bbe\u7f6e\u56fe\u5f62\u5206\u8fa8\u7387<\/strong><\/p>\n<\/p>\n<p><p><code>dpi<\/code>\uff08\u6bcf\u82f1\u5bf8\u70b9\u6570\uff09\u53c2\u6570\u7528\u4e8e\u8bbe\u7f6e\u56fe\u5f62\u7684\u5206\u8fa8\u7387\u3002\u8f83\u9ad8\u7684 <code>dpi<\/code> \u503c\u4f1a\u4f7f\u56fe\u5f62\u770b\u8d77\u6765\u66f4\u52a0\u6e05\u6670\uff0c\u4f46\u540c\u65f6\u4e5f\u4f1a\u589e\u52a0\u56fe\u5f62\u6587\u4ef6\u7684\u5927\u5c0f\u3002\u53ef\u4ee5\u5728\u521b\u5efa\u56fe\u5f62\u65f6\u901a\u8fc7 <code>figure<\/code> \u51fd\u6570\u7684 <code>dpi<\/code> \u53c2\u6570\u6765\u8bbe\u7f6e\u5206\u8fa8\u7387\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u8bbe\u7f6e\u56fe\u5f62\u5927\u5c0f\u4e3a12x8\u82f1\u5bf8\uff0c\u5206\u8fa8\u7387\u4e3a100 dpi<\/strong><\/h2>\n<p>plt.figure(figsize=(12, 8), dpi=100)<\/p>\n<p>plt.plot([1, 2, 3, 4], [1, 4, 9, 16])<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u53ef\u4ee5\u540c\u65f6\u8c03\u6574\u56fe\u5f62\u7684\u5927\u5c0f\u548c\u6e05\u6670\u5ea6\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u901a\u8fc7 <code>savefig<\/code> \u65b9\u6cd5\u8bbe\u7f6e\u8f93\u51fa\u56fe\u5f62\u7684\u5206\u8fa8\u7387<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u4fdd\u5b58\u56fe\u5f62\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7 <code>savefig<\/code> \u65b9\u6cd5\u7684 <code>dpi<\/code> \u53c2\u6570\u6765\u8bbe\u7f6e\u56fe\u5f62\u7684\u5206\u8fa8\u7387\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>plt.plot([1, 2, 3, 4], [1, 4, 9, 16])<\/p>\n<h2><strong>\u4fdd\u5b58\u56fe\u5f62\uff0c\u5206\u8fa8\u7387\u4e3a300 dpi<\/strong><\/h2>\n<p>plt.savefig(&#39;plot.png&#39;, dpi=300)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u9700\u8981\u8f93\u51fa\u9ad8\u5206\u8fa8\u7387\u56fe\u5f62\u7684\u60c5\u51b5\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u4e09\u3001\u8c03\u6574\u5b50\u56fe\u7684\u5e03\u5c40<\/h3>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528 <code>subplots_adjust<\/code> \u65b9\u6cd5\u8c03\u6574\u5b50\u56fe\u5e03\u5c40<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u521b\u5efa\u591a\u4e2a\u5b50\u56fe\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>subplots_adjust<\/code> \u65b9\u6cd5\u6765\u8c03\u6574\u5b50\u56fe\u4e4b\u95f4\u7684\u95f4\u8ddd\uff0c\u4ece\u800c\u4f18\u5316\u56fe\u5f62\u7684\u5e03\u5c40\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>fig, axs = plt.subplots(2, 2, figsize=(12, 8))<\/p>\n<p>fig.subplots_adjust(hspace=0.4, wspace=0.4)<\/p>\n<p>axs[0, 0].plot([1, 2, 3, 4], [1, 4, 9, 16])<\/p>\n<p>axs[0, 1].plot([1, 2, 3, 4], [1, 4, 9, 16])<\/p>\n<p>axs[1, 0].plot([1, 2, 3, 4], [1, 4, 9, 16])<\/p>\n<p>axs[1, 1].plot([1, 2, 3, 4], [1, 4, 9, 16])<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u8c03\u6574 <code>hspace<\/code> \u548c <code>wspace<\/code> \u53c2\u6570\uff0c\u53ef\u4ee5\u63a7\u5236\u5b50\u56fe\u4e4b\u95f4\u7684\u5782\u76f4\u548c\u6c34\u5e73\u95f4\u8ddd\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528 <code>GridSpec<\/code> \u6a21\u5757\u81ea\u5b9a\u4e49\u5b50\u56fe\u5e03\u5c40<\/strong><\/p>\n<\/p>\n<p><p><code>GridSpec<\/code> \u6a21\u5757\u5141\u8bb8\u66f4\u7075\u6d3b\u5730\u63a7\u5236\u5b50\u56fe\u7684\u5e03\u5c40\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/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, :])<\/p>\n<p>ax2 = fig.add_subplot(gs[1, :-1])<\/p>\n<p>ax3 = fig.add_subplot(gs[1:, -1])<\/p>\n<p>ax4 = fig.add_subplot(gs[-1, 0])<\/p>\n<p>ax5 = fig.add_subplot(gs[-1, -2])<\/p>\n<p>ax1.plot([1, 2, 3, 4], [1, 4, 9, 16])<\/p>\n<p>ax2.plot([1, 2, 3, 4], [1, 4, 9, 16])<\/p>\n<p>ax3.plot([1, 2, 3, 4], [1, 4, 9, 16])<\/p>\n<p>ax4.plot([1, 2, 3, 4], [1, 4, 9, 16])<\/p>\n<p>ax5.plot([1, 2, 3, 4], [1, 4, 9, 16])<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u53ef\u4ee5\u5b9e\u73b0\u66f4\u590d\u6742\u7684\u5e03\u5c40\u9700\u6c42\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u56db\u3001\u4f7f\u7528\u5176\u4ed6\u7ed8\u56fe\u5e93<\/h3>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528 <code>seaborn<\/code> \u5e93\u8c03\u6574\u56fe\u5f62\u5927\u5c0f<\/strong><\/p>\n<\/p>\n<p><p><code>seaborn<\/code> \u662f\u4e00\u4e2a\u57fa\u4e8e <code>matplotlib<\/code> \u7684\u9ad8\u7ea7\u7ed8\u56fe\u5e93\uff0c\u63d0\u4f9b\u4e86\u66f4\u4e3a\u7b80\u6d01\u7684\u63a5\u53e3\u548c\u7f8e\u89c2\u7684\u9ed8\u8ba4\u6837\u5f0f\u3002\u5728 <code>seaborn<\/code> \u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7 <code>set<\/code> \u51fd\u6570\u6765\u8bbe\u7f6e\u56fe\u5f62\u7684\u5927\u5c0f\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\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\u7f6e\u56fe\u5f62\u5927\u5c0f\u4e3a12x8\u82f1\u5bf8<\/strong><\/h2>\n<p>sns.set(rc={&#39;figure.figsize&#39;:(12, 8)})<\/p>\n<p>sns.lineplot(x=[1, 2, 3, 4], y=[1, 4, 9, 16])<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><code>seaborn<\/code> \u63d0\u4f9b\u4e86\u66f4\u4e3a\u7b80\u6d01\u7684\u63a5\u53e3\uff0c\u4f7f\u5f97\u56fe\u5f62\u7684\u8c03\u6574\u66f4\u52a0\u65b9\u4fbf\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528 <code>plotly<\/code> \u5e93\u8c03\u6574\u56fe\u5f62\u5927\u5c0f<\/strong><\/p>\n<\/p>\n<p><p><code>plotly<\/code> \u662f\u4e00\u4e2a\u4ea4\u4e92\u5f0f\u7ed8\u56fe\u5e93\uff0c\u652f\u6301\u591a\u79cd\u7ed8\u56fe\u7c7b\u578b\u548c\u4ea4\u4e92\u529f\u80fd\u3002\u5728 <code>plotly<\/code> \u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7 <code>layout<\/code> \u53c2\u6570\u6765\u8bbe\u7f6e\u56fe\u5f62\u7684\u5927\u5c0f\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import plotly.graph_objects as go<\/p>\n<p>fig = go.Figure(data=go.Scatter(x=[1, 2, 3, 4], y=[1, 4, 9, 16]))<\/p>\n<p>fig.update_layout(width=1200, height=800)<\/p>\n<p>fig.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><code>plotly<\/code> \u652f\u6301\u4ea4\u4e92\u5f0f\u56fe\u5f62\uff0c\u9002\u7528\u4e8e\u9700\u8981\u52a8\u6001\u5c55\u793a\u6570\u636e\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u4e94\u3001\u4f7f\u7528 Jupyter Notebook \u8c03\u6574\u56fe\u5f62\u5927\u5c0f<\/h3>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5728 Jupyter Notebook \u4e2d\u663e\u793a\u56fe\u5f62<\/strong><\/p>\n<\/p>\n<p><p>\u5728 Jupyter Notebook \u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7 <code>%matplotlib inline<\/code> \u9b54\u6cd5\u547d\u4ee4\u6765\u663e\u793a\u56fe\u5f62\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">%matplotlib inline<\/p>\n<p>import matplotlib.pyplot as plt<\/p>\n<p>plt.figure(figsize=(12, 8))<\/p>\n<p>plt.plot([1, 2, 3, 4], [1, 4, 9, 16])<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u5728 Jupyter Notebook \u4e2d\u8fdb\u884c\u6570\u636e\u5206\u6790\u548c\u53ef\u89c6\u5316\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528 <code>IPython.display<\/code> \u6a21\u5757\u8c03\u6574\u56fe\u5f62\u5927\u5c0f<\/strong><\/p>\n<\/p>\n<p><p><code>IPython.display<\/code> \u6a21\u5757\u63d0\u4f9b\u4e86\u66f4\u591a\u7684\u63a7\u5236\u9009\u9879\uff0c\u53ef\u4ee5\u7528\u4e8e\u8c03\u6574\u56fe\u5f62\u7684\u663e\u793a\u65b9\u5f0f\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from IPython.display import set_matplotlib_formats<\/p>\n<p>set_matplotlib_formats(&#39;retina&#39;)<\/p>\n<p>import matplotlib.pyplot as plt<\/p>\n<p>plt.figure(figsize=(12, 8))<\/p>\n<p>plt.plot([1, 2, 3, 4], [1, 4, 9, 16])<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u53ef\u4ee5\u63d0\u9ad8\u56fe\u5f62\u7684\u663e\u793a\u8d28\u91cf\uff0c\u9002\u7528\u4e8e\u9700\u8981\u9ad8\u5206\u8fa8\u7387\u56fe\u5f62\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u4ecb\u7ecd\uff0c\u53ef\u4ee5\u770b\u51fa\u5728Python\u4e2d\u8c03\u6574\u56fe\u5f62\u5927\u5c0f\u7684\u65b9\u6cd5\u591a\u79cd\u591a\u6837\uff0c\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u3002\u65e0\u8bba\u662f\u901a\u8fc7 <code>matplotlib<\/code> \u5e93\u8bbe\u7f6e\u56fe\u5f62\u7684\u5927\u5c0f\u53c2\u6570\u3001\u6539\u53d8\u56fe\u5f62\u7684\u5206\u8fa8\u7387\u3001\u8c03\u6574\u5b50\u56fe\u7684\u5e03\u5c40\uff0c\u8fd8\u662f\u4f7f\u7528\u5176\u4ed6\u7ed8\u56fe\u5e93\u5982 <code>seaborn<\/code> \u548c <code>plotly<\/code>\uff0c\u90fd\u53ef\u4ee5\u5b9e\u73b0\u5bf9\u56fe\u5f62\u5927\u5c0f\u7684\u7cbe\u786e\u63a7\u5236\u3002\u6b64\u5916\uff0c\u5728 Jupyter Notebook \u4e2d\u8fdb\u884c\u56fe\u5f62\u8c03\u6574\u4e5f\u662f\u5e38\u89c1\u7684\u9700\u6c42\uff0c\u53ef\u4ee5\u901a\u8fc7\u76f8\u5e94\u7684\u6280\u5de7\u548c\u65b9\u6cd5\u6765\u5b9e\u73b0\u3002\u5e0c\u671b\u672c\u6587\u5bf9\u60a8\u5728Python\u7ed8\u56fe\u4e2d\u7684\u56fe\u5f62\u5927\u5c0f\u8c03\u6574\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u8c03\u6574\u7ed8\u56fe\u7684\u5c3a\u5bf8\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528Matplotlib\u5e93\u6765\u7ed8\u5236\u56fe\u5f62\u5e76\u8c03\u6574\u56fe\u5f62\u7684\u5c3a\u5bf8\u3002\u901a\u8fc7\u5728\u8c03\u7528<code>plt.figure(figsize=(width, height))<\/code>\u65f6\u8bbe\u7f6e<code>width<\/code>\u548c<code>height<\/code>\u53c2\u6570\uff0c\u53ef\u4ee5\u8f7b\u677e\u6539\u53d8\u56fe\u5f62\u7684\u5927\u5c0f\u3002\u5bbd\u5ea6\u548c\u9ad8\u5ea6\u7684\u5355\u4f4d\u662f\u82f1\u5bf8\uff0c\u56e0\u6b64\u9700\u8981\u6839\u636e\u9700\u8981\u8fdb\u884c\u9002\u5f53\u7684\u8bbe\u7f6e\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728\u7ed8\u56fe\u65f6\u4fdd\u6301\u56fe\u5f62\u7684\u6bd4\u4f8b\uff1f<\/strong><br \/>\u5728\u8c03\u6574\u56fe\u5f62\u5927\u5c0f\u65f6\uff0c\u6709\u65f6\u9700\u8981\u4fdd\u6301\u56fe\u5f62\u7684\u6bd4\u4f8b\u4e0d\u53d8\u3002\u53ef\u4ee5\u4f7f\u7528<code>plt.axis(&#39;equal&#39;)<\/code>\u547d\u4ee4\uff0c\u8fd9\u6837\u65e0\u8bba\u56fe\u5f62\u7684\u5c3a\u5bf8\u5982\u4f55\u53d8\u5316\uff0cX\u8f74\u548cY\u8f74\u7684\u6bd4\u4f8b\u90fd\u4f1a\u4fdd\u6301\u4e00\u81f4\u3002\u8fd9\u6837\u53ef\u4ee5\u786e\u4fdd\u56fe\u5f62\u5728\u653e\u5927\u6216\u7f29\u5c0f\u65f6\u4e0d\u4f1a\u5931\u771f\u3002<\/p>\n<p><strong>\u4f7f\u7528\u5176\u4ed6\u5e93\u65f6\uff0c\u5982\u4f55\u8c03\u6574\u56fe\u5f62\u7684\u5c3a\u5bf8\uff1f<\/strong><br \/>\u9664\u4e86Matplotlib\uff0c\u5176\u4ed6\u7ed8\u56fe\u5e93\u5982Seaborn\u548cPlotly\u4e5f\u5141\u8bb8\u7528\u6237\u8c03\u6574\u56fe\u5f62\u7684\u5c3a\u5bf8\u3002\u5728Seaborn\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e<code>plt.figure(figsize=(width, height))<\/code>\u6765\u6539\u53d8\u5c3a\u5bf8\uff0c\u800c\u5728Plotly\u4e2d\uff0c\u53ef\u4ee5\u5728\u521b\u5efa\u56fe\u5f62\u65f6\u6307\u5b9a<code>width<\/code>\u548c<code>height<\/code>\u53c2\u6570\u3002\u6839\u636e\u6240\u7528\u5e93\u7684\u4e0d\u540c\uff0c\u5177\u4f53\u65b9\u6cd5\u53ef\u80fd\u6709\u6240\u4e0d\u540c\uff0c\u4f46\u57fa\u672c\u601d\u8def\u662f\u7c7b\u4f3c\u7684\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\uff0c\u8c03\u6574\u753b\u51fa\u6765\u7684\u56fe\u7684\u5927\u5c0f\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u6cd5\u5b9e\u73b0\uff0c\u4e3b\u8981\u5305\u62ec\uff1a\u8bbe\u7f6e\u56fe\u5f62\u7684\u5927\u5c0f\u53c2\u6570\u3001\u6539\u53d8\u56fe\u5f62\u7684\u5206\u8fa8\u7387\u3001\u8c03 [&hellip;]","protected":false},"author":3,"featured_media":1111785,"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\/1111773"}],"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=1111773"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1111773\/revisions"}],"predecessor-version":[{"id":1111786,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1111773\/revisions\/1111786"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1111785"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1111773"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1111773"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1111773"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}