版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
pyecharts雷达图
雷达图一般用于比赛评价分析
注意
schema有几个indicator指示器就会默认取前几个数值,
单例模式只能显示一组数据
首先导入本章通用的雷达图模块
from pyecharts import options as opts
from pyecharts.charts import Radar
# 例1 基本示例
v1=[[120,112,45,50,70,90,20,30]]
v2=[[80,90,120,50,60,85,5,15]]
radar1=(
Radar()
.add_schema(# 添加schema架构
schema=[
opts.RadarIndicatorItem(name='ability1',max_=150),# 设置指示器名称和最大值
opts.RadarIndicatorItem(name='ability2',max_=150),
opts.RadarIndicatorItem(name='ability3',max_=150),
opts.RadarIndicatorItem(name='ability4',max_=100),
opts.RadarIndicatorItem(name='ability5',max_=100),
opts.RadarIndicatorItem(name='ability6',max_=100),
]
)
.add('budget',v1)# 添加一条数据,参数1为数据名,参数2为数据
.add('fact',v2) # schema有几个indicator指示器就会默认取前几个数值
.set_global_opts(title_opts=opts.TitleOpts(title='radar 基本示例'),)
)
radar1.render('echarts-radar.html')
# 例2 单例模式
v1=[[120,112,45,50,70,90]]
v2=[[80,90,120,50,60,85]]
v3=[[110,60,20,70,40,55]]
radar2=(
Radar()
.add_schema(# 添加schema架构
schema=[
opts.RadarIndicatorItem(name='ability1',max_=150),
opts.RadarIndicatorItem(name='ability2',max_=150),
opts.RadarIndicatorItem(name='ability3',max_=150),
opts.RadarIndicatorItem(name='ability4',max_=100),
opts.RadarIndicatorItem(name='ability5',max_=100),
opts.RadarIndicatorItem(name='ability6',max_=100),
]
)
.add('budget',v1)
.add('fact',v2)
.add('plus',v2)
.set_global_opts(title_opts=opts.TitleOpts(title='radar 基本示例'),
legend_opts=opts.LegendOpts(selected_mode='single'))# 通过legend设置单例模式
)
radar2.render('echarts-radar.html')
单例模式中不管怎么点都只能显示一组数据,就像单选框一样
# 例3 圆形模式
radar3=(
Radar()
.add_schema(
schema=[
opts.RadarIndicatorItem(name='ability1',max_=150),
opts.RadarIndicatorItem(name='ability2',max_=150),
opts.RadarIndicatorItem(name='ability3',max_=150),
opts.RadarIndicatorItem(name='ability4',max_=100),
opts.RadarIndicatorItem(name='ability5',max_=100),
opts.RadarIndicatorItem(name='ability6',max_=100),
],
shape='circle' # 设置雷达图类型圆形
)
.add('budget',v1)
.add('fact',v2)
.set_global_opts(title_opts=opts.TitleOpts(title='radar 圆形模式示例'),)
)
radar3.render('echarts-radar.html')
雷达图参数参考
def add(
# 系列名称,用于 tooltip 的显示,legend 的图例筛选。
series_name: str,
# 系列数据项
data: Sequence,
# 是否选中图例
is_selected: bool = True,
# ECharts 提供的标记类型包括 'circle', 'rect', 'roundRect', 'triangle',
# 'diamond', 'pin', 'arrow', 'none'
# 可以通过 'image://url' 设置为图片,其中 URL 为图片的链接,或者 dataURI。
symbol: Optional[str] = None,
# 系列 label 颜色
color: Optional[str] = None,
# 标签配置项,参考 `series_options.LabelOpts`
label_opts: opts.LabelOpts = opts.LabelOpts(),
# 线样式配置项,参考 `series_options.LineStyleOpts`
linestyle_opts: opts.LineStyleOpts = opts.LineStyleOpts(),
# 区域填充样式配置项,参考 `series_options.AreaStyleOpts`
areastyle_opts: opts.AreaStyleOpts = opts.AreaStyleOpts(),
# 提示框组件配置项,参考 `series_options.TooltipOpts`
tooltip_opts: Union[opts.TooltipOpts, dict, None] = None,
)
class RadarIndicatorItem(
# 指示器名称。
name: Optional[str] = None,
# 指示器的最大值,可选,建议设置
min_: Optional[Numeric] = None,
# 指示器的最小值,可选,默认为 0。
max_: Optional[Numeric] = None,
# 标签特定的颜色。
color: Optional[str] = None,
)