{"id":968758,"date":"2024-12-27T05:09:54","date_gmt":"2024-12-26T21:09:54","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/968758.html"},"modified":"2024-12-27T05:09:57","modified_gmt":"2024-12-26T21:09:57","slug":"python%e5%a6%82%e4%bd%95%e8%b0%83%e6%95%b4%e6%a8%aa%e5%9d%90%e6%a0%87","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/968758.html","title":{"rendered":"python\u5982\u4f55\u8c03\u6574\u6a2a\u5750\u6807"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24183356\/43d9d923-1c2a-41a7-bbf5-2d62b831bb74.webp\" alt=\"python\u5982\u4f55\u8c03\u6574\u6a2a\u5750\u6807\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\uff0c\u8c03\u6574\u6a2a\u5750\u6807\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528Matplotlib\u5e93\u3001\u8bbe\u7f6e\u523b\u5ea6\u6807\u7b7e\u3001\u65cb\u8f6c\u6807\u7b7e\u3001\u8c03\u6574\u5750\u6807\u8303\u56f4\u3002<\/strong> \u8fd9\u4e9b\u65b9\u6cd5\u901a\u8fc7\u4e0d\u540c\u7684\u65b9\u5f0f\u6765\u5b9a\u5236\u56fe\u8868\u7684\u663e\u793a\u6548\u679c\uff0c\u4f7f\u5f97\u6570\u636e\u7684\u53ef\u89c6\u5316\u66f4\u52a0\u6e05\u6670\u548c\u7f8e\u89c2\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u4f7f\u7528Matplotlib\u5e93\u8fdb\u884c\u6a2a\u5750\u6807\u8c03\u6574\u7684\u5177\u4f53\u6b65\u9aa4\u53ca\u6ce8\u610f\u4e8b\u9879\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4f7f\u7528MATPLOTLIB\u5e93<\/p>\n<\/p>\n<p><p>Matplotlib\u662fPython\u4e2d\u975e\u5e38\u6d41\u884c\u7684\u7ed8\u56fe\u5e93\uff0c\u4e3b\u8981\u7528\u4e8e\u751f\u6210\u9759\u6001\u3001\u4ea4\u4e92\u5f0f\u548c\u52a8\u6001\u7684\u4e8c\u7ef4\u56fe\u5f62\u3002\u901a\u8fc7Matplotlib\uff0c\u60a8\u53ef\u4ee5\u8f7b\u677e\u5730\u8c03\u6574\u56fe\u8868\u7684\u6a2a\u5750\u6807\u3002\u8981\u8c03\u6574\u6a2a\u5750\u6807\uff0c\u9996\u5148\u9700\u8981\u5b89\u88c5\u5e76\u5bfc\u5165Matplotlib\u5e93\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\uff0c\u4f7f\u7528<code>plt.plot()<\/code>\u6216\u5176\u4ed6\u7ed8\u56fe\u51fd\u6570\u6765\u521b\u5efa\u57fa\u672c\u7684\u56fe\u5f62\u3002\u60a8\u53ef\u4ee5\u901a\u8fc7<code>plt.xticks()<\/code>\u51fd\u6570\u6765\u8bbe\u7f6e\u6a2a\u5750\u6807\u7684\u523b\u5ea6\u548c\u6807\u7b7e\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u4f20\u9012\u4e00\u4e2a\u5217\u8868\u6765\u8bbe\u7f6e\u523b\u5ea6\u4f4d\u7f6e\uff0c\u5e76\u901a\u8fc7\u53e6\u4e00\u4e2a\u5217\u8868\u6765\u8bbe\u7f6e\u76f8\u5e94\u7684\u523b\u5ea6\u6807\u7b7e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.plot(x, y)<\/p>\n<p>plt.xticks([0, 1, 2, 3], [&#39;A&#39;, &#39;B&#39;, &#39;C&#39;, &#39;D&#39;])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u53ef\u4ee5\u5e2e\u52a9\u60a8\u6839\u636e\u9700\u8981\u81ea\u5b9a\u4e49\u6a2a\u5750\u6807\u7684\u663e\u793a\u65b9\u5f0f\uff0c\u4f7f\u5f97\u56fe\u5f62\u66f4\u52a0\u76f4\u89c2\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u8bbe\u7f6e\u523b\u5ea6\u6807\u7b7e<\/p>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u60a8\u53ef\u80fd\u5e0c\u671b\u81ea\u5b9a\u4e49\u6a2a\u5750\u6807\u7684\u523b\u5ea6\u6807\u7b7e\uff0c\u4ee5\u4fbf\u66f4\u597d\u5730\u53cd\u6620\u6570\u636e\u7684\u542b\u4e49\u3002\u60a8\u53ef\u4ee5\u901a\u8fc7<code>plt.xticks()<\/code>\u51fd\u6570\u6765\u5b9e\u73b0\u8fd9\u4e00\u70b9\u3002\u9664\u4e86\u8bbe\u7f6e\u523b\u5ea6\u4f4d\u7f6e\u5916\uff0c\u60a8\u8fd8\u53ef\u4ee5\u901a\u8fc7\u4f20\u9012\u4e00\u4e2a\u5b57\u7b26\u4e32\u5217\u8868\u6765\u6307\u5b9a\u523b\u5ea6\u6807\u7b7e\u3002<\/p>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c\u5047\u8bbe\u60a8\u6709\u4e00\u7ec4\u6570\u636e\u9700\u8981\u6309\u7167\u6708\u4efd\u663e\u793a\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">months = [&#39;Jan&#39;, &#39;Feb&#39;, &#39;Mar&#39;, &#39;Apr&#39;, &#39;May&#39;, &#39;Jun&#39;, &#39;Jul&#39;, &#39;Aug&#39;, &#39;Sep&#39;, &#39;Oct&#39;, &#39;Nov&#39;, &#39;Dec&#39;]<\/p>\n<p>plt.plot(x, y)<\/p>\n<p>plt.xticks(range(12), months)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u53ef\u4ee5\u63d0\u9ad8\u56fe\u8868\u7684\u53ef\u8bfb\u6027\uff0c\u4f7f\u5f97\u89c2\u4f17\u66f4\u5bb9\u6613\u7406\u89e3\u6570\u636e\u7684\u65f6\u95f4\u7ef4\u5ea6\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u65cb\u8f6c\u6807\u7b7e<\/p>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u6a2a\u5750\u6807\u6807\u7b7e\u53ef\u80fd\u4f1a\u91cd\u53e0\u6216\u8fc7\u4e8e\u5bc6\u96c6\uff0c\u5bfc\u81f4\u96be\u4ee5\u9605\u8bfb\u3002\u4e3a\u4e86\u907f\u514d\u8fd9\u79cd\u60c5\u51b5\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7<code>plt.xticks(rotation=angle)<\/code>\u51fd\u6570\u6765\u65cb\u8f6c\u6807\u7b7e\uff0c\u4ece\u800c\u63d0\u9ad8\u56fe\u8868\u7684\u6e05\u6670\u5ea6\u3002<\/p>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u5c06\u6807\u7b7e\u65cb\u8f6c45\u5ea6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.plot(x, y)<\/p>\n<p>plt.xticks(rotation=45)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u7279\u522b\u9002\u7528\u4e8e\u6807\u7b7e\u8f83\u957f\u6216\u5bc6\u96c6\u7684\u573a\u666f\uff0c\u53ef\u4ee5\u663e\u8457\u6539\u5584\u56fe\u8868\u7684\u53ef\u89c6\u5316\u6548\u679c\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u8c03\u6574\u5750\u6807\u8303\u56f4<\/p>\n<\/p>\n<p><p>\u6709\u65f6\uff0c\u60a8\u53ef\u80fd\u9700\u8981\u9650\u5236\u6a2a\u5750\u6807\u7684\u663e\u793a\u8303\u56f4\uff0c\u4ee5\u4fbf\u66f4\u597d\u5730\u805a\u7126\u4e8e\u7279\u5b9a\u7684\u6570\u636e\u533a\u57df\u3002\u60a8\u53ef\u4ee5\u901a\u8fc7<code>plt.xlim()<\/code>\u51fd\u6570\u6765\u8bbe\u7f6e\u6a2a\u5750\u6807\u7684\u663e\u793a\u8303\u56f4\u3002<\/p>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u5c06\u6a2a\u5750\u6807\u9650\u5236\u57280\u523010\u4e4b\u95f4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.plot(x, y)<\/p>\n<p>plt.xlim(0, 10)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u53ef\u4ee5\u5e2e\u52a9\u60a8\u6392\u9664\u4e0d\u5fc5\u8981\u7684\u6570\u636e\u5e72\u6270\uff0c\u4f7f\u5f97\u56fe\u8868\u66f4\u5177\u9488\u5bf9\u6027\u548c\u5b9e\u7528\u6027\u3002<\/p>\n<\/p>\n<p><p>\u4e94\u3001\u4f7f\u7528\u65e5\u671f\u683c\u5f0f\u5316<\/p>\n<\/p>\n<p><p>\u5982\u679c\u60a8\u7684\u6570\u636e\u6d89\u53ca\u65f6\u95f4\u5e8f\u5217\uff0c\u60a8\u53ef\u80fd\u9700\u8981\u5c06\u6a2a\u5750\u6807\u8bbe\u7f6e\u4e3a\u65e5\u671f\u683c\u5f0f\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u53ef\u4ee5\u4f7f\u7528<code>matplotlib.dates<\/code>\u6a21\u5757\u63d0\u4f9b\u7684\u529f\u80fd\u6765\u5b9e\u73b0\u3002<\/p>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u5bfc\u5165<code>matplotlib.dates<\/code>\u6a21\u5757\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.dates as mdates<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528<code>mdates.DateFormatter<\/code>\u6765\u8bbe\u7f6e\u65e5\u671f\u683c\u5f0f\u3002\u4f8b\u5982\uff0c\u8bbe\u7f6e\u4e3a<code>YYYY-MM-DD<\/code>\u683c\u5f0f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.plot(dates, values)<\/p>\n<p>plt.gca().xaxis.set_major_formatter(mdates.DateFormatter(&#39;%Y-%m-%d&#39;))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u53ef\u4ee5\u4f7f\u5f97\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u7684\u53ef\u89c6\u5316\u66f4\u52a0\u4e13\u4e1a\u548c\u6e05\u6670\u3002<\/p>\n<\/p>\n<p><p>\u516d\u3001\u4f7f\u7528PANDAS\u8fdb\u884c\u65f6\u95f4\u5e8f\u5217\u7ed8\u56fe<\/p>\n<\/p>\n<p><p>Pandas\u5e93\u662fPython\u4e2d\u5f3a\u5927\u7684\u6570\u636e\u5206\u6790\u5de5\u5177\uff0c\u7ed3\u5408Matplotlib\u53ef\u4ee5\u65b9\u4fbf\u5730\u8fdb\u884c\u65f6\u95f4\u5e8f\u5217\u7684\u7ed8\u56fe\u548c\u6a2a\u5750\u6807\u8c03\u6574\u3002<\/p>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u9700\u8981\u786e\u4fddPandas\u5e93\u5df2\u5b89\u88c5\u5e76\u5bfc\u5165\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5047\u8bbe\u60a8\u6709\u4e00\u4e2aDataFrame\uff0c\u5176\u4e2d\u5305\u542b\u65e5\u671f\u548c\u76f8\u5e94\u7684\u6570\u636e\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528<code>plot()<\/code>\u51fd\u6570\u76f4\u63a5\u7ed8\u5236\u56fe\u5f62\uff0c\u5e76\u6307\u5b9a<code>x<\/code>\u8f74\u4e3a\u65e5\u671f\u5217\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">df = pd.DataFrame({&#39;Date&#39;: pd.date_range(start=&#39;1\/1\/2023&#39;, periods=10),<\/p>\n<p>                   &#39;Value&#39;: np.random.rand(10)})<\/p>\n<p>df.plot(x=&#39;Date&#39;, y=&#39;Value&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>Pandas\u4f1a\u81ea\u52a8\u5904\u7406\u65e5\u671f\u683c\u5f0f\u5e76\u8fdb\u884c\u5408\u7406\u7684\u6a2a\u5750\u6807\u663e\u793a\u3002<\/p>\n<\/p>\n<p><p>\u4e03\u3001\u4f7f\u7528SEABORN\u5e93<\/p>\n<\/p>\n<p><p>Seaborn\u662f\u57fa\u4e8eMatplotlib\u7684\u9ad8\u7ea7\u7ed8\u56fe\u5e93\uff0c\u63d0\u4f9b\u4e86\u66f4\u4e3a\u7f8e\u89c2\u548c\u590d\u6742\u7684\u56fe\u5f62\u3002\u901a\u8fc7Seaborn\uff0c\u60a8\u53ef\u4ee5\u66f4\u8f7b\u677e\u5730\u8c03\u6574\u6a2a\u5750\u6807\u3002<\/p>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u786e\u4fddSeaborn\u5df2\u5b89\u88c5\u5e76\u5bfc\u5165\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import seaborn as sns<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>Seaborn\u63d0\u4f9b\u4e86\u591a\u4e2a\u7ed8\u56fe\u51fd\u6570\uff0c\u5982<code>sns.lineplot()<\/code>\uff0c\u53ef\u4ee5\u76f4\u63a5\u7528\u4e8e\u7ed8\u5236\u56fe\u5f62\uff0c\u5e76\u81ea\u52a8\u5904\u7406\u6a2a\u5750\u6807\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">sns.lineplot(x=&#39;Date&#39;, y=&#39;Value&#39;, data=df)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u53ef\u4ee5\u751f\u6210\u66f4\u52a0\u7f8e\u89c2\u548c\u4e13\u4e1a\u7684\u56fe\u5f62\uff0c\u4f7f\u5f97\u6570\u636e\u7684\u5c55\u793a\u6548\u679c\u66f4\u4f73\u3002<\/p>\n<\/p>\n<p><p>\u516b\u3001\u7efc\u5408\u5e94\u7528\u5b9e\u4f8b<\/p>\n<\/p>\n<p><p>\u4e3a\u4e86\u66f4\u597d\u5730\u7406\u89e3\u4e0a\u8ff0\u65b9\u6cd5\u7684\u5e94\u7528\uff0c\u4e0b\u9762\u63d0\u4f9b\u4e00\u4e2a\u7efc\u5408\u5b9e\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u8c03\u6574\u6a2a\u5750\u6807\u4ee5\u5b9e\u73b0\u6700\u4f73\u7684\u56fe\u5f62\u53ef\u89c6\u5316\u6548\u679c\u3002<\/p>\n<\/p>\n<p><p>\u5047\u8bbe\u60a8\u6709\u4e00\u7ec4\u65f6\u95f4\u5e8f\u5217\u6570\u636e\uff0c\u9700\u8981\u7ed8\u5236\u5e76\u8c03\u6574\u6a2a\u5750\u6807\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>import matplotlib.dates as mdates<\/p>\n<p>import pandas as pd<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u751f\u6210\u793a\u4f8b\u6570\u636e<\/strong><\/h2>\n<p>dates = pd.date_range(start=&#39;2023-01-01&#39;, periods=100)<\/p>\n<p>values = np.random.rand(100)<\/p>\n<h2><strong>\u521b\u5efaDataFrame<\/strong><\/h2>\n<p>df = pd.DataFrame({&#39;Date&#39;: dates, &#39;Value&#39;: values})<\/p>\n<h2><strong>\u7ed8\u5236\u56fe\u5f62<\/strong><\/h2>\n<p>plt.figure(figsize=(10, 6))<\/p>\n<p>plt.plot(df[&#39;Date&#39;], df[&#39;Value&#39;])<\/p>\n<h2><strong>\u8bbe\u7f6e\u65e5\u671f\u683c\u5f0f<\/strong><\/h2>\n<p>plt.gca().xaxis.set_major_formatter(mdates.DateFormatter(&#39;%Y-%m-%d&#39;))<\/p>\n<h2><strong>\u65cb\u8f6c\u6807\u7b7e<\/strong><\/h2>\n<p>plt.xticks(rotation=45)<\/p>\n<h2><strong>\u8bbe\u7f6e\u5750\u6807\u8303\u56f4<\/strong><\/h2>\n<p>plt.xlim(df[&#39;Date&#39;].min(), df[&#39;Date&#39;].max())<\/p>\n<h2><strong>\u663e\u793a\u56fe\u5f62<\/strong><\/h2>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u60a8\u53ef\u4ee5\u5145\u5206\u5229\u7528Python\u7684\u5404\u79cd\u7ed8\u56fe\u5de5\u5177\u548c\u6280\u5de7\uff0c\u8fdb\u884c\u6a2a\u5750\u6807\u7684\u8c03\u6574\uff0c\u4ece\u800c\u5b9e\u73b0\u9ad8\u8d28\u91cf\u7684\u6570\u636e\u53ef\u89c6\u5316\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u81ea\u5b9a\u4e49\u6a2a\u5750\u6807\u7684\u6807\u7b7e\uff1f<\/strong><br \/>\u5728Python\u7684\u7ed8\u56fe\u5e93\u4e2d\uff0c\u4f8b\u5982Matplotlib\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7<code>plt.xticks()<\/code>\u51fd\u6570\u81ea\u5b9a\u4e49\u6a2a\u5750\u6807\u7684\u6807\u7b7e\u3002\u60a8\u53ef\u4ee5\u6307\u5b9a\u6807\u7b7e\u7684\u6587\u5b57\u3001\u4f4d\u7f6e\u4ee5\u53ca\u65cb\u8f6c\u89d2\u5ea6\uff0c\u8fd9\u6837\u53ef\u4ee5\u4f7f\u56fe\u8868\u66f4\u6613\u4e8e\u9605\u8bfb\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528<code>plt.xticks(ticks=[0, 1, 2], labels=[&#39;A&#39;, &#39;B&#39;, &#39;C&#39;], rotation=45)<\/code>\u6765\u8bbe\u7f6e\u6a2a\u5750\u6807\u7684\u523b\u5ea6\u548c\u5bf9\u5e94\u7684\u6807\u7b7e\u3002<\/p>\n<p><strong>\u5982\u4f55\u6539\u53d8\u6a2a\u5750\u6807\u7684\u8303\u56f4\u6216\u523b\u5ea6\uff1f<\/strong><br \/>\u53ef\u4ee5\u4f7f\u7528<code>plt.xlim()<\/code>\u51fd\u6570\u6765\u8bbe\u7f6e\u6a2a\u5750\u6807\u7684\u8303\u56f4\uff0c\u4f8b\u5982<code>plt.xlim(0, 10)<\/code>\u5c06\u6a2a\u5750\u6807\u7684\u8303\u56f4\u8bbe\u7f6e\u4e3a0\u523010\u3002\u540c\u65f6\uff0c\u60a8\u8fd8\u53ef\u4ee5\u901a\u8fc7<code>plt.xticks()<\/code>\u6765\u8bbe\u7f6e\u523b\u5ea6\u7684\u95f4\u9694\uff0c\u4f7f\u5f97\u6570\u636e\u5c55\u793a\u66f4\u52a0\u6e05\u6670\u3002\u901a\u8fc7\u5408\u7406\u8c03\u6574\u6a2a\u5750\u6807\u7684\u8303\u56f4\u548c\u523b\u5ea6\uff0c\u53ef\u4ee5\u63d0\u5347\u56fe\u8868\u7684\u53ef\u8bfb\u6027\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5982\u4f55\u5b9e\u73b0\u6a2a\u5750\u6807\u7684\u65e5\u671f\u683c\u5f0f\u663e\u793a\uff1f<\/strong><br \/>\u5904\u7406\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528Matplotlib\u7684\u65e5\u671f\u683c\u5f0f\u5316\u529f\u80fd\u3002\u901a\u8fc7<code>mdates<\/code>\u6a21\u5757\uff0c\u60a8\u53ef\u4ee5\u5c06\u6a2a\u5750\u6807\u8bbe\u7f6e\u4e3a\u65e5\u671f\u683c\u5f0f\u3002\u4f8b\u5982\uff0c\u4f7f\u7528<code>mdates.DateFormatter(&#39;%Y-%m-%d&#39;)<\/code>\u6765\u683c\u5f0f\u5316\u65e5\u671f\uff0c\u5e76\u7ed3\u5408<code>plt.gca().xaxis.set_major_formatter()<\/code>\u6765\u5e94\u7528\u8fd9\u4e2a\u683c\u5f0f\u5316\u89c4\u5219\u3002\u8fd9\u6837\u80fd\u4f7f\u65e5\u671f\u5728\u56fe\u8868\u4e0a\u4ee5\u6e05\u6670\u3001\u6613\u8bfb\u7684\u65b9\u5f0f\u663e\u793a\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\uff0c\u8c03\u6574\u6a2a\u5750\u6807\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528Matplotlib\u5e93\u3001\u8bbe\u7f6e\u523b\u5ea6\u6807\u7b7e\u3001\u65cb\u8f6c\u6807\u7b7e\u3001\u8c03\u6574\u5750\u6807\u8303\u56f4\u3002 \u8fd9 [&hellip;]","protected":false},"author":3,"featured_media":968761,"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\/968758"}],"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=968758"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/968758\/revisions"}],"predecessor-version":[{"id":968762,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/968758\/revisions\/968762"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/968761"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=968758"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=968758"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=968758"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}