{"id":204682,"date":"2025-05-29T13:52:17","date_gmt":"2025-05-29T05:52:17","guid":{"rendered":"https:\/\/server.hk\/cnblog\/204682\/"},"modified":"2025-05-29T13:52:17","modified_gmt":"2025-05-29T05:52:17","slug":"%e5%a6%82%e4%bd%95%e7%94%a8-python-%e7%bb%98%e5%88%b6%e5%b8%a6%e6%9c%89%e5%8c%ba%e9%97%b4%e8%be%b9%e7%95%8c%e7%9a%84%e6%95%a3%e7%82%b9%e5%9b%be%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/204682\/","title":{"rendered":"\u5982\u4f55\u7528 Python \u7ed8\u5236\u5e26\u6709\u533a\u95f4\u8fb9\u754c\u7684\u6563\u70b9\u56fe\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u5982\u4f55\u7528 Python \u7ed8\u5236\u5e26\u6709\u533a\u95f4\u8fb9\u754c\u7684\u6563\u70b9\u56fe\uff1f<\/h1>\n<p>\u5b66\u4e60\u8981\u52aa\u529b\uff0c\u4f46\u662f\u4e0d\u8981\u6025\uff01\u4eca\u5929\u7684\u8fd9\u7bc7\u6587\u7ae0<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u5982\u4f55\u7528 Python \u7ed8\u5236\u5e26\u6709\u533a\u95f4\u8fb9\u754c\u7684\u6563\u70b9\u56fe\uff1f\u300b<\/span>\u5c06\u4f1a\u4ecb\u7ecd\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u60f3\u6df1\u5165\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\uff0c\u53ef\u4ee5\u5173\u6ce8\u6211\uff01\u6211\u4f1a\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u6587\u7ae0\u7684\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u90fd\u80fd\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241113\/1731466676673415b45bbce.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u5982\u4f55\u5728 python \u4e2d\u7ed8\u5236\u5177\u6709\u533a\u95f4\u8fb9\u754c\u7684\u6563\u70b9\u56fe<\/strong><\/p>\n<p>\u672c\u6587\u65e8\u5728\u89e3\u7b54\u4e00\u4e2a\u5e38\u89c1\u95ee\u9898\uff1a\u201c\u5982\u4f55\u4f7f\u7528 python \u7ed8\u5236\u5177\u6709\u533a\u95f4\u8fb9\u754c\u7684\u6563\u70b9\u56fe\uff1f\u201d\u8fd9\u4e2a\u95ee\u9898\u4e2d\u7684\u6570\u636e\u5177\u6709\u4ee5\u4e0b\u683c\u5f0f\uff1a<\/p>\n<pre>a\uff1acore1, up1, down1, core2, up2, down2\nb\uff1acore1, up1, down1, core2, up2, down2\nc\uff1acore1, up1, down1, core2, up2, down2<\/pre>\n<p>\u8981\u7ed8\u5236\u8fd9\u4e9b\u6570\u636e\uff0c\u53ef\u4ee5\u4f7f\u7528 matplotlib \u5e93\uff0c\u5b83\u662f\u4e00\u4e2a\u7528\u4e8e\u521b\u5efa\u5404\u79cd\u7c7b\u578b\u7684\u56fe\u5f62\u7684\u5f3a\u5927\u5de5\u5177\u3002\u4ee5\u4e0b\u662f\u5b9e\u73b0\u6b64\u76ee\u6807\u7684\u4e00\u6b65\u6b65\u8bf4\u660e\uff1a<\/p>\n<ol>\n<li><strong>\u5bfc\u5165\u5fc5\u8981\u7684\u5e93<\/strong><\/li>\n<\/ol>\n<pre>import matplotlib.pyplot as plt\nimport numpy as np<\/pre>\n<ol>\n<li><strong>\u521b\u5efa\u753b\u5e03\u548c\u5b50\u56fe<\/strong><\/li>\n<\/ol>\n<pre>fig, ax = plt.subplots(1, 2)  # 1 \u884c 2 \u5217\u7684\u753b\u5e03<\/pre>\n<ol>\n<li><strong>\u89e3\u6790\u6570\u636e<\/strong><\/li>\n<\/ol>\n<pre>data = {\n    \"a\": [1, 2, 3, 4, 5, 6],\n    \"b\": [2, 3, 4, 5, 6, 7],\n    \"c\": [3, 4, 5, 6, 7, 8]\n}\n\ncores = [\"core1\", \"core2\"]<\/pre>\n<ol>\n<li><strong>\u6839\u636e\u4e2d\u5fc3\u70b9\u548c\u9519\u8bef\u8303\u56f4\u7ed8\u5236\u7ebf\u6bb5<\/strong><\/li>\n<\/ol>\n<pre>for key in data.keys():\n    for i, core in enumerate(cores):\n        y = data[key]\n        up = data[key][i*3+1::2]\n        down = data[key][i*3+2::2]\n        ax[i].errorbar(key, y, yerr=[down, up], fmt='o', capsize=5, linewidth=1.5)<\/pre>\n<p>\u8bf7\u6ce8\u610f\uff0cfmt=&#8217;o&#8217; \u6307\u5b9a\u4f7f\u7528\u5706\u70b9\u7ed8\u5236\u6570\u636e\u70b9\u3002<\/p>\n<ol>\n<li><strong>\u8bbe\u7f6e\u5750\u6807\u8f74\u6807\u7b7e\u548c\u6807\u9898<\/strong><\/li>\n<\/ol>\n<pre>for i, axi in enumerate(ax):\n    axi.set_ylabel(\"value\")\n    axi.set_title(f\"core {i+1}\")<\/pre>\n<ol>\n<li><strong>\u663e\u793a\u56fe\u5f62<\/strong><\/li>\n<\/ol>\n<pre>plt.show()<\/pre>\n<p>\u901a\u8fc7\u9075\u5faa\u8fd9\u4e9b\u6b65\u9aa4\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 python \u521b\u5efa\u4e00\u4e2a\u5177\u6709\u4e2d\u5fc3\u70b9\u548c\u7f6e\u4fe1\u533a\u95f4\u7684\u6563\u70b9\u56fe\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u300a\u5982\u4f55\u7528 Python \u7ed8\u5236\u5e26\u6709\u533a\u95f4\u8fb9\u754c\u7684\u6563\u70b9\u56fe\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\u7528 Python \u7ed8\u5236\u5e26\u6709\u533a&#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-204682","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204682","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=204682"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204682\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=204682"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=204682"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=204682"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}