{"id":204679,"date":"2025-05-29T13:14:39","date_gmt":"2025-05-29T05:14:39","guid":{"rendered":"https:\/\/server.hk\/cnblog\/204679\/"},"modified":"2025-05-29T13:14:39","modified_gmt":"2025-05-29T05:14:39","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-python-%e7%bb%98%e5%88%b6%e5%b8%a6%e6%9c%89%e7%bd%ae%e4%bf%a1%e5%8c%ba%e9%97%b4%e7%9a%84%e5%9b%be%e5%bd%a2%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/204679\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 Python \u7ed8\u5236\u5e26\u6709\u7f6e\u4fe1\u533a\u95f4\u7684\u56fe\u5f62\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u5982\u4f55\u4f7f\u7528 Python \u7ed8\u5236\u5e26\u6709\u7f6e\u4fe1\u533a\u95f4\u7684\u56fe\u5f62\uff1f<\/h1>\n<p>IT\u884c\u4e1a\u76f8\u5bf9\u4e8e\u4e00\u822c\u4f20\u7edf\u884c\u4e1a\uff0c\u53d1\u5c55\u66f4\u65b0\u901f\u5ea6\u66f4\u5feb\uff0c\u4e00\u65e6\u505c\u6b62\u4e86\u5b66\u4e60\uff0c\u5f88\u5feb\u5c31\u4f1a\u88ab\u884c\u4e1a\u6240\u6dd8\u6c70\u3002\u6240\u4ee5\u6211\u4eec\u9700\u8981\u8e0f\u8e0f\u5b9e\u5b9e\u7684\u4e0d\u65ad\u5b66\u4e60\uff0c\u7cbe\u8fdb\u81ea\u5df1\u7684\u6280\u672f\uff0c\u5c24\u5176\u662f\u521d\u5b66\u8005\u3002\u4eca\u5929\u7ed9\u5927\u5bb6\u6574\u7406\u4e86\u300a\u5982\u4f55\u4f7f\u7528 Python \u7ed8\u5236\u5e26\u6709\u7f6e\u4fe1\u533a\u95f4\u7684\u56fe\u5f62\uff1f\u300b\uff0c\u804a\u804a\uff0c\u6211\u4eec\u4e00\u8d77\u6765\u770b\u770b\u5427\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241113\/17314627046734063013147.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u7ed8\u5236\u5e26\u6709\u6307\u5b9a\u7f6e\u4fe1\u533a\u95f4\u7684\u56fe\u5f62<\/strong><\/p>\n<p>\u5728 python \u4e2d\u7ed8\u5236\u5177\u6709\u591a\u4e2a\u7f6e\u4fe1\u533a\u95f4\u7684\u56fe\u5f62\u65f6\uff0c\u4ee5\u4e0b\u6b65\u9aa4\u53ef\u4ee5\u7b80\u5316\u8fc7\u7a0b\uff1a<\/p>\n<ol>\n<li><strong>\u5bfc\u5165\u5fc5\u5907\u5e93\uff1a<\/strong>\u5bfc\u5165 matplotlib \u5e93\uff0c\u5b83\u63d0\u4f9b\u7ed8\u56fe\u529f\u80fd\u3002<\/li>\n<li><strong>\u51c6\u5907\u6570\u636e\uff1a<\/strong>\u5c06\u60a8\u7684\u6570\u636e\u5206\u7ec4\u4e3a\u5305\u542b\u4e2d\u5fc3\u70b9\u53ca\u5176\u7f6e\u4fe1\u533a\u95f4\u7684\u5143\u7ec4\u6216\u5217\u8868\u3002<\/li>\n<li><strong>\u521b\u5efa\u56fe\u5f62\u5bf9\u8c61\uff1a<\/strong>\u4f7f\u7528 matplotlib.pyplot.subplots() \u51fd\u6570\u521b\u5efa\u5177\u6709\u6240\u9700\u5b50\u56fe\u6570\u7684\u56fe\u5f62\u3002<\/li>\n<li><strong>\u7ed8\u5236\u7f6e\u4fe1\u533a\u95f4\uff1a<\/strong>\u5bf9\u4e8e\u6bcf\u4e2a\u4e2d\u5fc3\u70b9\uff0c\u4f7f\u7528 matplotlib.pyplot.errorbar() \u51fd\u6570\u7ed8\u5236\u5176\u7f6e\u4fe1\u533a\u95f4\u3002\u6307\u5b9a\u4e2d\u5fc3\u70b9\u3001\u7f6e\u4fe1\u533a\u95f4\u7684\u4e0a\u754c\u548c\u4e0b\u754c\u3002<\/li>\n<li><strong>\u4fee\u6539\u56fe\u5f62\u5916\u89c2\uff1a<\/strong>\u8bbe\u7f6e\u56fe\u5f62\u6807\u9898\u3001\u8f74\u6807\u7b7e\u548c\u56fe\u4f8b\uff0c\u4ee5\u4f7f\u5176\u6613\u4e8e\u7406\u89e3\u548c\u7f8e\u89c2\u3002<\/li>\n<\/ol>\n<p><strong>\u793a\u4f8b\u4ee3\u7801\uff1a<\/strong><\/p>\n<p>\u4ee5\u4e0b\u793a\u4f8b\u4ee3\u7801\u6f14\u793a\u4e86\u5982\u4f55\u4f7f\u7528\u4e0a\u8ff0\u6b65\u9aa4\u7ed8\u5236\u5177\u6709\u4e2d\u5fc3\u70b9\u548c\u7f6e\u4fe1\u533a\u95f4\u7684\u56fe\u5f62\uff1a<\/p>\n<pre>import matplotlib.pyplot as plt\n\n# \u6837\u4f8b\u6570\u636e\ndata = {\n    'A': [10, 20, 30],\n    'B': [25, 35, 45],\n    'C': [40, 50, 60]\n}\n\n# \u51c6\u5907\u6570\u636e\nerrors = [(up - down) \/ 2 for up, down in zip(data['A'][1:], data['A'][:-1])]\nerrors.append(0)\n\n# \u521b\u5efa\u56fe\u5f62\u5bf9\u8c61\nfig, ax = plt.subplots(figsize=(10, 6))\n\n# \u7ed8\u5236\u7f6e\u4fe1\u533a\u95f4\nax.errorbar(range(len(data['A'])), data['A'],\n             yerr=errors,\n             capsize=3)\n\n# \u8bbe\u7f6e\u56fe\u5f62\u5916\u89c2\nax.set_title('\u7f6e\u4fe1\u533a\u95f4\u56fe')\nax.set_xlabel('\u89c2\u6d4b\u503c')\nax.set_ylabel('\u503c')\nax.legend(data.keys())\nplt.show()<\/pre>\n<p>\u8fd9\u5c06\u751f\u6210\u5177\u6709\u6307\u5b9a\u7f6e\u4fe1\u533a\u95f4\u7684\u56fe\u5f62\uff0c\u6bcf\u4e2a\u4e2d\u5fc3\u70b9\u7528\u4e00\u6761\u5782\u76f4\u7ebf\u8868\u793a\uff0c\u7f6e\u4fe1\u533a\u95f4\u7528\u8fde\u63a5\u7ebf\u8868\u793a\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u300a\u5982\u4f55\u4f7f\u7528 Python \u7ed8\u5236\u5e26\u6709\u7f6e\u4fe1\u533a\u95f4\u7684\u56fe\u5f62\uff1f\u300b\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u5173\u4e8e\u7684\u8d44\u6599\u8bf7\u5173\u6ce8\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u4f7f\u7528 Python \u7ed8\u5236\u5e26\u6709&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-204679","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204679","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=204679"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204679\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=204679"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=204679"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=204679"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}