{"id":1122437,"date":"2025-01-08T19:20:37","date_gmt":"2025-01-08T11:20:37","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1122437.html"},"modified":"2025-01-08T19:20:41","modified_gmt":"2025-01-08T11:20:41","slug":"python%e5%a6%82%e4%bd%95%e6%8c%87%e5%ae%9a%e5%9d%90%e6%a0%87%e8%bd%b4%e5%8f%aa%e6%98%be%e7%a4%ba%e9%83%a8%e5%88%86","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1122437.html","title":{"rendered":"python\u5982\u4f55\u6307\u5b9a\u5750\u6807\u8f74\u53ea\u663e\u793a\u90e8\u5206"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25084304\/bf661521-7bb1-4a0e-bda1-93ef73a48c67.webp\" alt=\"python\u5982\u4f55\u6307\u5b9a\u5750\u6807\u8f74\u53ea\u663e\u793a\u90e8\u5206\" \/><\/p>\n<p><p> <strong>Python\u5982\u4f55\u6307\u5b9a\u5750\u6807\u8f74\u53ea\u663e\u793a\u90e8\u5206\uff1a\u4f7f\u7528Matplotlib\u7684<code>set_xlim<\/code>\u548c<code>set_ylim<\/code>\u65b9\u6cd5\u3001\u8bbe\u7f6e\u523b\u5ea6\u8303\u56f4\u3001\u9690\u85cf\u4e0d\u9700\u8981\u7684\u523b\u5ea6\u6807\u7b7e<\/strong>\u3002\u5176\u4e2d\uff0c\u4f7f\u7528Matplotlib\u7684<code>set_xlim<\/code>\u548c<code>set_ylim<\/code>\u65b9\u6cd5\u662f\u6700\u5e38\u89c1\u7684\u65b9\u5f0f\uff0c\u80fd\u591f\u8f7b\u677e\u5730\u8bbe\u5b9aX\u8f74\u548cY\u8f74\u663e\u793a\u7684\u8303\u56f4\u3002<\/p>\n<\/p>\n<p><p><strong>\u4f7f\u7528Matplotlib\u7684<code>set_xlim<\/code>\u548c<code>set_ylim<\/code>\u65b9\u6cd5<\/strong>\u53ef\u4ee5\u8ba9\u4f60\u81ea\u7531\u5730\u8bbe\u5b9a\u5750\u6807\u8f74\u7684\u663e\u793a\u8303\u56f4\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u53ea\u60f3\u663e\u793aX\u8f74\u4ece0\u523010\u7684\u90e8\u5206\uff0c\u53ef\u4ee5\u4f7f\u7528<code>plt.xlim(0, 10)<\/code>\u6765\u5b9e\u73b0\u3002\u540c\u6837\u5730\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528<code>plt.ylim<\/code>\u6765\u8bbe\u5b9aY\u8f74\u7684\u8303\u56f4\u3002\u8fd9\u79cd\u65b9\u6cd5\u975e\u5e38\u76f4\u89c2\u4e14\u6613\u4e8e\u5b9e\u73b0\u3002\u9664\u6b64\u4e4b\u5916\uff0c\u4f60\u8fd8\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u523b\u5ea6\u8303\u56f4\u548c\u9690\u85cf\u4e0d\u9700\u8981\u7684\u523b\u5ea6\u6807\u7b7e\u6765\u8fdb\u4e00\u6b65\u4f18\u5316\u5750\u6807\u8f74\u7684\u663e\u793a\u6548\u679c\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001Matplotlib\u7b80\u4ecb<\/h3>\n<\/p>\n<p><p>Matplotlib\u662f\u4e00\u4e2aPython\u76842D\u7ed8\u56fe\u5e93\uff0c\u80fd\u591f\u751f\u6210\u51fa\u7248\u8d28\u91cf\u7684\u56fe\u5f62\uff0c\u4e14\u652f\u6301\u591a\u79cd\u8f93\u51fa\u683c\u5f0f\u3002\u5b83\u901a\u5e38\u4e0eNumPy\u4e00\u8d77\u4f7f\u7528\uff0c\u80fd\u591f\u8f7b\u677e\u7ed8\u5236\u51fa\u5404\u79cd\u590d\u6742\u7684\u56fe\u5f62\u3002Matplotlib\u5728\u6570\u636e\u79d1\u5b66\u3001<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u3001\u5de5\u7a0b\u7b49\u9886\u57df\u90fd\u6709\u5e7f\u6cdb\u7684\u5e94\u7528\u3002<\/p>\n<\/p>\n<p><p>Matplotlib\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u529f\u80fd\u6765\u5b9a\u5236\u56fe\u5f62\uff0c\u5305\u62ec\u4f46\u4e0d\u9650\u4e8e\u8bbe\u7f6e\u5750\u6807\u8f74\u3001\u56fe\u4f8b\u3001\u6807\u9898\u3001\u6807\u7b7e\u7b49\u3002\u5176\u7075\u6d3b\u6027\u548c\u5f3a\u5927\u7684\u529f\u80fd\u4f7f\u5176\u6210\u4e3aPython\u4e2d\u6700\u5e38\u7528\u7684\u7ed8\u56fe\u5e93\u4e4b\u4e00\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528<code>set_xlim<\/code>\u548c<code>set_ylim<\/code><\/h3>\n<\/p>\n<p><h4>1. \u57fa\u672c\u4f7f\u7528\u65b9\u6cd5<\/h4>\n<\/p>\n<p><p>\u8981\u6307\u5b9a\u5750\u6807\u8f74\u53ea\u663e\u793a\u90e8\u5206\uff0c\u53ef\u4ee5\u4f7f\u7528<code>set_xlim<\/code>\u548c<code>set_ylim<\/code>\u65b9\u6cd5\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<p>import numpy as np<\/p>\n<p>x = np.linspace(-10, 10, 100)<\/p>\n<p>y = np.sin(x)<\/p>\n<p>plt.plot(x, y)<\/p>\n<p>plt.xlim(0, 10)  # \u8bbe\u7f6eX\u8f74\u8303\u56f4<\/p>\n<p>plt.ylim(-1, 1)  # \u8bbe\u7f6eY\u8f74\u8303\u56f4<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u901a\u8fc7<code>plt.xlim(0, 10)<\/code>\u8bbe\u7f6e\u4e86X\u8f74\u7684\u8303\u56f4\u4e3a0\u523010\uff0c\u800c\u901a\u8fc7<code>plt.ylim(-1, 1)<\/code>\u8bbe\u7f6e\u4e86Y\u8f74\u7684\u8303\u56f4\u4e3a-1\u52301\u3002<\/p>\n<\/p>\n<p><h4>2. \u9ad8\u7ea7\u7528\u6cd5<\/h4>\n<\/p>\n<p><p>\u9664\u4e86\u57fa\u672c\u7684<code>set_xlim<\/code>\u548c<code>set_ylim<\/code>\u65b9\u6cd5\uff0cMatplotlib\u8fd8\u63d0\u4f9b\u4e86\u4e00\u4e9b\u9ad8\u7ea7\u7528\u6cd5\u3002\u4f8b\u5982\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e<code>auto<\/code>\u53c2\u6570\u81ea\u52a8\u8c03\u6574\u5750\u6807\u8f74\u8303\u56f4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.plot(x, y)<\/p>\n<p>plt.xlim(auto=True)  # \u81ea\u52a8\u8c03\u6574X\u8f74\u8303\u56f4<\/p>\n<p>plt.ylim(auto=True)  # \u81ea\u52a8\u8c03\u6574Y\u8f74\u8303\u56f4<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u6570\u636e\u8303\u56f4\u672a\u77e5\u7684\u60c5\u51b5\uff0c\u80fd\u591f\u81ea\u52a8\u6839\u636e\u6570\u636e\u8c03\u6574\u5750\u6807\u8f74\u7684\u663e\u793a\u8303\u56f4\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u8bbe\u7f6e\u523b\u5ea6\u8303\u56f4<\/h3>\n<\/p>\n<p><h4>1. \u4f7f\u7528<code>set_xticks<\/code>\u548c<code>set_yticks<\/code><\/h4>\n<\/p>\n<p><p>\u9664\u4e86\u4f7f\u7528<code>set_xlim<\/code>\u548c<code>set_ylim<\/code>\u65b9\u6cd5\uff0c\u4f60\u8fd8\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u523b\u5ea6\u8303\u56f4\u6765\u5b9e\u73b0\u90e8\u5206\u663e\u793a\u5750\u6807\u8f74\u3002\u4f8b\u5982\uff0c\u4f7f\u7528<code>set_xticks<\/code>\u548c<code>set_yticks<\/code>\u65b9\u6cd5\u53ef\u4ee5\u81ea\u5b9a\u4e49\u523b\u5ea6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.plot(x, y)<\/p>\n<p>plt.xticks(np.arange(0, 11, step=1))  # \u8bbe\u7f6eX\u8f74\u523b\u5ea6<\/p>\n<p>plt.yticks(np.arange(-1, 1.1, step=0.5))  # \u8bbe\u7f6eY\u8f74\u523b\u5ea6<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u901a\u8fc7<code>plt.xticks<\/code>\u65b9\u6cd5\u8bbe\u7f6e\u4e86X\u8f74\u7684\u523b\u5ea6\u8303\u56f4\u4e3a0\u523010\uff0c\u6b65\u957f\u4e3a1\uff1b\u901a\u8fc7<code>plt.yticks<\/code>\u65b9\u6cd5\u8bbe\u7f6e\u4e86Y\u8f74\u7684\u523b\u5ea6\u8303\u56f4\u4e3a-1\u52301\uff0c\u6b65\u957f\u4e3a0.5\u3002<\/p>\n<\/p>\n<p><h4>2. \u9690\u85cf\u4e0d\u9700\u8981\u7684\u523b\u5ea6\u6807\u7b7e<\/h4>\n<\/p>\n<p><p>\u6709\u65f6\u5019\uff0c\u4f60\u53ef\u80fd\u53ea\u60f3\u663e\u793a\u90e8\u5206\u523b\u5ea6\u6807\u7b7e\uff0c\u53ef\u4ee5\u901a\u8fc7\u9690\u85cf\u4e0d\u9700\u8981\u7684\u523b\u5ea6\u6807\u7b7e\u6765\u5b9e\u73b0\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.plot(x, y)<\/p>\n<p>plt.xticks([0, 5, 10])  # \u53ea\u663e\u793a0, 5, 10\u4e09\u4e2a\u523b\u5ea6<\/p>\n<p>plt.yticks([-1, 0, 1])  # \u53ea\u663e\u793a-1, 0, 1\u4e09\u4e2a\u523b\u5ea6<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u80fd\u591f\u66f4\u52a0\u7cbe\u7ec6\u5730\u63a7\u5236\u5750\u6807\u8f74\u7684\u663e\u793a\u6548\u679c\uff0c\u9002\u7528\u4e8e\u9700\u8981\u7a81\u51fa\u663e\u793a\u7279\u5b9a\u523b\u5ea6\u7684\u60c5\u51b5\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u9690\u85cf\u4e0d\u9700\u8981\u7684\u523b\u5ea6\u6807\u7b7e<\/h3>\n<\/p>\n<p><p>\u6709\u65f6\u5019\uff0c\u663e\u793a\u6240\u6709\u7684\u523b\u5ea6\u6807\u7b7e\u53ef\u80fd\u4f1a\u4f7f\u56fe\u5f62\u663e\u5f97\u6742\u4e71\u65e0\u7ae0\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u4f60\u53ef\u4ee5\u9009\u62e9\u9690\u85cf\u4e0d\u9700\u8981\u7684\u523b\u5ea6\u6807\u7b7e\u6765\u4f18\u5316\u56fe\u5f62\u7684\u663e\u793a\u6548\u679c\u3002<\/p>\n<\/p>\n<p><h4>1. \u4f7f\u7528<code>tick_params<\/code>\u65b9\u6cd5<\/h4>\n<\/p>\n<p><p>\u4f60\u53ef\u4ee5\u901a\u8fc7<code>tick_params<\/code>\u65b9\u6cd5\u6765\u9690\u85cf\u4e0d\u9700\u8981\u7684\u523b\u5ea6\u6807\u7b7e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.plot(x, y)<\/p>\n<p>plt.tick_params(axis=&#39;x&#39;, which=&#39;both&#39;, bottom=False, top=False, labelbottom=False)  # \u9690\u85cfX\u8f74\u523b\u5ea6<\/p>\n<p>plt.tick_params(axis=&#39;y&#39;, which=&#39;both&#39;, left=False, right=False, labelleft=False)  # \u9690\u85cfY\u8f74\u523b\u5ea6<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u901a\u8fc7<code>plt.tick_params<\/code>\u65b9\u6cd5\u9690\u85cf\u4e86X\u8f74\u548cY\u8f74\u7684\u6240\u6709\u523b\u5ea6\u3002<\/p>\n<\/p>\n<p><h4>2. \u4f7f\u7528<code>set_visible<\/code>\u65b9\u6cd5<\/h4>\n<\/p>\n<p><p>\u4f60\u8fd8\u53ef\u4ee5\u901a\u8fc7<code>set_visible<\/code>\u65b9\u6cd5\u6765\u9690\u85cf\u7279\u5b9a\u7684\u523b\u5ea6\u6807\u7b7e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.plot(x, y)<\/p>\n<p>ax = plt.gca()<\/p>\n<p>ax.xaxis.set_visible(False)  # \u9690\u85cfX\u8f74\u523b\u5ea6<\/p>\n<p>ax.yaxis.set_visible(False)  # \u9690\u85cfY\u8f74\u523b\u5ea6<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u80fd\u591f\u66f4\u52a0\u7075\u6d3b\u5730\u63a7\u5236\u5750\u6807\u8f74\u7684\u663e\u793a\u6548\u679c\uff0c\u9002\u7528\u4e8e\u9700\u8981\u90e8\u5206\u9690\u85cf\u523b\u5ea6\u7684\u60c5\u51b5\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u5b9e\u9645\u6848\u4f8b\u5206\u6790<\/h3>\n<\/p>\n<p><h4>1. \u6570\u636e\u53ef\u89c6\u5316\u4e2d\u7684\u5e94\u7528<\/h4>\n<\/p>\n<p><p>\u5728\u6570\u636e\u53ef\u89c6\u5316\u4e2d\uff0c\u6307\u5b9a\u5750\u6807\u8f74\u53ea\u663e\u793a\u90e8\u5206\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u9700\u6c42\u3002\u4f8b\u5982\uff0c\u5728\u80a1\u7968\u4ef7\u683c\u8d70\u52bf\u56fe\u4e2d\uff0c\u6211\u4eec\u53ef\u80fd\u53ea\u5173\u5fc3\u6700\u8fd1\u4e00\u6bb5\u65f6\u95f4\u7684\u4ef7\u683c\u53d8\u5316\uff0c\u8fd9\u65f6\u5019\u5c31\u9700\u8981\u901a\u8fc7\u8bbe\u5b9a\u5750\u6807\u8f74\u8303\u56f4\u6765\u5b9e\u73b0\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u751f\u6210\u793a\u4f8b\u6570\u636e<\/strong><\/h2>\n<p>dates = pd.date_range(&#39;20230101&#39;, periods=100)<\/p>\n<p>prices = np.random.rand(100) * 100<\/p>\n<p>plt.plot(dates, prices)<\/p>\n<p>plt.xlim(dates[50], dates[99])  # \u53ea\u663e\u793a\u6700\u8fd150\u5929\u7684\u6570\u636e<\/p>\n<p>plt.ylim(0, 100)  # \u8bbe\u7f6eY\u8f74\u8303\u56f4<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u901a\u8fc7<code>plt.xlim<\/code>\u65b9\u6cd5\u53ea\u663e\u793a\u4e86\u6700\u8fd150\u5929\u7684\u80a1\u7968\u4ef7\u683c\u53d8\u5316\u3002<\/p>\n<\/p>\n<p><h4>2. \u79d1\u5b66\u7814\u7a76\u4e2d\u7684\u5e94\u7528<\/h4>\n<\/p>\n<p><p>\u5728\u79d1\u5b66\u7814\u7a76\u4e2d\uff0c\u6307\u5b9a\u5750\u6807\u8f74\u53ea\u663e\u793a\u90e8\u5206\u4e5f\u6709\u5e7f\u6cdb\u7684\u5e94\u7528\u3002\u4f8b\u5982\uff0c\u5728\u751f\u7269\u5b9e\u9a8c\u4e2d\uff0c\u6211\u4eec\u53ef\u80fd\u53ea\u5173\u5fc3\u67d0\u4e2a\u7279\u5b9a\u65f6\u95f4\u6bb5\u5185\u7684\u6570\u636e\u53d8\u5316\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u751f\u6210\u793a\u4f8b\u6570\u636e<\/p>\n<p>time = np.linspace(0, 100, 500)<\/p>\n<p>response = np.exp(-time \/ 20) * np.sin(time)<\/p>\n<p>plt.plot(time, response)<\/p>\n<p>plt.xlim(20, 80)  # \u53ea\u663e\u793a20\u523080\u65f6\u95f4\u6bb5\u7684\u6570\u636e<\/p>\n<p>plt.ylim(-1, 1)  # \u8bbe\u7f6eY\u8f74\u8303\u56f4<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u901a\u8fc7<code>plt.xlim<\/code>\u65b9\u6cd5\u53ea\u663e\u793a\u4e8620\u523080\u65f6\u95f4\u6bb5\u5185\u7684\u5b9e\u9a8c\u6570\u636e\u53d8\u5316\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u672c\u6587\u7684\u4ecb\u7ecd\uff0c\u6211\u4eec\u8be6\u7ec6\u8ba8\u8bba\u4e86\u5728Python\u4e2d\u5982\u4f55\u6307\u5b9a\u5750\u6807\u8f74\u53ea\u663e\u793a\u90e8\u5206\u7684\u65b9\u6cd5\u3002\u4e3b\u8981\u5305\u62ec\u4f7f\u7528Matplotlib\u7684<code>set_xlim<\/code>\u548c<code>set_ylim<\/code>\u65b9\u6cd5\u3001\u8bbe\u7f6e\u523b\u5ea6\u8303\u56f4\u3001\u9690\u85cf\u4e0d\u9700\u8981\u7684\u523b\u5ea6\u6807\u7b7e\u7b49\u3002\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u7279\u5b9a\u7684\u5e94\u7528\u573a\u666f\uff0c\u80fd\u591f\u6ee1\u8db3\u4e0d\u540c\u7684\u9700\u6c42\u3002<\/p>\n<\/p>\n<p><p><strong>\u4f7f\u7528Matplotlib\u7684<code>set_xlim<\/code>\u548c<code>set_ylim<\/code>\u65b9\u6cd5<\/strong>\u662f\u6700\u5e38\u89c1\u4e14\u6613\u4e8e\u5b9e\u73b0\u7684\u65b9\u5f0f\uff0c\u9002\u7528\u4e8e\u7edd\u5927\u591a\u6570\u60c5\u51b5\u3002<strong>\u8bbe\u7f6e\u523b\u5ea6\u8303\u56f4\u548c\u9690\u85cf\u4e0d\u9700\u8981\u7684\u523b\u5ea6\u6807\u7b7e<\/strong>\u80fd\u591f\u8fdb\u4e00\u6b65\u4f18\u5316\u56fe\u5f62\u7684\u663e\u793a\u6548\u679c\uff0c\u9002\u7528\u4e8e\u9700\u8981\u7cbe\u7ec6\u63a7\u5236\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><p>\u5e0c\u671b\u901a\u8fc7\u672c\u6587\u7684\u4ecb\u7ecd\uff0c\u80fd\u591f\u5e2e\u52a9\u4f60\u66f4\u597d\u5730\u7406\u89e3\u548c\u638c\u63e1\u5728Python\u4e2d\u6307\u5b9a\u5750\u6807\u8f74\u53ea\u663e\u793a\u90e8\u5206\u7684\u65b9\u6cd5\uff0c\u4ece\u800c\u63d0\u9ad8\u6570\u636e\u53ef\u89c6\u5316\u7684\u8d28\u91cf\u548c\u6548\u679c\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u8bbe\u7f6e\u5750\u6807\u8f74\u7684\u663e\u793a\u8303\u56f4\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528Matplotlib\u5e93\u6765\u8bbe\u7f6e\u5750\u6807\u8f74\u7684\u663e\u793a\u8303\u56f4\u3002\u53ef\u4ee5\u901a\u8fc7<code>plt.xlim()<\/code>\u548c<code>plt.ylim()<\/code>\u51fd\u6570\u6765\u6307\u5b9ax\u8f74\u548cy\u8f74\u7684\u8303\u56f4\u3002\u4f8b\u5982\uff0c<code>plt.xlim(0, 10)<\/code>\u5c06x\u8f74\u8303\u56f4\u8bbe\u7f6e\u4e3a0\u523010\uff0c<code>plt.ylim(-5, 5)<\/code>\u5c06y\u8f74\u8303\u56f4\u8bbe\u7f6e\u4e3a-5\u52305\u3002\u8fd9\u79cd\u65b9\u6cd5\u53ef\u4ee5\u5e2e\u52a9\u7528\u6237\u66f4\u597d\u5730\u805a\u7126\u4e8e\u611f\u5174\u8da3\u7684\u6570\u636e\u533a\u57df\u3002<\/p>\n<p><strong>\u662f\u5426\u53ef\u4ee5\u53ea\u663e\u793a\u7279\u5b9a\u5750\u6807\u8f74\u7684\u523b\u5ea6\uff1f<\/strong><br \/>\u5f53\u7136\u53ef\u4ee5\u3002\u5728\u4f7f\u7528Matplotlib\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7<code>plt.xticks()<\/code>\u548c<code>plt.yticks()<\/code>\u6765\u8bbe\u7f6e\u7279\u5b9a\u523b\u5ea6\u3002\u4f8b\u5982\uff0c<code>plt.xticks([0, 2, 4, 6, 8, 10])<\/code>\u5c06x\u8f74\u523b\u5ea6\u9650\u5236\u4e3a\u6307\u5b9a\u7684\u503c\u3002\u8fd9\u79cd\u65b9\u6cd5\u6709\u52a9\u4e8e\u4f18\u5316\u56fe\u8868\u7684\u53ef\u8bfb\u6027\uff0c\u786e\u4fdd\u53ea\u663e\u793a\u6700\u76f8\u5173\u7684\u4fe1\u606f\u3002<\/p>\n<p><strong>\u5982\u4f55\u9690\u85cf\u4e0d\u9700\u8981\u7684\u5750\u6807\u8f74\u6216\u523b\u5ea6\uff1f<\/strong><br \/>\u5982\u679c\u5e0c\u671b\u5728\u56fe\u8868\u4e2d\u9690\u85cf\u67d0\u4e9b\u5750\u6807\u8f74\u6216\u523b\u5ea6\uff0cMatplotlib\u63d0\u4f9b\u4e86\u7b80\u5355\u7684\u89e3\u51b3\u65b9\u6848\u3002\u53ef\u4ee5\u4f7f\u7528<code>plt.gca().axes.get_xaxis().set_visible(False)<\/code>\u6765\u9690\u85cfx\u8f74\uff0c\u7c7b\u4f3c\u5730\uff0c\u4f7f\u7528<code>plt.gca().axes.get_yaxis().set_visible(False)<\/code>\u6765\u9690\u85cfy\u8f74\u3002\u8fd9\u6837\u53ef\u4ee5\u4f7f\u56fe\u8868\u66f4\u52a0\u7b80\u6d01\uff0c\u7a81\u51fa\u4e3b\u8981\u6570\u636e\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u5982\u4f55\u6307\u5b9a\u5750\u6807\u8f74\u53ea\u663e\u793a\u90e8\u5206\uff1a\u4f7f\u7528Matplotlib\u7684set_xlim\u548cset_ylim\u65b9\u6cd5\u3001\u8bbe\u7f6e\u523b [&hellip;]","protected":false},"author":3,"featured_media":1122448,"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\/1122437"}],"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=1122437"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1122437\/revisions"}],"predecessor-version":[{"id":1122450,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1122437\/revisions\/1122450"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1122448"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1122437"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1122437"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1122437"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}