{"id":1109769,"date":"2025-01-08T17:13:19","date_gmt":"2025-01-08T09:13:19","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1109769.html"},"modified":"2025-01-08T17:13:24","modified_gmt":"2025-01-08T09:13:24","slug":"python%e5%a6%82%e4%bd%95%e5%9c%a8%e5%9d%90%e6%a0%87%e4%b8%8a%e6%a0%87%e6%9c%80%e5%a4%a7%e5%80%bc","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1109769.html","title":{"rendered":"python\u5982\u4f55\u5728\u5750\u6807\u4e0a\u6807\u6700\u5927\u503c"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25072908\/897dcc71-dc3f-4d40-8dd5-a96050d9f117.webp\" alt=\"python\u5982\u4f55\u5728\u5750\u6807\u4e0a\u6807\u6700\u5927\u503c\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u6807\u8bb0\u5750\u6807\u4e0a\u7684\u6700\u5927\u503c\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u6cd5\u5b9e\u73b0<\/strong>\uff0c\u4f8b\u5982\u4f7f\u7528Matplotlib\u5e93\u3001Seaborn\u5e93\u7b49\u3002<strong>\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u662f\u901a\u8fc7Matplotlib\u5e93<\/strong>\uff0c\u56e0\u4e3a\u5b83\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u7ed8\u56fe\u529f\u80fd\u548c\u7075\u6d3b\u7684\u56fe\u5f62\u5b9a\u5236\u9009\u9879\u3002\u4e3a\u4e86\u6807\u8bb0\u5750\u6807\u4e0a\u7684\u6700\u5927\u503c\uff0c\u6211\u4eec\u9700\u8981\u627e\u5230\u6570\u636e\u4e2d\u7684\u6700\u5927\u503c\u53ca\u5176\u5bf9\u5e94\u7684\u5750\u6807\u4f4d\u7f6e\uff0c\u5e76\u5728\u56fe\u4e0a\u6807\u8bb0\u51fa\u6765\u3002\u63a5\u4e0b\u6765\uff0c\u5c06\u8be6\u7ec6\u63cf\u8ff0\u5982\u4f55\u4f7f\u7528Matplotlib\u5e93\u6765\u5b9e\u73b0\u8fd9\u4e00\u529f\u80fd\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u5bfc\u5165\u5fc5\u8981\u7684\u5e93<\/h3>\n<\/p>\n<p><p>\u5728\u5f00\u59cb\u7ed8\u56fe\u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u5bfc\u5165\u5fc5\u8981\u7684\u5e93\u3002Matplotlib\u5e93\u662fPython\u4e2d\u6700\u5e38\u7528\u7684\u7ed8\u56fe\u5e93\u4e4b\u4e00\uff0c\u6211\u4eec\u9700\u8981\u5bfc\u5165\u5b83\u7684pyplot\u6a21\u5757\u3002<\/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><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u751f\u6210\u6570\u636e<\/h3>\n<\/p>\n<p><p>\u4e3a\u4e86\u6f14\u793a\u5982\u4f55\u5728\u5750\u6807\u4e0a\u6807\u8bb0\u6700\u5927\u503c\uff0c\u6211\u4eec\u9700\u8981\u751f\u6210\u4e00\u4e9b\u793a\u4f8b\u6570\u636e\u3002\u8fd9\u91cc\u6211\u4eec\u4f7f\u7528NumPy\u5e93\u751f\u6210\u4e00\u4e9b\u968f\u673a\u6570\u636e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">x = np.linspace(0, 10, 100)<\/p>\n<p>y = np.sin(x) + np.random.normal(0, 0.1, 100)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u7ed8\u5236\u6570\u636e<\/h3>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u4f7f\u7528Matplotlib\u7ed8\u5236\u8fd9\u4e9b\u6570\u636e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.plot(x, y, label=&#39;Data&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u627e\u5230\u6700\u5927\u503c\u53ca\u5176\u5bf9\u5e94\u7684\u5750\u6807<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528NumPy\u7684<code>max<\/code>\u51fd\u6570\u627e\u5230y\u6570\u636e\u4e2d\u7684\u6700\u5927\u503c\uff0c\u5e76\u4f7f\u7528<code>argmax<\/code>\u51fd\u6570\u627e\u5230\u6700\u5927\u503c\u7684\u7d22\u5f15\uff0c\u7136\u540e\u4f7f\u7528\u8fd9\u4e2a\u7d22\u5f15\u627e\u5230\u5bf9\u5e94\u7684x\u5750\u6807\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">max_y = np.max(y)<\/p>\n<p>max_x = x[np.argmax(y)]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u6807\u8bb0\u6700\u5927\u503c<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528Matplotlib\u7684<code>annotate<\/code>\u51fd\u6570\u5728\u56fe\u4e0a\u6807\u8bb0\u6700\u5927\u503c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.annotate(f&#39;Max Value: {max_y:.2f}&#39;, xy=(max_x, max_y), xytext=(max_x+1, max_y+1),<\/p>\n<p>             arrowprops=dict(facecolor=&#39;red&#39;, shrink=0.05))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516d\u3001\u6dfb\u52a0\u56fe\u4f8b\u548c\u663e\u793a\u56fe\u5f62<\/h3>\n<\/p>\n<p><p>\u6700\u540e\uff0c\u6dfb\u52a0\u56fe\u4f8b\u5e76\u663e\u793a\u56fe\u5f62\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.legend()<\/p>\n<p>plt.xlabel(&#39;X-axis&#39;)<\/p>\n<p>plt.ylabel(&#39;Y-axis&#39;)<\/p>\n<p>plt.title(&#39;Plot with Max Value Annotated&#39;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u5b8c\u6574\u4ee3\u7801<\/h3>\n<\/p>\n<p><p>\u4e0b\u9762\u662f\u5b8c\u6574\u7684\u4ee3\u7801\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<h2><strong>\u751f\u6210\u6570\u636e<\/strong><\/h2>\n<p>x = np.linspace(0, 10, 100)<\/p>\n<p>y = np.sin(x) + np.random.normal(0, 0.1, 100)<\/p>\n<h2><strong>\u7ed8\u5236\u6570\u636e<\/strong><\/h2>\n<p>plt.plot(x, y, label=&#39;Data&#39;)<\/p>\n<h2><strong>\u627e\u5230\u6700\u5927\u503c\u53ca\u5176\u5bf9\u5e94\u7684\u5750\u6807<\/strong><\/h2>\n<p>max_y = np.max(y)<\/p>\n<p>max_x = x[np.argmax(y)]<\/p>\n<h2><strong>\u6807\u8bb0\u6700\u5927\u503c<\/strong><\/h2>\n<p>plt.annotate(f&#39;Max Value: {max_y:.2f}&#39;, xy=(max_x, max_y), xytext=(max_x+1, max_y+1),<\/p>\n<p>             arrowprops=dict(facecolor=&#39;red&#39;, shrink=0.05))<\/p>\n<h2><strong>\u6dfb\u52a0\u56fe\u4f8b\u548c\u663e\u793a\u56fe\u5f62<\/strong><\/h2>\n<p>plt.legend()<\/p>\n<p>plt.xlabel(&#39;X-axis&#39;)<\/p>\n<p>plt.ylabel(&#39;Y-axis&#39;)<\/p>\n<p>plt.title(&#39;Plot with Max Value Annotated&#39;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u8be6\u7ec6\u63cf\u8ff0\u6807\u8bb0\u6700\u5927\u503c\u7684\u65b9\u6cd5<\/h3>\n<\/p>\n<p><p><strong>Matplotlib\u7684<code>annotate<\/code>\u51fd\u6570\u662f\u6807\u8bb0\u56fe\u5f62\u4e2d\u7279\u5b9a\u70b9\u7684\u5f3a\u5927\u5de5\u5177<\/strong>\u3002\u5b83\u5141\u8bb8\u6211\u4eec\u5728\u56fe\u5f62\u4e0a\u6dfb\u52a0\u6ce8\u91ca\uff0c\u5e76\u53ef\u4ee5\u901a\u8fc7\u8bb8\u591a\u53c2\u6570\u6765\u81ea\u5b9a\u4e49\u6ce8\u91ca\u7684\u5916\u89c2\u548c\u4f4d\u7f6e\u3002<code>annotate<\/code>\u51fd\u6570\u7684\u57fa\u672c\u7528\u6cd5\u5305\u62ec\u4ee5\u4e0b\u51e0\u4e2a\u53c2\u6570\uff1a<\/p>\n<\/p>\n<ul>\n<li><code>text<\/code>\uff1a\u8981\u663e\u793a\u7684\u6ce8\u91ca\u6587\u672c\u3002<\/li>\n<li><code>xy<\/code>\uff1a\u8981\u6ce8\u91ca\u7684\u70b9\u7684\u5750\u6807\u3002<\/li>\n<li><code>xytext<\/code>\uff1a\u6ce8\u91ca\u6587\u672c\u7684\u4f4d\u7f6e\uff0c\u5982\u679c\u4e0d\u6307\u5b9a\uff0c\u9ed8\u8ba4\u4e0e<code>xy<\/code>\u76f8\u540c\u3002<\/li>\n<li><code>arrowprops<\/code>\uff1a\u4e00\u4e2a\u5b57\u5178\uff0c\u6307\u5b9a\u7bad\u5934\u7684\u5c5e\u6027\uff0c\u5982\u989c\u8272\u3001\u5f62\u72b6\u7b49\u3002<\/li>\n<\/ul>\n<p><p>\u901a\u8fc7\u8bbe\u7f6e\u8fd9\u4e9b\u53c2\u6570\uff0c\u6211\u4eec\u53ef\u4ee5\u7075\u6d3b\u5730\u5728\u56fe\u5f62\u4e0a\u6807\u8bb0\u7279\u5b9a\u70b9\uff0c\u5e76\u4f7f\u6ce8\u91ca\u6587\u672c\u548c\u7bad\u5934\u7684\u5916\u89c2\u7b26\u5408\u6211\u4eec\u7684\u9700\u6c42\u3002<\/p>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u4e86\u4ee5\u4e0b\u53c2\u6570\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.annotate(f&#39;Max Value: {max_y:.2f}&#39;, xy=(max_x, max_y), xytext=(max_x+1, max_y+1),<\/p>\n<p>             arrowprops=dict(facecolor=&#39;red&#39;, shrink=0.05))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ul>\n<li><code>f&#39;Max Value: {max_y:.2f}&#39;<\/code>\uff1a\u6ce8\u91ca\u6587\u672c\uff0c\u663e\u793a\u6700\u5927\u503c\uff0c\u4fdd\u7559\u4e24\u4f4d\u5c0f\u6570\u3002<\/li>\n<li><code>xy=(max_x, max_y)<\/code>\uff1a\u8981\u6ce8\u91ca\u7684\u70b9\u7684\u5750\u6807\uff0c\u5373\u6700\u5927\u503c\u6240\u5728\u7684\u5750\u6807\u3002<\/li>\n<li><code>xytext=(max_x+1, max_y+1)<\/code>\uff1a\u6ce8\u91ca\u6587\u672c\u7684\u4f4d\u7f6e\uff0c\u7a0d\u5fae\u504f\u79fb\u539f\u70b9\uff0c\u4ee5\u907f\u514d\u8986\u76d6\u6570\u636e\u70b9\u3002<\/li>\n<li><code>arrowprops=dict(facecolor=&#39;red&#39;, shrink=0.05)<\/code>\uff1a\u7bad\u5934\u7684\u5c5e\u6027\uff0c\u8bbe\u7f6e\u7bad\u5934\u7684\u989c\u8272\u4e3a\u7ea2\u8272\uff0c\u5e76\u63a7\u5236\u7bad\u5934\u7684\u7f29\u653e\u3002<\/li>\n<\/ul>\n<p><h3>\u5176\u4ed6\u6807\u8bb0\u6700\u5927\u503c\u7684\u65b9\u6cd5<\/h3>\n<\/p>\n<p><p>\u867d\u7136Matplotlib\u662f\u6700\u5e38\u7528\u7684\u7ed8\u56fe\u5e93\uff0c\u4f46\u5728\u4e00\u4e9b\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u53ef\u80fd\u4f1a\u9009\u62e9\u5176\u4ed6\u5e93\uff0c\u4f8b\u5982Seaborn\u6216Plotly\uff0c\u5b83\u4eec\u63d0\u4f9b\u4e86\u989d\u5916\u7684\u529f\u80fd\u548c\u66f4\u7b80\u6d01\u7684\u8bed\u6cd5\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u7b80\u8981\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u8fd9\u4e9b\u5e93\u6765\u6807\u8bb0\u6700\u5927\u503c\u3002<\/p>\n<\/p>\n<p><h3>\u4f7f\u7528Seaborn\u6807\u8bb0\u6700\u5927\u503c<\/h3>\n<\/p>\n<p><p>Seaborn\u662f\u57fa\u4e8eMatplotlib\u6784\u5efa\u7684\u9ad8\u7ea7\u7ed8\u56fe\u5e93\uff0c\u63d0\u4f9b\u4e86\u66f4\u7b80\u6d01\u7684API\u548c\u66f4\u7f8e\u89c2\u7684\u9ed8\u8ba4\u6837\u5f0f\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Seaborn\u7ed8\u5236\u56fe\u5f62\uff0c\u5e76\u7ed3\u5408Matplotlib\u7684<code>annotate<\/code>\u51fd\u6570\u6807\u8bb0\u6700\u5927\u503c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import seaborn as sns<\/p>\n<p>import numpy as np<\/p>\n<p>import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u751f\u6210\u6570\u636e<\/strong><\/h2>\n<p>x = np.linspace(0, 10, 100)<\/p>\n<p>y = np.sin(x) + np.random.normal(0, 0.1, 100)<\/p>\n<h2><strong>\u7ed8\u5236\u6570\u636e<\/strong><\/h2>\n<p>sns.lineplot(x, y)<\/p>\n<h2><strong>\u627e\u5230\u6700\u5927\u503c\u53ca\u5176\u5bf9\u5e94\u7684\u5750\u6807<\/strong><\/h2>\n<p>max_y = np.max(y)<\/p>\n<p>max_x = x[np.argmax(y)]<\/p>\n<h2><strong>\u6807\u8bb0\u6700\u5927\u503c<\/strong><\/h2>\n<p>plt.annotate(f&#39;Max Value: {max_y:.2f}&#39;, xy=(max_x, max_y), xytext=(max_x+1, max_y+1),<\/p>\n<p>             arrowprops=dict(facecolor=&#39;blue&#39;, shrink=0.05))<\/p>\n<h2><strong>\u663e\u793a\u56fe\u5f62<\/strong><\/h2>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4f7f\u7528Plotly\u6807\u8bb0\u6700\u5927\u503c<\/h3>\n<\/p>\n<p><p>Plotly\u662f\u4e00\u4e2a\u4ea4\u4e92\u5f0f\u7ed8\u56fe\u5e93\uff0c\u9002\u5408\u521b\u5efa\u52a8\u6001\u548c\u4ea4\u4e92\u5f0f\u56fe\u8868\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Plotly\u7684<code>scatter<\/code>\u51fd\u6570\u7ed8\u5236\u6570\u636e\uff0c\u5e76\u7ed3\u5408<code>add_annotation<\/code>\u51fd\u6570\u6807\u8bb0\u6700\u5927\u503c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import plotly.graph_objects as go<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u751f\u6210\u6570\u636e<\/strong><\/h2>\n<p>x = np.linspace(0, 10, 100)<\/p>\n<p>y = np.sin(x) + np.random.normal(0, 0.1, 100)<\/p>\n<h2><strong>\u627e\u5230\u6700\u5927\u503c\u53ca\u5176\u5bf9\u5e94\u7684\u5750\u6807<\/strong><\/h2>\n<p>max_y = np.max(y)<\/p>\n<p>max_x = x[np.argmax(y)]<\/p>\n<h2><strong>\u521b\u5efa\u56fe\u5f62<\/strong><\/h2>\n<p>fig = go.Figure()<\/p>\n<h2><strong>\u6dfb\u52a0\u6570\u636e<\/strong><\/h2>\n<p>fig.add_trace(go.Scatter(x=x, y=y, mode=&#39;lines&#39;, name=&#39;Data&#39;))<\/p>\n<h2><strong>\u6dfb\u52a0\u6ce8\u91ca<\/strong><\/h2>\n<p>fig.add_annotation(x=max_x, y=max_y,<\/p>\n<p>                   text=f&#39;Max Value: {max_y:.2f}&#39;,<\/p>\n<p>                   showarrow=True,<\/p>\n<p>                   arrowhead=2)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u5f62<\/strong><\/h2>\n<p>fig.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728Python\u4e2d\u6807\u8bb0\u5750\u6807\u4e0a\u7684\u6700\u5927\u503c\u4e3b\u8981\u6709\u4ee5\u4e0b\u65b9\u6cd5\uff1a<strong>\u4f7f\u7528Matplotlib\u5e93<\/strong>\u3001<strong>\u4f7f\u7528Seaborn\u5e93<\/strong>\u3001<strong>\u4f7f\u7528Plotly\u5e93<\/strong>\u3002\u8fd9\u4e9b\u65b9\u6cd5\u5404\u6709\u4f18\u7f3a\u70b9\uff0c\u9009\u62e9\u54ea\u79cd\u65b9\u6cd5\u53d6\u51b3\u4e8e\u5177\u4f53\u7684\u9700\u6c42\u548c\u504f\u597d\u3002\u901a\u8fc7\u5b66\u4e60\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u6211\u4eec\u53ef\u4ee5\u7075\u6d3b\u5730\u5728\u56fe\u5f62\u4e0a\u6807\u8bb0\u6700\u5927\u503c\uff0c\u4f7f\u6570\u636e\u5206\u6790\u548c\u53ef\u89c6\u5316\u66f4\u52a0\u6e05\u6670\u548c\u6613\u4e8e\u7406\u89e3\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u627e\u51fa\u6570\u636e\u96c6\u4e2d\u7684\u6700\u5927\u503c\u5e76\u6807\u8bb0\u5176\u5750\u6807\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528NumPy\u5e93\u6765\u5904\u7406\u6570\u7ec4\u6570\u636e\uff0c\u627e\u51fa\u6700\u5927\u503c\u53ca\u5176\u5750\u6807\u3002\u9996\u5148\uff0c\u60a8\u9700\u8981\u5bfc\u5165NumPy\u5e93\u5e76\u521b\u5efa\u4e00\u4e2a\u6570\u7ec4\u3002\u4f7f\u7528<code>np.argmax()<\/code>\u51fd\u6570\u53ef\u4ee5\u83b7\u53d6\u6700\u5927\u503c\u7684\u7d22\u5f15\uff0c\u901a\u8fc7\u8be5\u7d22\u5f15\u53ef\u4ee5\u76f4\u63a5\u8bbf\u95ee\u6700\u5927\u503c\u548c\u5176\u5750\u6807\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-python\">import numpy as np\n\ndata = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])\nmax_index = np.argmax(data)\nmax_value = data.flat[max_index]\ncoordinates = np.unravel_index(max_index, data.shape)\n\nprint(&quot;\u6700\u5927\u503c:&quot;, max_value)\nprint(&quot;\u5750\u6807:&quot;, coordinates)\n<\/code><\/pre>\n<p><strong>\u5982\u4f55\u5728\u56fe\u8868\u4e0a\u6807\u8bb0\u6700\u5927\u503c\uff1f<\/strong><br \/>\u5728\u4f7f\u7528Matplotlib\u7ed8\u5236\u56fe\u8868\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7<code>plt.annotate()<\/code>\u51fd\u6570\u5728\u56fe\u5f62\u4e0a\u6807\u8bb0\u6700\u5927\u503c\u3002\u627e\u51fa\u6700\u5927\u503c\u53ca\u5176\u5750\u6807\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u8be5\u51fd\u6570\u6dfb\u52a0\u6ce8\u91ca\u6216\u6807\u8bb0\u3002\u4ee5\u4e0b\u662f\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<pre><code class=\"language-python\">import matplotlib.pyplot as plt\n\nx = np.arange(10)\ny = np.random.rand(10)\n\nplt.plot(x, y)\nmax_index = np.argmax(y)\nplt.scatter(x[max_index], y[max_index], color=&#39;red&#39;)  # \u6807\u8bb0\u6700\u5927\u503c\nplt.annotate(&#39;\u6700\u5927\u503c&#39;, xy=(x[max_index], y[max_index]), xytext=(x[max_index]+0.5, y[max_index]+0.1),\n             arrowprops=dict(facecolor=&#39;black&#39;, shrink=0.05))\nplt.show()\n<\/code><\/pre>\n<p><strong>\u662f\u5426\u53ef\u4ee5\u4f7f\u7528\u5176\u4ed6\u5e93\u6765\u6807\u8bb0\u6700\u5927\u503c\uff1f<\/strong><br \/>\u9664\u4e86NumPy\u548cMatplotlib\uff0c\u60a8\u8fd8\u53ef\u4ee5\u4f7f\u7528Pandas\u8fdb\u884c\u6570\u636e\u5904\u7406\uff0c\u5e76\u7ed3\u5408Seaborn\u8fdb\u884c\u53ef\u89c6\u5316\u3002Pandas\u63d0\u4f9b\u4e86\u7b80\u5355\u7684\u65b9\u5f0f\u6765\u5904\u7406\u6570\u636e\u5e27\uff0c\u5229\u7528<code>idxmax()<\/code>\u51fd\u6570\u53ef\u4ee5\u8f7b\u677e\u627e\u5230\u6700\u5927\u503c\u7684\u7d22\u5f15\u3002Seaborn\u53ef\u4ee5\u8fdb\u884c\u66f4\u7f8e\u89c2\u7684\u56fe\u8868\u7ed8\u5236\u3002\u4ee5\u4e0b\u662f\u7ed3\u5408\u4f7f\u7528\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code class=\"language-python\">import pandas as pd\nimport seaborn as sns\nimport matplotlib.pyplot as plt\n\ndata = pd.DataFrame({&#39;x&#39;: range(10), &#39;y&#39;: np.random.rand(10)})\nmax_index = data[&#39;y&#39;].idxmax()\n\nsns.lineplot(data=data, x=&#39;x&#39;, y=&#39;y&#39;)\nplt.scatter(data[&#39;x&#39;][max_index], data[&#39;y&#39;][max_index], color=&#39;red&#39;)  # \u6807\u8bb0\u6700\u5927\u503c\nplt.annotate(&#39;\u6700\u5927\u503c&#39;, xy=(data[&#39;x&#39;][max_index], data[&#39;y&#39;][max_index]), \n             xytext=(data[&#39;x&#39;][max_index]+0.5, data[&#39;y&#39;][max_index]+0.1),\n             arrowprops=dict(facecolor=&#39;black&#39;, shrink=0.05))\nplt.show()\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u6807\u8bb0\u5750\u6807\u4e0a\u7684\u6700\u5927\u503c\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u6cd5\u5b9e\u73b0\uff0c\u4f8b\u5982\u4f7f\u7528Matplotlib\u5e93\u3001Seaborn\u5e93\u7b49\u3002\u6700 [&hellip;]","protected":false},"author":3,"featured_media":1109782,"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\/1109769"}],"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=1109769"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1109769\/revisions"}],"predecessor-version":[{"id":1109784,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1109769\/revisions\/1109784"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1109782"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1109769"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1109769"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1109769"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}