Pycharts其他类型图表

1
2
3
4
5
6
7
8
9
10
11
12
import os, re
import random
import numpy as np
import pandas as pd
from datetime import date, datetime, timedelta

from pyecharts.charts import Kline, Line, Bar, Grid,Map,Pie,Timeline,Geo
from pyecharts.commons.utils import JsCode
from pyecharts import options as opts
from pyecharts.globals import CurrentConfig, NotebookType,ThemeType,ChartType, SymbolType
from pyecharts.faker import Faker

其他种类图表的基本用法

折线图

  1. is_smooth = False,# 是否平滑曲线
  2. is_connect_nones = False, # 是否连接空数据
  3. is_step = False, # 是否展示为阶梯图
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
line = (Line()
.add_xaxis(Faker.choose())
.add_yaxis('B',Faker.values())
.add_yaxis('C',Faker.values())
.add_yaxis('D',Faker.values())
.set_series_opts(
markpoint_opts=opts.MarkPointOpts(
data=[
opts.MarkPointItem(type_="max", name="x轴最大",value_index=1)
]),
)
)

line.render_notebook()
line.render('1.html')
Awesome-pyecharts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
c = (Pie().add("",
[list(z) for z in zip(["古装", "其他"], [35, 65])],
center=["20%", "30%"],
radius=[50, 80],
# label_opts=new_label_opts(),
)
.add(
"",
[list(z) for z in zip(["动作", "其他"],[24, 76])],
center=["55%", "30%"],
radius=[50, 80],
# label_opts=new_label_opts(),
)
.add(
"",
[list(z) for z in zip(["爱情", "其他"],[10, 90])],
center=["20%", "70%"],
radius=[50, 80],
label_opts=opts.LabelOpts(is_show=True),
)
.add(
"",
[list(z) for z in zip(["惊悚", "其他"],[20, 80])],
center=["55%", "70%"],
radius=[50, 80],
label_opts=opts.LabelOpts(is_show=True),
)
.set_global_opts(
title_opts=opts.TitleOpts(title="Pie-多饼图基本示例"),
legend_opts=opts.LegendOpts(
type_="scroll",
pos_top="30%",
pos_left="70%",
orient="vertical"
),
)
)
c.render_notebook()
c.render('2.html')
Awesome-pyecharts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
c = (Pie()
.add(
"",
[list(z) for z in zip(Faker.choose(), Faker.values())],
radius=["40%", "75%"],
center=["35%", "50%"],
rosetype="radius",
label_opts=opts.LabelOpts(is_show=True),
)
.set_global_opts(
title_opts=opts.TitleOpts(
title="饼图-玫瑰图示例"))
)
c.render_notebook()
c.render('3.html')
Awesome-pyecharts
1
2
3
4
5
6
7
8
9
10
11
12
13
c = (Map()
.add(
"商家A",
[list(z) for z in zip(["杭州市", "宁波市", "舟山市", "台州市", "温州市", "丽水市", "金华市", "衢州市", "绍兴市", "湖州市", "嘉兴市"], Faker.values())], "浙江")
.set_global_opts(
title_opts=opts.TitleOpts(
title="Map浙江地图-Test"),
visualmap_opts=opts.VisualMapOpts()
)
)

c.render_notebook()
c.render('4.html')
Awesome-pyecharts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
attr = Faker.choose()
tl = Timeline()
for i in range(2015, 2022):
pie = (Pie()
.add(
"商家A",
[list(z) for z in zip(attr, Faker.values())],
center=["50%", "50%"], radius=["40%", "60%"],
)
.set_global_opts(title_opts=opts.TitleOpts(
"某商店{}年营业额".format(i)
)
)
)
tl.add(pie, "{}年".format(i))
tl.render_notebook()
tl.render('5.html')
Awesome-pyecharts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
c = (Bar()    
.add_xaxis(Faker.choose())
.add_yaxis("商家1", Faker.values(),
category_gap="50%")
.set_series_opts(
itemstyle_opts={
"normal": { "color": JsCode("""
new echarts.graphic.LinearGradient(0, 0, 0, 1, [{offset: 0, color: 'rgba(0, 244, 255, 1)' },
{offset: 1,color: 'rgba(0, 77, 167, 1)'}],
false
)
"""
),
"barBorderRadius": [50, 50, 50, 50],
"shadowColor": "rgb(0, 160, 221)",
}
}
)
.set_global_opts(
title_opts=opts.TitleOpts(
title="圆角直方图-渐变圆柱示例"
)
)
)
c.render_notebook()
c.render('6.html')
Awesome-pyecharts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
c = (Map()
.add(
"商家1",
[list(z) for z in zip(Faker.provinces, Faker.values())], "china")
.set_global_opts(
title_opts=opts.TitleOpts(
title="地图 + 颜色分段(连续型)"
),
visualmap_opts=opts.VisualMapOpts(
max_=150),
)
)
c.render_notebook()
c.render('7.html')
Awesome-pyecharts
1
2
3
4
5
6
7
8
9
10
11
12
13
c = (Map()    
.add(
"商家1",
[list(z) for z in zip(Faker.country, Faker.values())], "world"
)
.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
.set_global_opts(
title_opts=opts.TitleOpts(title="Pyecharts-世界地图"),
visualmap_opts=opts.VisualMapOpts(max_=200),
)
)
c.render_notebook()
c.render('8.html')
Awesome-pyecharts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
c = (Geo()    
.add_schema(
maptype="china",
itemstyle_opts=opts.ItemStyleOpts(color="#323c48", border_color="#111"),
)
.add(
"",
[list(z) for z in zip(Faker.provinces, Faker.values())],
type_=ChartType.EFFECT_SCATTER,
color="white",
)
.add(
"geo",
[("宁波", "南京"), ("宁波", "北京"), ("宁波", "兰州"), ("宁波", "拉萨"), ("宁波", "银川"), ("宁波", "武汉")],
type_=ChartType.LINES,
effect_opts=opts.EffectOpts(
symbol=SymbolType.ARROW,
symbol_size=6, color="blue"
),
linestyle_opts=opts.LineStyleOpts(curve=0.2),
)
.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
.set_global_opts(
title_opts=opts.TitleOpts(
title="Geo-Lines-background"
)
)
)
c.render_notebook()
c.render('9.html')
Awesome-pyecharts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
tl = Timeline()
for i in range(2015, 2022):
map0 = (Map()
.add(
"商家1",
[list(z) for z in zip(Faker.provinces, Faker.values())],
"china"
)
.set_global_opts(
title_opts=opts.TitleOpts(
title="{}年数据".format(i)
),
visualmap_opts=opts.VisualMapOpts(max_=200),
)
)
tl.add(map0, "{}年".format(i))
tl.render_notebook()
tl.render('10.html')
Awesome-pyecharts