Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize data Visualization with pyecharts

Shulou Source: shulou.com Published: 2022-06-01 07:15:29 09月21日 Update

This article will explain in detail how pyecharts can realize data visualization. Xiaobian thinks it is quite practical, so share it with you for reference. I hope you can gain something after reading this article.

1. overview

Pyecharts is Baidu open source, suitable for data visualization tools, flexible configuration, relatively beautiful display charts, smooth.

2. installation

Installation in Python 3 environment:

pip3 install pyecharts3. Data visualization code 3.1 histogram from pyecharts import options as optsfrom pyecharts.charts import Barfrom pyecharts.faker import Faker c = ( Bar() .add_xaxis(Faker.choose()) .add_yaxis("Merchant A", Faker.values(), stack="stack1") .add_yaxis("Merchant B", Faker.values(), stack="stack1") .set_series_opts(label_opts=opts.LabelOpts(is_show=False)) .set_global_opts(title_opts=opts.TitleOpts(title="Bar-Stacked Data (All)")) .render("bar_stack0.html"))

Executing the above code will generate mycharts.html file in relative directory, which will be opened through page.

3.2 Line charts import pyecharts.options as optsfrom pyecharts.charts import Line ""Gallery use pyecharts 1.1.0 Reference: https://echarts.apache.org/examples/editor.html? c=line-smooth Currently unavailable function: None "" x_data = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]y_data = [820, 932, 901, 934, 1290, 1330, 1320] ( Line() .set_global_opts( tooltip_opts=opts.TooltipOpts(is_show=False), xaxis_opts=opts.AxisOpts(type_="category"), yaxis_opts=opts.AxisOpts( type_="value", axistick_opts=opts.AxisTickOpts(is_show=True), splitline_opts=opts.SplitLineOpts(is_show=True), ), ) .add_xaxis(xaxis_data=x_data) .add_yaxis( series_name="", y_axis=y_data, symbol="emptyCircle", is_symbol_show=True, is_smooth=True, label_opts=opts.LabelOpts(is_show=False), ) .render("smoothed_line_chart.html"))

3.3 pie chart from pyecharts import options as optsfrom pyecharts.charts import Piefrom pyecharts.faker import Faker c = ( Pie() .add( "", [list(z) for z in zip(Faker.choose(), Faker.values())], radius=["40%", "75%"], ) .set_global_opts( title_opts=opts.TitleOpts(title="Pie-Radius"), legend_opts=opts.LegendOpts(orient="vertical", pos_top="15%", pos_left="2%"), ) .set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}")) .render("pie_radius.html"))

About "pyecharts how to achieve data visualization" this article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it to let more people see.

Tags: Data visualization articles code merchants more references good practical beautiful content functions charts addresses tools files articles environment directories knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux MariaDB Huawei Xiaomi Redmi