{"id":1075766,"date":"2025-01-08T11:47:12","date_gmt":"2025-01-08T03:47:12","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1075766.html"},"modified":"2025-01-08T11:47:15","modified_gmt":"2025-01-08T03:47:15","slug":"python%e5%a6%82%e4%bd%95%e5%81%9a%e6%97%b6%e9%97%b4%e4%b8%bax%e8%bd%b4-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1075766.html","title":{"rendered":"python\u5982\u4f55\u505a\u65f6\u95f4\u4e3ax\u8f74"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24180659\/5cae9bee-db34-401d-8bf7-7589c11a968c.webp\" alt=\"python\u5982\u4f55\u505a\u65f6\u95f4\u4e3ax\u8f74\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u4f7f\u7528\u65f6\u95f4\u4f5c\u4e3ax\u8f74\u7684\u65b9\u5f0f\u4e3b\u8981\u6709\uff1a\u4f7f\u7528pandas\u548cmatplotlib\u3001\u4f7f\u7528seaborn\u3001\u4f7f\u7528plotly\u7b49\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u8fd9\u4e9b\u5e93\u6765\u5b9e\u73b0\u65f6\u95f4\u4e3ax\u8f74\u7684\u6570\u636e\u53ef\u89c6\u5316\u3002\u63a8\u8350\u4f7f\u7528matplotlib\u548cpandas\uff0c\u56e0\u4e3a\u5b83\u4eec\u529f\u80fd\u5f3a\u5927\u4e14\u7075\u6d3b\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u4f7f\u7528Python\u8fdb\u884c\u6570\u636e\u53ef\u89c6\u5316\u65f6\uff0c\u6211\u4eec\u7ecf\u5e38\u9700\u8981\u5c06\u65f6\u95f4\u4f5c\u4e3ax\u8f74\u3002\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u662f\u4f7f\u7528matplotlib\u548cpandas\u5e93\u3002\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u786e\u4fdd\u65f6\u95f4\u6570\u636e\u88ab\u6b63\u786e\u89e3\u6790\u548c\u683c\u5f0f\u5316\uff0c\u7136\u540e\u5c06\u5176\u4f20\u9012\u7ed9\u7ed8\u56fe\u51fd\u6570\u3002\u63a5\u4e0b\u6765\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u8fd9\u4e9b\u5e93\u6765\u5904\u7406\u65f6\u95f4\u6570\u636e\u5e76\u751f\u6210\u56fe\u8868\u3002<\/p>\n<\/p>\n<p><h2>\u4e00\u3001\u4f7f\u7528pandas\u548cmatplotlib<\/h2>\n<\/p>\n<p><h3>1\u3001\u5bfc\u5165\u5fc5\u8981\u7684\u5e93<\/h3>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5bfc\u5165\u5fc5\u8981\u7684\u5e93\u3002pandas\u7528\u4e8e\u5904\u7406\u6570\u636e\uff0cmatplotlib\u7528\u4e8e\u7ed8\u56fe\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>import matplotlib.pyplot as plt<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u521b\u5efa\u6216\u52a0\u8f7d\u6570\u636e<\/h3>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u521b\u5efa\u4e00\u4e9b\u793a\u4f8b\u6570\u636e\u6216\u52a0\u8f7d\u73b0\u6709\u6570\u636e\u3002\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u5305\u542b\u65f6\u95f4\u548c\u6570\u503c\u7684\u6570\u636e\u96c6\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">data = {<\/p>\n<p>    &#39;date&#39;: [&#39;2023-01-01&#39;, &#39;2023-01-02&#39;, &#39;2023-01-03&#39;, &#39;2023-01-04&#39;, &#39;2023-01-05&#39;],<\/p>\n<p>    &#39;value&#39;: [10, 20, 15, 25, 30]<\/p>\n<p>}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<p>df[&#39;date&#39;] = pd.to_datetime(df[&#39;date&#39;])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>3\u3001\u7ed8\u5236\u56fe\u8868<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528matplotlib\u7ed8\u5236\u56fe\u8868\uff0c\u5e76\u5c06\u65f6\u95f4\u4f5c\u4e3ax\u8f74\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.figure(figsize=(10, 5))<\/p>\n<p>plt.plot(df[&#39;date&#39;], df[&#39;value&#39;], marker=&#39;o&#39;)<\/p>\n<p>plt.xlabel(&#39;Date&#39;)<\/p>\n<p>plt.ylabel(&#39;Value&#39;)<\/p>\n<p>plt.title(&#39;Time Series Data&#39;)<\/p>\n<p>plt.xticks(rotation=45)<\/p>\n<p>plt.grid(True)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u5c06\u65e5\u671f\u5217\u8f6c\u6362\u4e3adatetime\u683c\u5f0f\uff0c\u7136\u540e\u4f7f\u7528matplotlib\u7684plot\u51fd\u6570\u7ed8\u5236\u56fe\u8868\uff0c\u5e76\u5c06\u65e5\u671f\u5217\u4f5c\u4e3ax\u8f74\u3002<\/strong><\/p>\n<\/p>\n<p><h2>\u4e8c\u3001\u4f7f\u7528seaborn<\/h2>\n<\/p>\n<p><h3>1\u3001\u5bfc\u5165\u5fc5\u8981\u7684\u5e93<\/h3>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5bfc\u5165seaborn\u5e93\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import seaborn as sns<\/p>\n<p>import pandas as pd<\/p>\n<p>import matplotlib.pyplot as plt<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u521b\u5efa\u6216\u52a0\u8f7d\u6570\u636e<\/h3>\n<\/p>\n<p><p>\u548c\u4e4b\u524d\u4e00\u6837\uff0c\u6211\u4eec\u521b\u5efa\u4e00\u4e9b\u793a\u4f8b\u6570\u636e\u6216\u52a0\u8f7d\u73b0\u6709\u6570\u636e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">data = {<\/p>\n<p>    &#39;date&#39;: [&#39;2023-01-01&#39;, &#39;2023-01-02&#39;, &#39;2023-01-03&#39;, &#39;2023-01-04&#39;, &#39;2023-01-05&#39;],<\/p>\n<p>    &#39;value&#39;: [10, 20, 15, 25, 30]<\/p>\n<p>}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<p>df[&#39;date&#39;] = pd.to_datetime(df[&#39;date&#39;])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>3\u3001\u7ed8\u5236\u56fe\u8868<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528seaborn\u7ed8\u5236\u56fe\u8868\uff0c\u5e76\u5c06\u65f6\u95f4\u4f5c\u4e3ax\u8f74\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.figure(figsize=(10, 5))<\/p>\n<p>sns.lineplot(x=&#39;date&#39;, y=&#39;value&#39;, data=df, marker=&#39;o&#39;)<\/p>\n<p>plt.xlabel(&#39;Date&#39;)<\/p>\n<p>plt.ylabel(&#39;Value&#39;)<\/p>\n<p>plt.title(&#39;Time Series Data&#39;)<\/p>\n<p>plt.xticks(rotation=45)<\/p>\n<p>plt.grid(True)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>Seaborn\u662f\u4e00\u4e2a\u57fa\u4e8ematplotlib\u7684\u9ad8\u7ea7\u63a5\u53e3\uff0c\u63d0\u4f9b\u4e86\u66f4\u4e3a\u7b80\u6d01\u548c\u7f8e\u89c2\u7684\u7ed8\u56fe\u65b9\u5f0f\u3002<\/strong><\/p>\n<\/p>\n<p><h2>\u4e09\u3001\u4f7f\u7528plotly<\/h2>\n<\/p>\n<p><h3>1\u3001\u5bfc\u5165\u5fc5\u8981\u7684\u5e93<\/h3>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5bfc\u5165plotly\u5e93\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import plotly.express as px<\/p>\n<p>import pandas as pd<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u521b\u5efa\u6216\u52a0\u8f7d\u6570\u636e<\/h3>\n<\/p>\n<p><p>\u548c\u4e4b\u524d\u4e00\u6837\uff0c\u6211\u4eec\u521b\u5efa\u4e00\u4e9b\u793a\u4f8b\u6570\u636e\u6216\u52a0\u8f7d\u73b0\u6709\u6570\u636e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">data = {<\/p>\n<p>    &#39;date&#39;: [&#39;2023-01-01&#39;, &#39;2023-01-02&#39;, &#39;2023-01-03&#39;, &#39;2023-01-04&#39;, &#39;2023-01-05&#39;],<\/p>\n<p>    &#39;value&#39;: [10, 20, 15, 25, 30]<\/p>\n<p>}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<p>df[&#39;date&#39;] = pd.to_datetime(df[&#39;date&#39;])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>3\u3001\u7ed8\u5236\u56fe\u8868<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528plotly\u7ed8\u5236\u56fe\u8868\uff0c\u5e76\u5c06\u65f6\u95f4\u4f5c\u4e3ax\u8f74\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">fig = px.line(df, x=&#39;date&#39;, y=&#39;value&#39;, title=&#39;Time Series Data&#39;)<\/p>\n<p>fig.update_xaxes(title_text=&#39;Date&#39;)<\/p>\n<p>fig.update_yaxes(title_text=&#39;Value&#39;)<\/p>\n<p>fig.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>Plotly\u662f\u4e00\u4e2a\u4ea4\u4e92\u5f0f\u56fe\u8868\u5e93\uff0c\u652f\u6301\u4e30\u5bcc\u7684\u4ea4\u4e92\u529f\u80fd\u548c\u7f8e\u89c2\u7684\u56fe\u8868\u3002<\/strong><\/p>\n<\/p>\n<p><h2>\u56db\u3001\u5904\u7406\u65f6\u95f4\u6570\u636e\u7684\u6280\u5de7<\/h2>\n<\/p>\n<p><h3>1\u3001\u89e3\u6790\u548c\u683c\u5f0f\u5316\u65f6\u95f4<\/h3>\n<\/p>\n<p><p>\u5728\u5904\u7406\u65f6\u95f4\u6570\u636e\u65f6\uff0c\u786e\u4fdd\u65f6\u95f4\u6570\u636e\u88ab\u6b63\u786e\u89e3\u6790\u548c\u683c\u5f0f\u5316\u975e\u5e38\u91cd\u8981\u3002\u4f7f\u7528pandas\u7684to_datetime\u51fd\u6570\u53ef\u4ee5\u65b9\u4fbf\u5730\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3adatetime\u5bf9\u8c61\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">df[&#39;date&#39;] = pd.to_datetime(df[&#39;date&#39;])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u5904\u7406\u7f3a\u5931\u503c<\/h3>\n<\/p>\n<p><p>\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u4e2d\u5e38\u5e38\u4f1a\u6709\u7f3a\u5931\u503c\uff0c\u5904\u7406\u8fd9\u4e9b\u7f3a\u5931\u503c\u53ef\u4ee5\u63d0\u9ad8\u56fe\u8868\u7684\u51c6\u786e\u6027\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">df = df.interpolate(method=&#39;time&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>3\u3001\u8bbe\u7f6e\u65f6\u95f4\u95f4\u9694<\/h3>\n<\/p>\n<p><p>\u5728\u7ed8\u5236\u56fe\u8868\u65f6\uff0c\u53ef\u4ee5\u6839\u636e\u9700\u8981\u8bbe\u7f6e\u65f6\u95f4\u95f4\u9694\uff0c\u5982\u6bcf\u65e5\u3001\u6bcf\u6708\u3001\u6bcf\u5e74\u7b49\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">df = df.set_index(&#39;date&#39;).resample(&#39;D&#39;).mean().reset_index()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u8fd9\u4e9b\u6280\u5de7\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u66f4\u597d\u5730\u5904\u7406\u548c\u53ef\u89c6\u5316\u65f6\u95f4\u6570\u636e\u3002<\/strong><\/p>\n<\/p>\n<p><h2>\u4e94\u3001\u5b9e\u4f8b\uff1a\u80a1\u7968\u4ef7\u683c\u53ef\u89c6\u5316<\/h2>\n<\/p>\n<p><h3>1\u3001\u5bfc\u5165\u6570\u636e<\/h3>\n<\/p>\n<p><p>\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u5305\u542b\u80a1\u7968\u4ef7\u683c\u7684CSV\u6587\u4ef6\uff0c\u6211\u4eec\u9996\u5148\u9700\u8981\u5bfc\u5165\u6570\u636e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>df = pd.read_csv(&#39;stock_prices.csv&#39;)<\/p>\n<p>df[&#39;date&#39;] = pd.to_datetime(df[&#39;date&#39;])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u7ed8\u5236\u56fe\u8868<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528matplotlib\u7ed8\u5236\u80a1\u7968\u4ef7\u683c\u56fe\u8868\uff0c\u5e76\u5c06\u65f6\u95f4\u4f5c\u4e3ax\u8f74\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>plt.figure(figsize=(15, 7))<\/p>\n<p>plt.plot(df[&#39;date&#39;], df[&#39;price&#39;], marker=&#39;o&#39;)<\/p>\n<p>plt.xlabel(&#39;Date&#39;)<\/p>\n<p>plt.ylabel(&#39;Stock Price&#39;)<\/p>\n<p>plt.title(&#39;Stock Price Over Time&#39;)<\/p>\n<p>plt.xticks(rotation=45)<\/p>\n<p>plt.grid(True)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>3\u3001\u6dfb\u52a0\u79fb\u52a8\u5e73\u5747\u7ebf<\/h3>\n<\/p>\n<p><p>\u4e3a\u4e86\u66f4\u597d\u5730\u5206\u6790\u80a1\u7968\u4ef7\u683c\u8d8b\u52bf\uff0c\u53ef\u4ee5\u6dfb\u52a0\u79fb\u52a8\u5e73\u5747\u7ebf\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">df[&#39;MA30&#39;] = df[&#39;price&#39;].rolling(window=30).mean()<\/p>\n<p>plt.figure(figsize=(15, 7))<\/p>\n<p>plt.plot(df[&#39;date&#39;], df[&#39;price&#39;], label=&#39;Stock Price&#39;, marker=&#39;o&#39;)<\/p>\n<p>plt.plot(df[&#39;date&#39;], df[&#39;MA30&#39;], label=&#39;30-Day MA&#39;, linestyle=&#39;--&#39;)<\/p>\n<p>plt.xlabel(&#39;Date&#39;)<\/p>\n<p>plt.ylabel(&#39;Stock Price&#39;)<\/p>\n<p>plt.title(&#39;Stock Price with 30-Day Moving Average&#39;)<\/p>\n<p>plt.legend()<\/p>\n<p>plt.xticks(rotation=45)<\/p>\n<p>plt.grid(True)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u901a\u8fc7\u6dfb\u52a0\u79fb\u52a8\u5e73\u5747\u7ebf\uff0c\u53ef\u4ee5\u66f4\u6e05\u6670\u5730\u89c2\u5bdf\u4ef7\u683c\u7684\u957f\u671f\u8d8b\u52bf\u3002<\/strong><\/p>\n<\/p>\n<p><h2>\u516d\u3001\u603b\u7ed3<\/h2>\n<\/p>\n<p><p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u8be6\u7ec6\u4ecb\u7ecd\u4e86\u5982\u4f55\u5728Python\u4e2d\u4f7f\u7528\u65f6\u95f4\u4f5c\u4e3ax\u8f74\u8fdb\u884c\u6570\u636e\u53ef\u89c6\u5316\u3002\u4e3b\u8981\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528pandas\u548cmatplotlib\u3001\u4f7f\u7528seaborn\u3001\u4f7f\u7528plotly\u7b49\u3002\u6211\u4eec\u8fd8\u8ba8\u8bba\u4e86\u5904\u7406\u65f6\u95f4\u6570\u636e\u7684\u4e00\u4e9b\u6280\u5de7\uff0c\u5982\u89e3\u6790\u548c\u683c\u5f0f\u5316\u65f6\u95f4\u3001\u5904\u7406\u7f3a\u5931\u503c\u3001\u8bbe\u7f6e\u65f6\u95f4\u95f4\u9694\u7b49\u3002\u6700\u540e\uff0c\u901a\u8fc7\u4e00\u4e2a\u80a1\u7968\u4ef7\u683c\u53ef\u89c6\u5316\u7684\u5b9e\u4f8b\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u5b9e\u9645\u5e94\u7528\u8fd9\u4e9b\u65b9\u6cd5\u548c\u6280\u5de7\u3002<\/p>\n<\/p>\n<p><p><strong>\u901a\u8fc7\u638c\u63e1\u8fd9\u4e9b\u65b9\u6cd5\u548c\u6280\u5de7\uff0c\u53ef\u4ee5\u66f4\u597d\u5730\u5904\u7406\u548c\u53ef\u89c6\u5316\u65f6\u95f4\u5e8f\u5217\u6570\u636e\uff0c\u4e3a\u6570\u636e\u5206\u6790\u548c\u51b3\u7b56\u63d0\u4f9b\u6709\u529b\u652f\u6301\u3002<\/strong><\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u5c06\u65f6\u95f4\u6570\u636e\u8f6c\u6362\u4e3ax\u8f74\u683c\u5f0f\uff1f<\/strong><br \/>\u8981\u5728Python\u4e2d\u5c06\u65f6\u95f4\u6570\u636e\u8f6c\u6362\u4e3ax\u8f74\u683c\u5f0f\uff0c\u901a\u5e38\u53ef\u4ee5\u4f7f\u7528<code>pandas<\/code>\u5e93\u6765\u5904\u7406\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u3002\u901a\u8fc7\u5c06\u65f6\u95f4\u5217\u8f6c\u6362\u4e3a<code>datetime<\/code>\u7c7b\u578b\uff0c\u7136\u540e\u4f7f\u7528<code>matplotlib<\/code>\u7b49\u53ef\u89c6\u5316\u5e93\u5c06\u5176\u4f5c\u4e3ax\u8f74\u7ed8\u5236\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff1a  <\/p>\n<pre><code class=\"language-python\">import pandas as pd\nimport matplotlib.pyplot as plt\n\n# \u521b\u5efa\u793a\u4f8b\u6570\u636e\ndata = {&#39;date&#39;: [&#39;2023-01-01&#39;, &#39;2023-01-02&#39;, &#39;2023-01-03&#39;], &#39;value&#39;: [10, 20, 15]}\ndf = pd.DataFrame(data)\ndf[&#39;date&#39;] = pd.to_datetime(df[&#39;date&#39;])\n\n# \u7ed8\u5236\u56fe\u5f62\nplt.plot(df[&#39;date&#39;], df[&#39;value&#39;])\nplt.xlabel(&#39;Date&#39;)\nplt.ylabel(&#39;Value&#39;)\nplt.title(&#39;Time Series Data&#39;)\nplt.show()\n<\/code><\/pre>\n<p>\u4f7f\u7528\u8fd9\u79cd\u65b9\u6cd5\uff0c\u65f6\u95f4\u6570\u636e\u5c06\u6b63\u786e\u5730\u663e\u793a\u5728x\u8f74\u4e0a\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5982\u4f55\u81ea\u5b9a\u4e49\u65f6\u95f4\u683c\u5f0f\u663e\u793a\u5728x\u8f74\u4e0a\uff1f<\/strong><br \/>\u5728Python\u7684<code>matplotlib<\/code>\u5e93\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>mdates<\/code>\u6a21\u5757\u6765\u8bbe\u7f6e\u65f6\u95f4\u683c\u5f0f\u3002\u901a\u8fc7<code>DateFormatter<\/code>\u7c7b\uff0c\u60a8\u53ef\u4ee5\u81ea\u5b9a\u4e49\u663e\u793a\u683c\u5f0f\uff0c\u4f8b\u5982&quot;YYYY-MM-DD&quot;\u6216&quot;MM\/DD\/YYYY&quot;\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a  <\/p>\n<pre><code class=\"language-python\">import matplotlib.dates as mdates\n\n# \u7ed8\u56fe\u4ee3\u7801...\nplt.gca().xaxis.set_major_formatter(mdates.DateFormatter(&#39;%Y-%m-%d&#39;))\n<\/code><\/pre>\n<p>\u8fd9\u5c06\u4f7fx\u8f74\u4e0a\u7684\u65e5\u671f\u663e\u793a\u4e3a\u60a8\u6307\u5b9a\u7684\u683c\u5f0f\u3002<\/p>\n<p><strong>\u4f7f\u7528Python\u7ed8\u5236\u65f6\u95f4\u5e8f\u5217\u56fe\u65f6\uff0c\u5982\u4f55\u5904\u7406\u7f3a\u5931\u7684\u65f6\u95f4\u6570\u636e\uff1f<\/strong><br \/>\u5728\u5904\u7406\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u65f6\uff0c\u7f3a\u5931\u503c\u662f\u5e38\u89c1\u95ee\u9898\u3002\u53ef\u4ee5\u4f7f\u7528<code>pandas<\/code>\u4e2d\u7684<code>resample<\/code>\u65b9\u6cd5\u6765\u586b\u8865\u7f3a\u5931\u7684\u65f6\u95f4\u6bb5\uff0c\u6216\u4f7f\u7528<code>interpolate<\/code>\u65b9\u6cd5\u8fdb\u884c\u63d2\u503c\u3002\u4f8b\u5982\uff1a  <\/p>\n<pre><code class=\"language-python\">df.set_index(&#39;date&#39;, inplace=True)\ndf = df.resample(&#39;D&#39;).mean().interpolate()\n<\/code><\/pre>\n<p>\u8fd9\u5c06\u786e\u4fdd\u65f6\u95f4\u5e8f\u5217\u56fe\u7684\u8fde\u8d2f\u6027\uff0c\u907f\u514d\u56e0\u7f3a\u5931\u6570\u636e\u800c\u5bfc\u81f4\u7684\u7ed8\u56fe\u95ee\u9898\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u4f7f\u7528\u65f6\u95f4\u4f5c\u4e3ax\u8f74\u7684\u65b9\u5f0f\u4e3b\u8981\u6709\uff1a\u4f7f\u7528pandas\u548cmatplotlib\u3001\u4f7f\u7528seaborn\u3001\u4f7f\u7528 [&hellip;]","protected":false},"author":3,"featured_media":1075771,"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\/1075766"}],"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=1075766"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1075766\/revisions"}],"predecessor-version":[{"id":1075773,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1075766\/revisions\/1075773"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1075771"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1075766"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1075766"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1075766"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}