代码如下:
# 1、导入需要用到的图表类和模块
from pyecharts import options as opts
from pyecharts.charts import Radar
from pyecharts.globals import ThemeType
# 2、准备数据
data = [[33, 45, 3, 9, 6, 4]]# 必须是二维数组,否则会集中一个指示器显示
c_schema = [
{"name": "化学药", "max": 0, "min": 45},
{"name": "中成药", "max": 0, "min": 45},
{"name": "生物制品", "max": 0, "min": 45},
{"name": "医疗器械", "max": 0, "min": 45},
{"name": "中药饮片", "max": 0, "min": 45},
{"name": "保健品", "max": 0, "min": 45},
]
# 3、绘制雷达图实例
radar = (
Radar(init_opts=opts.InitOpts(theme=ThemeType.VINTAGE))
.set_colors(["red"]) # 数据点颜色,填充区域也会改变
.add_schema(
schema=c_schema, # 雷达指示器配置项列表
shape="polygon", # 雷达图绘制类型,可选 'polygon' 和 'circle'
center=["50%", "50%"], # 雷达的中心(圆心)坐标,设置成百分比时第一项是相对于容器宽度,第二项是相对于容器高度
radius="80%", # 雷达的半径
angleaxis_opts=opts.AngleAxisOpts( # 极坐标系的角度轴
min_=0, # 坐标轴刻度标签最小值一般不显示
max_=360, # 坐标轴刻度标签最大值
interval=5, # 坐标轴分割间隔
axistick_opts=opts.AxisTickOpts(is_show=False), # 轴刻度
axislabel_opts=opts.LabelOpts(is_show=False), # 刻度标签
axisline_opts=opts.AxisLineOpts(is_show=False), # 坐标轴轴线
splitline_opts=opts.SplitLineOpts(is_show=False), # 坐标轴分隔线
),
radiusaxis_opts=opts.RadiusAxisOpts( # 极坐标系的径向轴
min_=0, # 设置坐标轴刻度的最小值
max_=45, # 设置坐标轴刻度的最大值
interval=20, # 坐标轴间隔值
splitarea_opts=opts.SplitAreaOpts( # 分割区域,可以装饰图形
is_show=True, # 显示分割区域
areastyle_opts=opts.AreaStyleOpts(color=["yellow","orange"], # 分割区域的颜色
opacity=0.3) # 透明度
),
),
polar_opts=opts.PolarOpts(),
splitarea_opt=opts.SplitAreaOpts(is_show=False), # 分隔区域配置项
splitline_opt=opts.SplitLineOpts(is_show=False), # 分割线配置项
)
.add(
series_name="全国药店药品销售额占比", # 数据名
data=data,
areastyle_opts=opts.AreaStyleOpts(opacity=0.5), # 区域填充样式配置项,透明度
linestyle_opts=opts.LineStyleOpts(width=1), # 线样式配置项,线宽
)
.set_global_opts(title_opts=opts.TitleOpts(title='全国药店药品销售额占比'))
)
# 4、渲染图表
radar.render_notebook()
运行效果图: