This article mainly refers to official documentation

Using the example

I strongly recommend taking a look at the source code for the example

Climb jingdong evaluation information and visualization

Install and view the version

Installation:

Source for Tsinghua source.

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyecharts
Copy the code

View version:

import pyecharts
print(pyecharts.__version__)
Copy the code

Guide package

The version used in this article is 1.7.1

The most common problem is direct import module failure, such as:

from pyecharts import Bar
Copy the code

Because of the extension module, this is required to import

from pyecharts.charts import Bar
Copy the code

Draw a bar chart

Create the chart and set the theme
bar = Bar(init_opts=opts.InitOpts(theme=ThemeType.LIGHT))
# add x value, x is a list
bar.add_xaxis(name)
# add y value, y is a list
bar.add_yaxis('Number of buyers',count)
Set the main title and subtitle
bar.set_global_opts(title_opts=opts.TitleOpts(title="Dior999 color distribution", subtitle="Data source: JINGdong"))
Set to generate HTML files
bar.render('bar.html')
Copy the code

The pie chart document

The document address

Draw a pie chart

from pyecharts.charts import Pie from pandas import Series import pandas as pd from pyecharts import options as opts Ss_colors = Series(colors) x = ss_colors.value_counts() list1= x.verus.tolist ()# number
list2=x.index.tolist()  # the name

c = (
    Pie()
    .add(
        "",
        [
            list(z)
            for z in zip(
                list2 ,
                list1 ,
            )
        ],
        center=["40%"."50%"],
    )
    .set_global_opts(
        title_opts=opts.TitleOpts(title="Color distribution"),
        legend_opts=opts.LegendOpts(type_="scroll", pos_left="80%", orient="vertical"),
    )
    .set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}"))
    .render("pie_scroll_legend.html"))Copy the code

Rich text pie chart

from pyecharts.charts import Pie
from pandas import Series
import pandas as pd
from pyecharts import options as opts

name,count =[],[]
data_jd = pd.read_csv('K: \ \ get_jd3 CSV')
data = data_jd.values.tolist()
for i in range(len(data)):
    now = data[i]
    name.append(now[0])
    count.append(now[1])

c = (
    Pie()
    .add(
        "",
        [list(z) for z in zip(name, count)],
        radius=["40%"."55%"],
        label_opts=opts.LabelOpts(
            position="outside",
            formatter="{a|{a}}{abg|}\n{hr|}\n {b|{b}: }{c} {per|{d}%} ",
            background_color="#eee",
            border_color="#aaa",
            border_width=1,
            border_radius=4,
            rich={
                "a": {"color": "# 999"."lineHeight": 22."align": "center"},
                "abg": {
                    "backgroundColor": "#e3e3e3"."width": "100%"."align": "right"."height": 22."borderRadius": [4.4.0.0],},"hr": {
                    "borderColor": "#aaa"."width": "100%"."borderWidth": 0.5."height": 0,},"b": {"fontSize": 16."lineHeight": 33},
                "per": {
                    "color": "#eee"."backgroundColor": "# 334455"."padding": [2.4]."borderRadius": 2,
                },
            },
        ),
    )
    .set_global_opts(title_opts=opts.TitleOpts(title=""))
    .render("pie_rich_label.html"))Copy the code

Draw a rose chart

from pyecharts.charts import Pie
from pandas import Series
import pandas as pd
from pyecharts import options as opts

name,count =[],[]
data_jd = pd.read_csv('K: \ \ get_jd3 CSV')
data = data_jd.values.tolist()
for i in range(len(data)):
    now = data[i]
    name.append(now[0])
    count.append(now[1])

c = (
    Pie()
    .add(
        "",
        [list(z) for z in zip(name, count)],
        radius=["30%"."75%"],
        center=["25%"."50%"],
        rosetype="radius",
        label_opts=opts.LabelOpts(is_show=False),
    )
    .set_global_opts(title_opts=opts.TitleOpts(title=""))
    .render("pie_rosetype.html"))Copy the code

Word cloud document

Word cloud document

Diamond word clouds

I didn’t see it as a diamond

import pyecharts.options as opts
from pyecharts.charts import WordCloud
import pandas as pd
from pyecharts.globals import SymbolType

data_jd = pd.read_csv('K: \ \ get_jd3 CSV')
data = data_jd.values.tolist()
c = (
    WordCloud()
    .add("", data, word_size_range=[20, 100], shape=SymbolType.DIAMOND)
    .set_global_opts(title_opts=opts.TitleOpts(title="WordCloud-shape-diamond"))
    .render("wordcloud_diamond.html"))Copy the code