{"id":1001516,"date":"2024-12-27T10:00:58","date_gmt":"2024-12-27T02:00:58","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1001516.html"},"modified":"2024-12-27T10:01:01","modified_gmt":"2024-12-27T02:01:01","slug":"python%e5%a6%82%e4%bd%95%e8%b0%83%e6%95%b4%e7%94%bb%e5%9b%be%e5%a4%a7%e5%b0%8f","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1001516.html","title":{"rendered":"python\u5982\u4f55\u8c03\u6574\u753b\u56fe\u5927\u5c0f"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25075639\/a419f4a8-9bc7-4173-bf92-fa08baf20d80.webp\" alt=\"python\u5982\u4f55\u8c03\u6574\u753b\u56fe\u5927\u5c0f\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u8c03\u6574\u753b\u56fe\u5927\u5c0f\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u5b9e\u73b0\uff0c\u5982\u4f7f\u7528matplotlib\u5e93\u7684figsize\u53c2\u6570\u3001\u8c03\u6574\u5b50\u56fe\u5e03\u5c40\u3001\u8bbe\u7f6e\u8f74\u8303\u56f4\u7b49\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u5e76\u6df1\u5165\u63a2\u8ba8\u5982\u4f55\u5728\u4e0d\u540c\u573a\u666f\u4e2d\u5e94\u7528\u8fd9\u4e9b\u6280\u5de7\u6765\u63d0\u5347\u56fe\u5f62\u7684\u53ef\u8bfb\u6027\u548c\u7f8e\u89c2\u5ea6\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u65e5\u5e38\u7684\u6570\u636e\u5206\u6790\u548c\u53ef\u89c6\u5316\u5de5\u4f5c\u4e2d\uff0c<strong>\u4f7f\u7528matplotlib\u5e93\u7684figsize\u53c2\u6570\u662f\u6700\u4e3a\u76f4\u63a5\u4e14\u5e38\u7528\u7684\u65b9\u6cd5<\/strong>\u3002\u901a\u8fc7\u6307\u5b9a\u56fe\u5f62\u7684\u5bbd\u5ea6\u548c\u9ad8\u5ea6\uff0c\u53ef\u4ee5\u8f7b\u677e\u8c03\u6574\u56fe\u5f62\u7684\u5927\u5c0f\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u901a\u8fc7plt.figure(figsize=(width, height))\u6765\u8bbe\u7f6e\u56fe\u5f62\u7684\u5c3a\u5bf8\uff0c\u4ee5\u786e\u4fdd\u5728\u4e0d\u540c\u8bbe\u5907\u4e0a\u663e\u793a\u65f6\u4f9d\u7136\u4fdd\u6301\u6e05\u6670\u53ef\u8bfb\u3002\u8fd9\u79cd\u65b9\u6cd5\u7279\u522b\u9002\u5408\u5728\u9700\u8981\u540c\u65f6\u5c55\u793a\u591a\u4e2a\u56fe\u5f62\u65f6\u4f7f\u7528\uff0c\u4ee5\u907f\u514d\u56fe\u5f62\u8fc7\u4e8e\u5bc6\u96c6\u6216\u8fc7\u4e8e\u7a00\u758f\u3002<\/p>\n<\/p>\n<hr>\n<p><p>\u4e00\u3001MATPLOTLIB\u5e93\u7684FIGSIZE\u53c2\u6570<\/p>\n<\/p>\n<p><p>matplotlib\u662fPython\u4e2d\u6700\u5e38\u7528\u7684\u7ed8\u56fe\u5e93\u4e4b\u4e00\uff0c\u5176\u4e2d\u7684figsize\u53c2\u6570\u662f\u8c03\u6574\u56fe\u5f62\u5927\u5c0f\u7684\u5173\u952e\u5de5\u5177\u3002\u901a\u8fc7\u5408\u7406\u4f7f\u7528figsize\uff0c\u6211\u4eec\u53ef\u4ee5\u63a7\u5236\u56fe\u5f62\u7684\u5bbd\u5ea6\u548c\u9ad8\u5ea6\uff0c\u4ece\u800c\u4f7f\u56fe\u5f62\u5728\u5404\u79cd\u8bbe\u5907\u548c\u5c4f\u5e55\u4e0a\u90fd\u80fd\u4fdd\u6301\u826f\u597d\u7684\u663e\u793a\u6548\u679c\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u57fa\u672c\u7528\u6cd5<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u4f7f\u7528matplotlib\u7ed8\u5236\u56fe\u5f62\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7plt.figure(figsize=(width, height))\u6765\u8bbe\u7f6e\u56fe\u5f62\u7684\u5927\u5c0f\u3002\u8fd9\u91cc\u7684width\u548cheight\u5206\u522b\u4ee3\u8868\u56fe\u5f62\u7684\u5bbd\u5ea6\u548c\u9ad8\u5ea6\uff0c\u5355\u4f4d\u662f\u82f1\u5bf8\u3002\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u5355\u4e2a\u56fe\u5f62\u7684\u8c03\u6574\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>plt.figure(figsize=(10, 5))<\/p>\n<p>plt.plot([1, 2, 3, 4], [10, 20, 25, 30])<\/p>\n<p>plt.title(&#39;Example Plot&#39;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4ee5\u4e0a\u4ee3\u7801\u4e2d\uff0cfigsize\u53c2\u6570\u5c06\u56fe\u5f62\u7684\u5bbd\u5ea6\u8bbe\u7f6e\u4e3a10\u82f1\u5bf8\uff0c\u9ad8\u5ea6\u8bbe\u7f6e\u4e3a5\u82f1\u5bf8\u3002\u8fd9\u79cd\u8c03\u6574\u53ef\u4ee5\u786e\u4fdd\u56fe\u5f62\u5728\u4e0d\u540c\u8bbe\u5907\u4e0a\u90fd\u6709\u826f\u597d\u7684\u5c55\u793a\u6548\u679c\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5728\u5b50\u56fe\u4e2d\u4f7f\u7528<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u9700\u8981\u7ed8\u5236\u591a\u4e2a\u5b50\u56fe\u65f6\uff0cfigsize\u4e5f\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u8fdb\u884c\u5e03\u5c40\u8c03\u6574\uff0c\u786e\u4fdd\u6bcf\u4e2a\u5b50\u56fe\u90fd\u6709\u8db3\u591f\u7684\u7a7a\u95f4\u5c55\u793a\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">fig, axs = plt.subplots(2, 2, figsize=(12, 8))<\/p>\n<p>axs[0, 0].plot([1, 2, 3], [1, 4, 9])<\/p>\n<p>axs[0, 1].plot([1, 2, 3], [1, 2, 3])<\/p>\n<p>axs[1, 0].plot([1, 2, 3], [10, 20, 30])<\/p>\n<p>axs[1, 1].plot([1, 2, 3], [30, 20, 10])<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528figsize\u53c2\u6570\u5c06\u6574\u4e2a\u56fe\u5f62\u7684\u5927\u5c0f\u8bbe\u7f6e\u4e3a12&#215;8\u82f1\u5bf8\uff0c\u4ece\u800c\u786e\u4fdd\u6bcf\u4e2a\u5b50\u56fe\u90fd\u6709\u8db3\u591f\u7684\u7a7a\u95f4\u8fdb\u884c\u5c55\u793a\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e8c\u3001\u8c03\u6574\u5b50\u56fe\u5e03\u5c40<\/p>\n<\/p>\n<p><p>\u5728\u591a\u5b50\u56fe\u7684\u60c5\u51b5\u4e0b\uff0c\u8c03\u6574\u5b50\u56fe\u7684\u5e03\u5c40\u662f\u786e\u4fdd\u6574\u4f53\u56fe\u5f62\u7f8e\u89c2\u7684\u91cd\u8981\u6b65\u9aa4\u3002\u5408\u7406\u7684\u5e03\u5c40\u4e0d\u4ec5\u53ef\u4ee5\u907f\u514d\u56fe\u5f62\u4e4b\u95f4\u7684\u91cd\u53e0\uff0c\u8fd8\u53ef\u4ee5\u63d0\u5347\u56fe\u5f62\u7684\u53ef\u8bfb\u6027\u548c\u4fe1\u606f\u4f20\u8fbe\u6548\u7387\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528tight_layout<\/strong><\/p>\n<\/p>\n<p><p>tight_layout\u662fmatplotlib\u4e2d\u7684\u4e00\u4e2a\u529f\u80fd\uff0c\u7528\u4e8e\u81ea\u52a8\u8c03\u6574\u5b50\u56fe\u53c2\u6570\uff0c\u4ee5\u51cf\u5c11\u5b50\u56fe\u4e4b\u95f4\u7684\u91cd\u53e0\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">fig, axs = plt.subplots(2, 2)<\/p>\n<p>fig.tight_layout(pad=3.0)<\/p>\n<p>axs[0, 0].plot([1, 2, 3], [1, 4, 9])<\/p>\n<p>axs[0, 1].plot([1, 2, 3], [1, 2, 3])<\/p>\n<p>axs[1, 0].plot([1, 2, 3], [10, 20, 30])<\/p>\n<p>axs[1, 1].plot([1, 2, 3], [30, 20, 10])<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u8c03\u7528fig.tight_layout(pad=3.0)\uff0c\u6211\u4eec\u53ef\u4ee5\u81ea\u52a8\u8c03\u6574\u5404\u4e2a\u5b50\u56fe\u4e4b\u95f4\u7684\u8ddd\u79bb\uff0c\u4ee5\u907f\u514d\u91cd\u53e0\u3002pad\u53c2\u6570\u7528\u4e8e\u63a7\u5236\u5b50\u56fe\u4e4b\u95f4\u7684\u95f4\u8ddd\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528GridSpec<\/strong><\/p>\n<\/p>\n<p><p>GridSpec\u662fmatplotlib\u4e2d\u7684\u53e6\u4e00\u4e2a\u5de5\u5177\uff0c\u63d0\u4f9b\u4e86\u66f4\u4e3a\u7075\u6d3b\u7684\u5b50\u56fe\u5e03\u5c40\u65b9\u5f0f\u3002\u4e0etight_layout\u4e0d\u540c\uff0cGridSpec\u5141\u8bb8\u6211\u4eec\u5bf9\u6bcf\u4e2a\u5b50\u56fe\u7684\u5c3a\u5bf8\u8fdb\u884c\u66f4\u7ec6\u81f4\u7684\u63a7\u5236\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.gridspec as gridspec<\/p>\n<p>fig = plt.figure(figsize=(10, 8))<\/p>\n<p>gs = gridspec.GridSpec(3, 3, figure=fig)<\/p>\n<p>ax1 = fig.add_subplot(gs[0, :])<\/p>\n<p>ax1.plot([1, 2, 3], [1, 4, 9])<\/p>\n<p>ax2 = fig.add_subplot(gs[1, :-1])<\/p>\n<p>ax2.plot([1, 2, 3], [1, 2, 3])<\/p>\n<p>ax3 = fig.add_subplot(gs[1:, -1])<\/p>\n<p>ax3.plot([1, 2, 3], [10, 20, 30])<\/p>\n<p>ax4 = fig.add_subplot(gs[2, 0])<\/p>\n<p>ax4.plot([1, 2, 3], [30, 20, 10])<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f7f\u7528GridSpec\uff0c\u6211\u4eec\u53ef\u4ee5\u6307\u5b9a\u6bcf\u4e2a\u5b50\u56fe\u5360\u636e\u7684\u7f51\u683c\u4f4d\u7f6e\uff0c\u4ece\u800c\u5b9e\u73b0\u590d\u6742\u7684\u56fe\u5f62\u5e03\u5c40\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e09\u3001\u8bbe\u7f6e\u8f74\u8303\u56f4\u548c\u6bd4\u4f8b<\/p>\n<\/p>\n<p><p>\u9664\u4e86\u8c03\u6574\u56fe\u5f62\u7684\u6574\u4f53\u5927\u5c0f\u548c\u5e03\u5c40\u5916\uff0c\u8bbe\u7f6e\u8f74\u8303\u56f4\u548c\u6bd4\u4f8b\u4e5f\u662f\u786e\u4fdd\u56fe\u5f62\u7f8e\u89c2\u7684\u91cd\u8981\u6b65\u9aa4\u3002\u901a\u8fc7\u5408\u7406\u8bbe\u7f6e\u8f74\u8303\u56f4\u548c\u6bd4\u4f8b\uff0c\u53ef\u4ee5\u4f7f\u6570\u636e\u5728\u56fe\u5f62\u4e2d\u5f97\u5230\u66f4\u597d\u7684\u5c55\u793a\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u8bbe\u7f6e\u8f74\u8303\u56f4<\/strong><\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u8bbe\u7f6e\u8f74\u8303\u56f4\uff0c\u6211\u4eec\u53ef\u4ee5\u63a7\u5236\u56fe\u5f62\u4e2d\u663e\u793a\u7684\u6570\u636e\u8303\u56f4\uff0c\u4ece\u800c\u7a81\u51fa\u91cd\u70b9\u6570\u636e\u6216\u9690\u85cf\u4e0d\u5fc5\u8981\u7684\u4fe1\u606f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.figure(figsize=(10, 5))<\/p>\n<p>plt.plot([1, 2, 3, 4], [10, 20, 25, 30])<\/p>\n<p>plt.xlim(1, 4)<\/p>\n<p>plt.ylim(10, 30)<\/p>\n<p>plt.title(&#39;Example Plot with Axis Limits&#39;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4ee5\u4e0a\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u901a\u8fc7xlim\u548cylim\u51fd\u6570\u8bbe\u7f6e\u4e86x\u8f74\u548cy\u8f74\u7684\u663e\u793a\u8303\u56f4\uff0c\u4ece\u800c\u786e\u4fdd\u56fe\u5f62\u5c55\u793a\u7684\u6570\u636e\u5728\u6211\u4eec\u5173\u6ce8\u7684\u8303\u56f4\u5185\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8bbe\u7f6e\u8f74\u6bd4\u4f8b<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528equal\u6bd4\u4f8b\u8bbe\u7f6e\u53ef\u4ee5\u786e\u4fdd\u56fe\u5f62\u4e2d\u7684x\u8f74\u548cy\u8f74\u5177\u6709\u76f8\u540c\u7684\u6bd4\u4f8b\uff0c\u4ece\u800c\u907f\u514d\u6570\u636e\u5728\u89c6\u89c9\u4e0a\u7684\u5931\u771f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.figure(figsize=(6, 6))<\/p>\n<p>plt.plot([0, 1, 2], [0, 1, 4])<\/p>\n<p>plt.axis(&#39;equal&#39;)<\/p>\n<p>plt.title(&#39;Equal Aspect Ratio&#39;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7axis(&#39;equal&#39;)\u51fd\u6570\uff0c\u56fe\u5f62\u7684x\u8f74\u548cy\u8f74\u6bd4\u4f8b\u88ab\u8bbe\u7f6e\u4e3a\u76f8\u7b49\uff0c\u4ece\u800c\u786e\u4fdd\u6570\u636e\u5728\u56fe\u5f62\u4e2d\u7684\u771f\u5b9e\u5c55\u793a\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u4f7f\u7528\u5176\u4ed6\u7ed8\u56fe\u5e93<\/p>\n<\/p>\n<p><p>\u867d\u7136matplotlib\u662fPython\u4e2d\u6700\u5e38\u7528\u7684\u7ed8\u56fe\u5e93\u4e4b\u4e00\uff0c\u4f46\u5728\u7279\u5b9a\u60c5\u51b5\u4e0b\uff0c\u5176\u4ed6\u7ed8\u56fe\u5e93\u4e5f\u53ef\u4ee5\u63d0\u4f9b\u66f4\u52a0\u4fbf\u6377\u6216\u4e13\u4e1a\u7684\u89e3\u51b3\u65b9\u6848\u3002\u4f8b\u5982\uff0cseaborn\u3001plotly\u548cbokeh\u7b49\u5e93\u90fd\u63d0\u4f9b\u4e86\u4e0d\u540c\u7684\u56fe\u5f62\u8c03\u6574\u529f\u80fd\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>Seaborn<\/strong><\/p>\n<\/p>\n<p><p>seaborn\u662f\u57fa\u4e8ematplotlib\u7684\u9ad8\u7ea7\u7ed8\u56fe\u5e93\uff0c\u63d0\u4f9b\u4e86\u66f4\u52a0\u7f8e\u89c2\u7684\u56fe\u5f62\u6837\u5f0f\u548c\u66f4\u52a0\u7b80\u4fbf\u7684\u7ed8\u56fe\u51fd\u6570\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import seaborn as sns<\/p>\n<p>data = sns.load_dataset(&#39;iris&#39;)<\/p>\n<p>sns.set(style=&quot;whitegrid&quot;)<\/p>\n<p>plt.figure(figsize=(10, 6))<\/p>\n<p>sns.boxplot(x=&quot;species&quot;, y=&quot;sepal_length&quot;, data=data)<\/p>\n<p>plt.title(&#39;Boxplot of Sepal Length by Species&#39;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528seaborn\u7ed8\u5236\u4e86\u4e00\u4e2a\u7f8e\u89c2\u7684\u7bb1\u7ebf\u56fe\uff0c\u5e76\u901a\u8fc7figsize\u53c2\u6570\u8c03\u6574\u4e86\u56fe\u5f62\u7684\u5927\u5c0f\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>Plotly<\/strong><\/p>\n<\/p>\n<p><p>plotly\u662f\u4e00\u4e2a\u4ea4\u4e92\u5f0f\u7ed8\u56fe\u5e93\uff0c\u9002\u5408\u7528\u4e8e\u9700\u8981\u7528\u6237\u4ea4\u4e92\u7684\u56fe\u5f62\u5c55\u793a\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import plotly.express as px<\/p>\n<p>df = px.data.iris()<\/p>\n<p>fig = px.scatter(df, x=&quot;sepal_width&quot;, y=&quot;sepal_length&quot;, color=&quot;species&quot;, title=&quot;Scatter Plot of Iris Dataset&quot;)<\/p>\n<p>fig.update_layout(width=800, height=500)<\/p>\n<p>fig.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f7f\u7528plotly\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u521b\u5efa\u4ea4\u4e92\u5f0f\u56fe\u5f62\uff0c\u5e76\u901a\u8fc7update_layout\u51fd\u6570\u8c03\u6574\u56fe\u5f62\u7684\u5927\u5c0f\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>Bokeh<\/strong><\/p>\n<\/p>\n<p><p>bokeh\u662f\u53e6\u4e00\u4e2a\u7528\u4e8e\u4ea4\u4e92\u5f0f\u7ed8\u56fe\u7684\u5e93\uff0c\u9002\u5408\u7528\u4e8e\u7f51\u9875\u5c55\u793a\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from bokeh.plotting import figure, show<\/p>\n<p>from bokeh.io import output_notebook<\/p>\n<p>output_notebook()<\/p>\n<p>p = figure(plot_width=800, plot_height=400, title=&quot;Line Plot Example&quot;)<\/p>\n<p>p.line([1, 2, 3, 4], [10, 20, 25, 30], line_width=2)<\/p>\n<p>show(p)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528bokeh\u7ed8\u5236\u4e86\u4e00\u6761\u7b80\u5355\u7684\u6298\u7ebf\u56fe\uff0c\u5e76\u901a\u8fc7plot_width\u548cplot_height\u53c2\u6570\u8c03\u6574\u4e86\u56fe\u5f62\u7684\u5927\u5c0f\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e94\u3001\u603b\u7ed3\u4e0e\u5b9e\u8df5\u5efa\u8bae<\/p>\n<\/p>\n<p><p>\u8c03\u6574\u56fe\u5f62\u5927\u5c0f\u662fPython\u6570\u636e\u53ef\u89c6\u5316\u4e2d\u7684\u4e00\u9879\u57fa\u672c\u6280\u80fd\uff0c\u901a\u8fc7\u5408\u7406\u8c03\u6574\u56fe\u5f62\u5927\u5c0f\u548c\u5e03\u5c40\uff0c\u53ef\u4ee5\u5927\u5927\u63d0\u5347\u56fe\u5f62\u7684\u7f8e\u89c2\u5ea6\u548c\u4fe1\u606f\u4f20\u8fbe\u6548\u7387\u3002\u5728\u5b9e\u8df5\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u4e0d\u540c\u7684\u8c03\u6574\u65b9\u6cd5\u548c\u7ed8\u56fe\u5e93\uff0c\u4ee5\u6ee1\u8db3\u4e0d\u540c\u573a\u666f\u4e0b\u7684\u53ef\u89c6\u5316\u9700\u6c42\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u6839\u636e\u6570\u636e\u7c7b\u578b\u9009\u62e9\u7ed8\u56fe\u5e93<\/strong><\/p>\n<\/p>\n<p><p>\u4e0d\u540c\u7684\u7ed8\u56fe\u5e93\u5728\u7279\u5b9a\u7c7b\u578b\u7684\u56fe\u5f62\u5c55\u793a\u4e0a\u5177\u6709\u4e0d\u540c\u7684\u4f18\u52bf\uff0c\u4f8b\u5982seaborn\u9002\u5408\u7edf\u8ba1\u6570\u636e\u5c55\u793a\uff0cplotly\u548cbokeh\u9002\u5408\u4ea4\u4e92\u5f0f\u56fe\u5f62\u5c55\u793a\u3002\u5728\u9009\u62e9\u7ed8\u56fe\u5e93\u65f6\uff0c\u5e94\u6839\u636e\u6570\u636e\u7c7b\u578b\u548c\u5c55\u793a\u9700\u6c42\u8fdb\u884c\u9009\u62e9\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5408\u7406\u8bbe\u7f6efigsize\u548c\u5e03\u5c40<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u7ed8\u5236\u56fe\u5f62\u65f6\uff0c\u5408\u7406\u8bbe\u7f6efigsize\u548c\u5e03\u5c40\u662f\u786e\u4fdd\u56fe\u5f62\u7f8e\u89c2\u7684\u5173\u952e\u6b65\u9aa4\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u5b9e\u9a8c\u4e0d\u540c\u7684figsize\u53c2\u6570\u548c\u5e03\u5c40\u8bbe\u7f6e\uff0c\u627e\u5230\u6700\u9002\u5408\u5f53\u524d\u6570\u636e\u7684\u56fe\u5f62\u5c55\u793a\u65b9\u5f0f\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5145\u5206\u5229\u7528\u8f74\u8303\u56f4\u548c\u6bd4\u4f8b\u8bbe\u7f6e<\/strong><\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u8bbe\u7f6e\u8f74\u8303\u56f4\u548c\u6bd4\u4f8b\uff0c\u53ef\u4ee5\u7a81\u51fa\u6570\u636e\u7684\u91cd\u70b9\u90e8\u5206\u6216\u786e\u4fdd\u6570\u636e\u7684\u771f\u5b9e\u5c55\u793a\u3002\u5728\u8fdb\u884c\u8fd9\u7c7b\u8bbe\u7f6e\u65f6\uff0c\u5e94\u6839\u636e\u6570\u636e\u7684\u5177\u4f53\u7279\u5f81\u548c\u5206\u6790\u76ee\u7684\u8fdb\u884c\u8c03\u6574\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u672c\u6587\u7684\u4ecb\u7ecd\uff0c\u5e0c\u671b\u80fd\u591f\u5e2e\u52a9\u60a8\u5728Python\u4e2d\u66f4\u597d\u5730\u8c03\u6574\u56fe\u5f62\u5927\u5c0f\uff0c\u63d0\u5347\u56fe\u5f62\u7684\u5c55\u793a\u6548\u679c\u548c\u4fe1\u606f\u4f20\u8fbe\u6548\u7387\u3002\u65e0\u8bba\u662f\u5728\u5b66\u672f\u7814\u7a76\u8fd8\u662f\u5728\u5546\u4e1a\u5e94\u7528\u4e2d\uff0c\u4f18\u79c0\u7684\u6570\u636e\u53ef\u89c6\u5316\u90fd\u80fd\u591f\u4e3a\u51b3\u7b56\u63d0\u4f9b\u6709\u529b\u652f\u6301\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u8c03\u6574\u56fe\u5f62\u7684\u5927\u5c0f\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528Matplotlib\u5e93\u7684<code>figure()<\/code>\u51fd\u6570\u6765\u8bbe\u7f6e\u56fe\u5f62\u7684\u5927\u5c0f\u3002\u901a\u8fc7\u4f20\u9012<code>figsize<\/code>\u53c2\u6570\uff08\u4f8b\u5982\uff0c<code>figsize=(\u5bbd\u5ea6, \u9ad8\u5ea6)<\/code>\uff09\u53ef\u4ee5\u8f7b\u677e\u8c03\u6574\u7ed8\u56fe\u7684\u5c3a\u5bf8\u3002\u8fd9\u4e2a\u53c2\u6570\u7684\u5355\u4f4d\u662f\u82f1\u5bf8\uff0c\u786e\u4fdd\u6839\u636e\u663e\u793a\u6216\u6253\u5370\u9700\u6c42\u8bbe\u7f6e\u5408\u9002\u7684\u5bbd\u9ad8\u6bd4\u3002<\/p>\n<p><strong>\u4e3a\u4ec0\u4e48\u56fe\u5f62\u7684\u5927\u5c0f\u8c03\u6574\u5bf9\u6570\u636e\u53ef\u89c6\u5316\u5f88\u91cd\u8981\uff1f<\/strong><br \/>\u56fe\u5f62\u7684\u5927\u5c0f\u76f4\u63a5\u5f71\u54cd\u4fe1\u606f\u7684\u53ef\u8bfb\u6027\u548c\u7f8e\u89c2\u5ea6\u3002\u5728\u6570\u636e\u5bc6\u96c6\u578b\u7684\u56fe\u8868\u4e2d\uff0c\u9002\u5f53\u7684\u5927\u5c0f\u53ef\u4ee5\u907f\u514d\u4fe1\u606f\u62e5\u6324\uff0c\u63d0\u5347\u6570\u636e\u7684\u53ef\u89c6\u5316\u6548\u679c\u3002\u6b64\u5916\uff0c\u5408\u9002\u7684\u56fe\u5f62\u5927\u5c0f\u4e5f\u4f7f\u5f97\u5728\u4e0d\u540c\u8bbe\u5907\u4e0a\uff08\u5982\u7535\u8111\u3001\u624b\u673a\uff09\u5c55\u793a\u65f6\uff0c\u80fd\u591f\u66f4\u597d\u5730\u9002\u5e94\u5c4f\u5e55\u5c3a\u5bf8\u3002<\/p>\n<p><strong>\u4f7f\u7528Python\u7ed8\u56fe\u65f6\uff0c\u5982\u4f55\u786e\u4fdd\u56fe\u5f62\u5728\u4e0d\u540c\u5e73\u53f0\u4e0a\u663e\u793a\u4e00\u81f4\uff1f<\/strong><br \/>\u4e3a\u4e86\u5728\u4e0d\u540c\u5e73\u53f0\u4e0a\u4fdd\u6301\u56fe\u5f62\u7684\u4e00\u81f4\u6027\uff0c\u53ef\u4ee5\u4f7f\u7528<code>dpi<\/code>\uff08\u6bcf\u82f1\u5bf8\u70b9\u6570\uff09\u53c2\u6570\u6765\u8bbe\u7f6e\u56fe\u5f62\u7684\u5206\u8fa8\u7387\u3002\u901a\u8fc7\u8bbe\u7f6e<code>dpi<\/code>\uff0c\u53ef\u4ee5\u786e\u4fdd\u56fe\u5f62\u5728\u9ad8\u5206\u8fa8\u7387\u663e\u793a\u5668\u4e0a\u4f9d\u7136\u6e05\u6670\u3002\u6b64\u5916\uff0c\u4f7f\u7528<code>tight_layout()<\/code>\u51fd\u6570\u4e5f\u80fd\u6709\u6548\u907f\u514d\u5143\u7d20\u91cd\u53e0\uff0c\u786e\u4fdd\u56fe\u5f62\u5728\u5404\u79cd\u5e73\u53f0\u4e0a\u90fd\u80fd\u4fdd\u6301\u826f\u597d\u7684\u5c55\u793a\u6548\u679c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u8c03\u6574\u753b\u56fe\u5927\u5c0f\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u5b9e\u73b0\uff0c\u5982\u4f7f\u7528matplotlib\u5e93\u7684figsize\u53c2\u6570\u3001\u8c03\u6574\u5b50\u56fe\u5e03 [&hellip;]","protected":false},"author":3,"featured_media":1001531,"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\/1001516"}],"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=1001516"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1001516\/revisions"}],"predecessor-version":[{"id":1001533,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1001516\/revisions\/1001533"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1001531"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1001516"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1001516"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1001516"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}