pyecharts雷达图
时间: 2023-09-25 22:10:02 浏览: 73
pyecharts是一个Python的可视化库,它支持多种类型的图表,包括雷达图(Radar Chart)。
下面是一个简单的示例代码,展示如何使用pyecharts创建雷达图:
```python
from pyecharts.charts import Radar
from pyecharts import options as opts
data = [
[55, 9, 56, 0.46, 18, 6, 1],
[25, 11, 21, 0.65, 34, 9, 2],
[56, 7, 63, 0.3, 14, 5, 3],
[33, 7, 29, 0.33, 16, 6, 4],
[42, 24, 44, 0.76, 40, 16, 5],
[82, 58, 90, 1.77, 68, 33, 6],
[74, 49, 77, 1.46, 48, 27, 7],
[78, 55, 80, 1.29, 59, 29, 8],
[267, 216, 280, 4.8, 108, 64, 9],
[185, 127, 216, 2.52, 61, 27, 10],
[39, 19, 38, 0.57, 31, 15, 11],
[41, 11, 40, 0.43, 21, 7, 12],
[64, 38, 74, 1.04, 46, 22, 13],
[108, 79, 120, 1.7, 75, 41, 14],
[108, 63, 116, 1.48, 44, 26, 15],
[33, 6, 29, 0.34, 13, 5, 16],
[94, 66, 110, 1.54, 62, 31, 17],
[186, 142, 192, 3.88, 93, 79, 18],
[57, 31, 54, 0.96, 32, 14, 19],
[22, 8, 17, 0.48, 23, 10, 20],
[39, 15, 36, 0.61, 29, 13, 21],
[94, 69, 114, 2.08, 73, 39, 22],
[99, 73, 110, 2.43, 76, 48, 23],
[31, 12, 30, 0.5, 32, 16, 24],
[42, 27, 43, 1, 53, 22, 25],
[154, 117, 157, 3.05, 92, 58, 26],
[234, 185, 230, 4.09, 123, 69, 27],
[160, 120, 186, 2.77, 91, 50, 28],
[134, 96, 165, 2.76, 83, 41, 29],
[52, 24, 60, 1.03, 50, 21, 30],
[46, 5, 49, 0.28, 10, 6, 31]
]
schema = [
{"name": "AQI", "max": 300, "min": 5},
{"name": "PM2.5", "max": 250, "min": 20},
{"name": "PM10", "max": 300, "min": 5},
{"name": "CO", "max": 5},
{"name": "NO2", "max": 200},
{"name": "SO2", "max": 100},
{"name": "等级", "max": 10, "min": 1}
]
radar_chart = (
Radar()
.add_schema(schema)
.add("北京", data, color="#f9713c")
.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
.set_global_opts(
legend_opts=opts.LegendOpts(is_show=False),
title_opts=opts.TitleOpts(title="北京空气质量雷达图"),
tooltip_opts=opts.TooltipOpts(trigger="axis", axis_pointer_type="cross"),
)
)
radar_chart.render("radar_chart.html")
```
在这个示例中,我们使用了一个包含空气质量数据的列表`data`和一个包含雷达图坐标轴的列表`schema`。然后,我们创建了一个Radar对象,使用`add_schema`方法添加雷达图坐标轴,使用`add`方法添加数据,最后使用`set_global_opts`方法设置全局参数。
运行这段代码,就可以使用pyecharts创建一个雷达图。
阅读全文