{"id":986246,"date":"2024-12-27T07:43:14","date_gmt":"2024-12-26T23:43:14","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/986246.html"},"modified":"2024-12-27T07:43:17","modified_gmt":"2024-12-26T23:43:17","slug":"python%e4%b8%adpyecharts%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/986246.html","title":{"rendered":"python\u4e2dpyecharts\u5982\u4f55\u4f7f\u7528"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25062914\/34631ab2-26c8-4285-82af-3cf15fc4f74b.webp\" alt=\"python\u4e2dpyecharts\u5982\u4f55\u4f7f\u7528\" \/><\/p>\n<p><h3>PYTHON\u4e2dPYECHARTS\u7684\u4f7f\u7528\u65b9\u6cd5<\/h3>\n<\/p>\n<p><p><strong>Pyecharts\u662f\u4e00\u4e2a\u7528\u4e8e\u751f\u6210ECharts\u56fe\u8868\u7684Python\u5e93\uff0c\u5177\u6709\u76f4\u89c2\u3001\u6613\u7528\u3001\u529f\u80fd\u5f3a\u5927\u7b49\u7279\u70b9\u3002\u8981\u5728Python\u4e2d\u4f7f\u7528Pyecharts\uff0c\u4f60\u9700\u8981\u5b89\u88c5\u5e93\u3001\u521b\u5efa\u56fe\u8868\u5bf9\u8c61\u3001\u8fdb\u884c\u6570\u636e\u7ed1\u5b9a\u3001\u4e2a\u6027\u5316\u8bbe\u7f6e\u4ee5\u53ca\u5c06\u56fe\u8868\u6e32\u67d3\u8f93\u51fa\u3002<\/strong>\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u63a2\u8ba8\u5982\u4f55\u5728Python\u73af\u5883\u4e2d\u4f7f\u7528Pyecharts\u6765\u521b\u5efa\u5404\u7c7b\u56fe\u8868\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u5b89\u88c5\u4e0e\u5165\u95e8<\/h3>\n<\/p>\n<p><p>\u5728\u5f00\u59cb\u4f7f\u7528Pyecharts\u4e4b\u524d\uff0c\u4f60\u9700\u8981\u786e\u4fdd\u5df2\u5b89\u88c5\u8be5\u5e93\u3002\u53ef\u4ee5\u901a\u8fc7pip\u547d\u4ee4\u8f7b\u677e\u5b8c\u6210\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">pip install pyecharts<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u5bfc\u5165Pyecharts\u5e93\u6765\u5f00\u59cb\u4f60\u7684\u56fe\u8868\u521b\u5efa\u4e4b\u65c5\u3002Pyecharts\u652f\u6301\u591a\u79cd\u7c7b\u578b\u7684\u56fe\u8868\uff0c\u5305\u62ec\u6298\u7ebf\u56fe\u3001\u67f1\u72b6\u56fe\u3001\u997c\u56fe\u3001\u5730\u56fe\u7b49\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u521b\u5efa\u57fa\u7840\u56fe\u8868<\/h3>\n<\/p>\n<p><h4>1. \u521b\u5efa\u6298\u7ebf\u56fe<\/h4>\n<\/p>\n<p><p>\u6298\u7ebf\u56fe\u662fPyecharts\u4e2d\u6700\u57fa\u672c\u7684\u56fe\u8868\u4e4b\u4e00\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684\u6298\u7ebf\u56fe\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from pyecharts.charts import Line<\/p>\n<p>from pyecharts import options as opts<\/p>\n<p>line = Line()<\/p>\n<p>line.add_xaxis([&quot;Monday&quot;, &quot;Tuesday&quot;, &quot;Wednesday&quot;, &quot;Thursday&quot;, &quot;Friday&quot;, &quot;Saturday&quot;, &quot;Sunday&quot;])<\/p>\n<p>line.add_yaxis(&quot;Sales&quot;, [120, 200, 150, 80, 70, 110, 130])<\/p>\n<p>line.set_global_opts(title_opts=opts.TitleOpts(title=&quot;Weekly Sales&quot;))<\/p>\n<p>line.render(&quot;line_chart.html&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u8868\u793a\u6bcf\u5468\u9500\u552e\u989d\u7684\u6298\u7ebf\u56fe\uff0c\u5e76\u5c06\u5176\u6e32\u67d3\u4e3aHTML\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><h4>2. \u521b\u5efa\u67f1\u72b6\u56fe<\/h4>\n<\/p>\n<p><p>\u67f1\u72b6\u56fe\u662f\u53e6\u4e00\u79cd\u5e38\u7528\u7684\u56fe\u8868\u7c7b\u578b\uff0c\u9002\u7528\u4e8e\u5c55\u793a\u5206\u7c7b\u6570\u636e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from pyecharts.charts import Bar<\/p>\n<p>bar = Bar()<\/p>\n<p>bar.add_xaxis([&quot;Apples&quot;, &quot;Bananas&quot;, &quot;Cherries&quot;])<\/p>\n<p>bar.add_yaxis(&quot;Quantity&quot;, [5, 20, 36])<\/p>\n<p>bar.set_global_opts(title_opts=opts.TitleOpts(title=&quot;Fruit Sales&quot;))<\/p>\n<p>bar.render(&quot;bar_chart.html&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e2a\u793a\u4f8b\u5c55\u793a\u4e86\u4e0d\u540c\u6c34\u679c\u7684\u9500\u552e\u6570\u91cf\uff0c\u5e76\u5c06\u7ed3\u679c\u4fdd\u5b58\u4e3a\u4e00\u4e2aHTML\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u6570\u636e\u7ed1\u5b9a\u4e0e\u4e2a\u6027\u5316\u8bbe\u7f6e<\/h3>\n<\/p>\n<p><h4>1. \u6570\u636e\u7ed1\u5b9a<\/h4>\n<\/p>\n<p><p>\u5728Pyecharts\u4e2d\uff0c\u6570\u636e\u7ed1\u5b9a\u662f\u901a\u8fc7<code>add_xaxis<\/code>\u548c<code>add_yaxis<\/code>\u65b9\u6cd5\u5b8c\u6210\u7684\u3002\u8fd9\u4e9b\u65b9\u6cd5\u5141\u8bb8\u4f60\u4e3a\u56fe\u8868\u6dfb\u52a0X\u8f74\u548cY\u8f74\u7684\u6570\u636e\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u5217\u8868\u6216\u5176\u4ed6\u53ef\u8fed\u4ee3\u5bf9\u8c61\u6765\u63d0\u4f9b\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h4>2. \u4e2a\u6027\u5316\u8bbe\u7f6e<\/h4>\n<\/p>\n<p><p>Pyecharts\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u4e2a\u6027\u5316\u9009\u9879\uff0c\u901a\u8fc7<code>set_global_opts<\/code>\u548c<code>set_series_opts<\/code>\u7b49\u65b9\u6cd5\u53ef\u4ee5\u8bbe\u7f6e\u56fe\u8868\u7684\u5916\u89c2\u548c\u884c\u4e3a\u3002\u4f8b\u5982\uff0c\u4f60\u53ef\u4ee5\u8bbe\u7f6e\u56fe\u8868\u7684\u6807\u9898\u3001\u989c\u8272\u3001\u56fe\u4f8b\u3001\u5750\u6807\u8f74\u7b49\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">line.set_global_opts(<\/p>\n<p>    title_opts=opts.TitleOpts(title=&quot;Sales Line Chart&quot;, subtitle=&quot;2023&quot;),<\/p>\n<p>    legend_opts=opts.LegendOpts(is_show=True),<\/p>\n<p>    xaxis_opts=opts.AxisOpts(name=&quot;Days&quot;),<\/p>\n<p>    yaxis_opts=opts.AxisOpts(name=&quot;Sales Amount&quot;)<\/p>\n<p>)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u521b\u5efa\u9ad8\u7ea7\u56fe\u8868<\/h3>\n<\/p>\n<p><h4>1. \u997c\u56fe<\/h4>\n<\/p>\n<p><p>\u997c\u56fe\u9002\u5408\u5c55\u793a\u5206\u7c7b\u6570\u636e\u7684\u6bd4\u4f8b\u5206\u5e03\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u521b\u5efa\u997c\u56fe\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from pyecharts.charts import Pie<\/p>\n<p>pie = Pie()<\/p>\n<p>pie.add(&quot;&quot;, [list(z) for z in zip([&quot;Apples&quot;, &quot;Bananas&quot;, &quot;Cherries&quot;], [5, 20, 36])])<\/p>\n<p>pie.set_global_opts(title_opts=opts.TitleOpts(title=&quot;Fruit Proportion&quot;))<\/p>\n<p>pie.render(&quot;pie_chart.html&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u5730\u56fe<\/h4>\n<\/p>\n<p><p>Pyecharts\u8fd8\u652f\u6301\u521b\u5efa\u5730\u56fe\uff0c\u8fd9\u5bf9\u4e8e\u5730\u7406\u6570\u636e\u7684\u53ef\u89c6\u5316\u975e\u5e38\u6709\u7528\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from pyecharts.charts import Map<\/p>\n<p>map = Map()<\/p>\n<p>map.add(&quot;Sales&quot;, [(&quot;Guangdong&quot;, 100), (&quot;Beijing&quot;, 200), (&quot;Shangh<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>&quot;, 300)], &quot;china&quot;)<\/p>\n<p>map.set_global_opts(title_opts=opts.TitleOpts(title=&quot;Sales Distribution&quot;))<\/p>\n<p>map.render(&quot;map_chart.html&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u4ea4\u4e92\u4e0e\u8f93\u51fa<\/h3>\n<\/p>\n<p><h4>1. \u4ea4\u4e92\u529f\u80fd<\/h4>\n<\/p>\n<p><p>Pyecharts\u652f\u6301\u591a\u79cd\u4ea4\u4e92\u529f\u80fd\uff0c\u5982\u5de5\u5177\u63d0\u793a\u3001\u7f29\u653e\u3001\u6570\u636e\u7b5b\u9009\u7b49\u3002\u8fd9\u4e9b\u529f\u80fd\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u9009\u9879\u8f7b\u677e\u5b9e\u73b0\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">line.set_series_opts(<\/p>\n<p>    label_opts=opts.LabelOpts(is_show=False),<\/p>\n<p>    tooltip_opts=opts.TooltipOpts(trigger=&quot;axis&quot;)<\/p>\n<p>)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u8f93\u51fa\u4e0e\u5206\u4eab<\/h4>\n<\/p>\n<p><p>Pyecharts\u751f\u6210\u7684\u56fe\u8868\u9ed8\u8ba4\u4ee5HTML\u683c\u5f0f\u8f93\u51fa\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u6d4f\u89c8\u5668\u67e5\u770b\u3002\u9664\u6b64\u4e4b\u5916\uff0cPyecharts\u8fd8\u652f\u6301\u5c06\u56fe\u8868\u4fdd\u5b58\u4e3a\u56fe\u7247\u6216\u5bfc\u51fa\u5230PDF\u7b49\u683c\u5f0f\uff0c\u65b9\u4fbf\u5206\u4eab\u548c\u5c55\u793a\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">line.render(&quot;line_chart.html&quot;)<\/p>\n<p>line.render_notebook()  # \u5728Jupyter Notebook\u4e2d\u8f93\u51fa<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516d\u3001\u603b\u7ed3\u4e0e\u6269\u5c55<\/h3>\n<\/p>\n<p><p>Pyecharts\u4e3aPython\u7528\u6237\u63d0\u4f9b\u4e86\u4e00\u79cd\u5f3a\u5927\u800c\u7075\u6d3b\u7684\u65b9\u5f0f\u6765\u521b\u5efa\u5404\u79cd\u4ea4\u4e92\u5f0f\u56fe\u8868\u3002\u901a\u8fc7\u672c\u6587\u7684\u4ecb\u7ecd\uff0c\u4f60\u5e94\u8be5\u80fd\u591f\u638c\u63e1Pyecharts\u7684\u57fa\u672c\u4f7f\u7528\u65b9\u6cd5\uff0c\u5e76\u5229\u7528\u5176\u4e30\u5bcc\u7684\u529f\u80fd\u8fdb\u884c\u6570\u636e\u53ef\u89c6\u5316\u3002\u5728\u5b9e\u8df5\u4e2d\uff0c\u4f60\u53ef\u4ee5\u5c1d\u8bd5\u7ed3\u5408\u5176\u4ed6Python\u6570\u636e\u5206\u6790\u5de5\u5177\uff08\u5982Pandas\u548cNumPy\uff09\u6765\u8fdb\u4e00\u6b65\u6269\u5c55Pyecharts\u7684\u5e94\u7528\u573a\u666f\u3002\u65e0\u8bba\u662f\u4e2a\u4eba\u9879\u76ee\u8fd8\u662f\u4f01\u4e1a\u7ea7\u5e94\u7528\uff0cPyecharts\u90fd\u80fd\u4e3a\u4f60\u7684\u6570\u636e\u53ef\u89c6\u5316\u9700\u6c42\u63d0\u4f9b\u6709\u529b\u652f\u6301\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u5b89\u88c5pyecharts\u5e93\uff1f<\/strong><br \/>\u8981\u4f7f\u7528pyecharts\uff0c\u9996\u5148\u9700\u8981\u5728\u4f60\u7684Python\u73af\u5883\u4e2d\u5b89\u88c5\u5b83\u3002\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528pip\u547d\u4ee4\u6765\u5b89\u88c5\u3002\u5728\u7ec8\u7aef\u6216\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a<code>pip install pyecharts<\/code>\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u5728\u4f60\u7684Python\u811a\u672c\u4e2d\u5bfc\u5165pyecharts\u6a21\u5757\u8fdb\u884c\u4f7f\u7528\u3002<\/p>\n<p><strong>pyecharts\u652f\u6301\u54ea\u4e9b\u7c7b\u578b\u7684\u56fe\u8868\uff1f<\/strong><br \/>pyecharts\u652f\u6301\u591a\u79cd\u7c7b\u578b\u7684\u56fe\u8868\uff0c\u5305\u62ec\u6298\u7ebf\u56fe\u3001\u67f1\u72b6\u56fe\u3001\u997c\u56fe\u3001\u6563\u70b9\u56fe\u3001\u5730\u56fe\u3001\u96f7\u8fbe\u56fe\u7b49\u3002\u6bcf\u79cd\u56fe\u8868\u90fd\u6709\u5176\u7279\u5b9a\u7684\u4f7f\u7528\u573a\u666f\uff0c\u7528\u6237\u53ef\u4ee5\u6839\u636e\u6570\u636e\u7684\u7279\u70b9\u548c\u5c55\u793a\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u56fe\u8868\u7c7b\u578b\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728pyecharts\u4e2d\u81ea\u5b9a\u4e49\u56fe\u8868\u7684\u6837\u5f0f\uff1f<\/strong><br \/>pyecharts\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u81ea\u5b9a\u4e49\u9009\u9879\uff0c\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u56fe\u8868\u7684\u6807\u9898\u3001\u989c\u8272\u3001\u6807\u7b7e\u3001\u5750\u6807\u8f74\u7b49\u5c5e\u6027\u6765\u8c03\u6574\u56fe\u8868\u7684\u6837\u5f0f\u3002\u7528\u6237\u53ef\u4ee5\u4f7f\u7528<code>set_global_opts()<\/code>\u65b9\u6cd5\u6765\u8bbe\u7f6e\u5168\u5c40\u9009\u9879\uff0c\u4f7f\u7528\u5404\u7c7b\u56fe\u8868\u5bf9\u8c61\u7684\u65b9\u6cd5\u6765\u8c03\u6574\u7279\u5b9a\u5c5e\u6027\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u901a\u8fc7<code>set_series_opts()<\/code>\u6765\u4fee\u6539\u7cfb\u5217\u7684\u6837\u5f0f\uff0c\u6216\u8005\u4f7f\u7528<code>set_title()<\/code>\u6765\u66f4\u6539\u56fe\u8868\u6807\u9898\u3002<\/p>\n<p><strong>pyecharts\u751f\u6210\u7684\u56fe\u8868\u5982\u4f55\u4fdd\u5b58\u4e3a\u56fe\u7247\u6587\u4ef6\uff1f<\/strong><br \/>\u4f7f\u7528pyecharts\u751f\u6210\u7684\u56fe\u8868\u53ef\u4ee5\u65b9\u4fbf\u5730\u4fdd\u5b58\u4e3a\u56fe\u7247\u6587\u4ef6\u3002\u53ef\u4ee5\u4f7f\u7528<code>render()<\/code>\u65b9\u6cd5\u5c06\u56fe\u8868\u6e32\u67d3\u4e3aHTML\u6587\u4ef6\uff0c\u6216\u8005\u4f7f\u7528<code>render_image()<\/code>\u65b9\u6cd5\u76f4\u63a5\u8f93\u51fa\u4e3aPNG\u6216JPEG\u683c\u5f0f\u7684\u56fe\u7247\u3002\u786e\u4fdd\u5728\u4f7f\u7528\u8fd9\u4e9b\u529f\u80fd\u65f6\uff0c\u76f8\u5173\u7684\u56fe\u5f62\u5e93\uff08\u5982<code>pillow<\/code>\uff09\u5df2\u6b63\u786e\u5b89\u88c5\uff0c\u4ee5\u652f\u6301\u56fe\u50cf\u7684\u751f\u6210\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"PYTHON\u4e2dPYECHARTS\u7684\u4f7f\u7528\u65b9\u6cd5 Pyecharts\u662f\u4e00\u4e2a\u7528\u4e8e\u751f\u6210ECharts\u56fe\u8868\u7684Python\u5e93 [&hellip;]","protected":false},"author":3,"featured_media":986253,"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\/986246"}],"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=986246"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/986246\/revisions"}],"predecessor-version":[{"id":986254,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/986246\/revisions\/986254"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/986253"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=986246"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=986246"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=986246"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}