\u6570\u636e\u53ef\u5728\u7ebf\u83b7\u5f97\uff0c\u5e76\u53ef\u4f7f\u7528 Pandas \u5bfc\u5165\uff1a <\/p>\n
\r\nimport pandas as pd\r\ndf = pd.read_csv('https:\/\/anvil.works\/blog\/img\/plotting-in-python\/uk-election-results.csv')<\/pre>\n\u73b0\u5728\u6211\u4eec\u5df2\u7ecf\u51c6\u5907\u597d\u4e86\u3002\u5728\u672c\u7cfb\u5217\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5df2\u7ecf\u770b\u5230\u4e86\u4e00\u4e9b\u4ee4\u4eba\u5370\u8c61\u6df1\u523b\u7684\u7b80\u5355 API\uff0c\u4f46\u662f Pandas \u4e00\u5b9a\u80fd\u593a\u51a0\u3002<\/p>\n
\u8981\u5728 x \u8f74\u4e0a\u7ed8\u5236\u6309\u5e74\u4efd\u548c\u6bcf\u4e2a\u515a\u6d3e\u5206\u7ec4\u7684\u67f1\u72b6\u56fe\uff0c\u6211\u53ea\u9700\u8981\u8fd9\u6837\u505a\uff1a<\/p>\n
\r\nimport matplotlib.pyplot as plt\r\nax = df.plot.bar(x='year')\r\nplt.show()<\/pre>\n\u53ea\u6709\u56db\u884c\uff0c\u8fd9\u7edd\u5bf9\u662f\u6211\u4eec\u5728\u672c\u7cfb\u5217\u4e2d\u521b\u5efa\u7684\u6700\u68d2\u7684\u591a\u6761\u5f62\u67f1\u72b6\u56fe\u3002<\/p>\n
\u6211\u4ee5\u5bbd\u683c\u5f0f\u4f7f\u7528\u6570\u636e\uff0c\u8fd9\u610f\u5473\u7740\u6bcf\u4e2a\u515a\u6d3e\u90fd\u6709\u4e00\u5217\uff1a<\/p>\n
\r\n year conservative labour liberal others\r\n0 1966 253 364 12 1\r\n1 1970 330 287 6 7\r\n2 Feb 1974 297 301 14 18\r\n.. ... ... ... ... ...\r\n12 2015 330 232 8 80\r\n13 2017 317 262 12 59\r\n14 2019 365 202 11 72<\/pre>\n\u8fd9\u610f\u5473\u7740 Pandas \u4f1a\u81ea\u52a8\u77e5\u9053\u6211\u5e0c\u671b\u5982\u4f55\u5206\u7ec4\uff0c\u5982\u679c\u6211\u5e0c\u671b\u8fdb\u884c\u4e0d\u540c\u7684\u5206\u7ec4\uff0cPandas \u53ef\u4ee5\u5f88\u5bb9\u6613\u5730\u91cd\u7ec4 DataFrame\u3002<\/p>\n
\u4e0e Seaborn \u4e00\u6837\uff0cPandas \u7684\u7ed8\u56fe\u529f\u80fd\u662f Matplotlib \u4e4b\u4e0a\u7684\u62bd\u8c61\uff0c\u8fd9\u5c31\u662f\u4e3a\u4ec0\u4e48\u8981\u8c03\u7528 Matplotlib \u7684 plt.show() \u51fd\u6570\u6765\u5b9e\u9645\u751f\u6210\u7ed8\u56fe\u7684\u539f\u56e0\u3002<\/p>\n
\u770b\u8d77\u6765\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n
<\/p>\n
\u8c03\u6574\u6837\u5f0f<\/strong><\/span><\/div>\n\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u8bbf\u95ee\u5e95\u5c42\u7684 Matplotlib \u65b9\u6cd5\u8f7b\u677e\u5730\u8c03\u6574\u6837\u5f0f\u3002<\/p>\n
\u9996\u5148\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u5c06 Matplotlib \u989c\u8272\u8868\u4f20\u9012\u5230\u7ed8\u56fe\u51fd\u6570\u6765\u4e3a\u67f1\u72b6\u56fe\u7740\u8272\uff1a<\/p>\n
\r\nfrom matplotlib.colors import ListedColormap\r\ncmap = ListedColormap(['#0343df', '#e50000', '#ffff14', '#929591'])\r\nax = df.plot.bar(x='year', colormap=cmap)<\/pre>\n\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u7ed8\u56fe\u51fd\u6570\u7684\u8fd4\u56de\u503c\u8bbe\u7f6e\u5750\u6807\u8f74\u6807\u7b7e\u548c\u6807\u9898\uff0c\u5b83\u53ea\u662f\u4e00\u4e2a Matplotlib \u7684 Axis \u5bf9\u8c61\u3002 <\/p>\n
\r\nax.set_xlabel(None)\r\nax.set_ylabel('Seats')\r\nax.set_title('UK election results')<\/pre>\n\u8fd9\u662f\u73b0\u5728\u7684\u6837\u5b50\uff1a<\/p>\n
<\/p>\n
\u8fd9\u4e0e\u4e0a\u9762\u7684 Matplotlib \u7248\u672c\u51e0\u4e4e\u76f8\u540c\uff0c\u4f46\u662f\u53ea\u7528\u4e86 8 \u884c\u4ee3\u7801\u800c\u4e0d\u662f 16 \u884c\uff01\u6211\u5185\u5fc3\u7684\u4ee3\u7801\u9ad8\u624b\u975e\u5e38\u9ad8\u5174\u3002 <\/p>\n
\u62bd\u8c61\u5fc5\u987b\u662f\u53ef\u8f6c\u4e49\u7684<\/strong><\/span><\/div>\n\u4e0e Seaborn \u4e00\u6837\uff0c\u5411\u4e0b\u8bbf\u95ee Matplotlib API \u8fdb\u884c\u7ec6\u8282\u8c03\u6574\u7684\u80fd\u529b\u786e\u5b9e\u5f88\u6709\u5e2e\u52a9\u3002\u8fd9\u662f\u7ed9\u51fa\u62bd\u8c61\u7d27\u6025\u51fa\u53e3\u4f7f\u5176\u65e2\u5f3a\u5927\u53c8\u7b80\u5355\u7684\u4e00\u4e2a\u5f88\u597d\u7684\u4f8b\u5b50\u3002<\/p>\n
via: https:\/\/opensource.com\/article\/20\/6\/pandas-python<\/p>\n
\u4f5c\u8005\uff1aShaun Taylor-Morgan \u9009\u9898\uff1alujun9972 \u8bd1\u8005\uff1ageekpi \u6821\u5bf9\uff1awxy<\/p>\n
\u672c\u6587\u7531 LCTT \u539f\u521b\u7f16\u8bd1\uff0cLinux\u4e2d\u56fd \u8363\u8a89\u63a8\u51fa<\/p>\n","protected":false},"excerpt":{"rendered":"
\u5728\u6709\u5173\u57fa\u4e8e Python \u7684\u7ed8\u56fe\u5e93\u7684\u7cfb\u5217\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5c06\u5bf9\u4f7f\u7528 Pandas \u8fd9\u4e2a\u975e\u5e38\u6d41\u884c\u7684 Python \u6570\u636e […]<\/p>\n","protected":false},"author":317,"featured_media":170268,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-194352","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/194352","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/317"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=194352"}],"version-history":[{"count":1,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/194352\/revisions"}],"predecessor-version":[{"id":194356,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/194352\/revisions\/194356"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/170268"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=194352"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=194352"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=194352"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}