课程:大数据可视化 实验室名称: 指导老师: 实训日期: 年 月 日 实训题目:Python数据可视化之Pyecharts 实训目的: 一、python的安装与基本使用 二、创建py项目 三、pyecharts模块的安装与介绍 四、在pyecharts官方网站查看快速入门文档 五、自行编写数据源 实现案例 雷达图 饼状图 K线图 实训内容:
from pyecharts import options as opts
from pyecharts.charts import Radar
value_bj = [
[267, 216, 280, 4.8, 108, 64],
[185, 127, 216, 2.52, 61, 27],
]
value_sh = [
[250, 200, 260, 3.82, 80, 40],
[200, 150, 200, 4.86, 50, 29],
]
c_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},
]
c = (
Radar()
.add_schema(schema=c_schema, shape="circle")
.add("北京", value_bj, color="#f9713c")
.add("上海", value_sh, color="#b3e4a1")
.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
.set_global_opts(title_opts=opts.TitleOpts(title="Radar-空气质量"))
.render("雷达图.html")
)
//导入柱状图-Bar
from pyecharts import Bar
//设置行名
columns = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
//设置数据
data1 = [2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3]
data2 = [2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3]
//设置柱状图的主标题与副标题
bar = Bar("柱状图", "一年的降水量与蒸发量")
//添加柱状图的数据及配置项
bar.add("降水量", columns, data1, mark_line=["average"], mark_point=["max", "min"])
bar.add("蒸发量", columns, data2, mark_line=["average"], mark_point=["max", "min"])
//生成本地文件(默认为.html文件)
bar.render(‘柱状图.html’)
import pyecharts.options as opts
from pyecharts.charts import Candlestick
x_data = ["2017-10-24", "2017-10-25", "2017-10-26", "2017-10-27"]
y_data = [[20, 30, 10, 35], [40, 35, 30, 55], [33, 38, 33, 40], [40, 40, 32, 42]]
(
Candlestick()
.add_xaxis(x_data)
.add_yaxis("",y_data)
.set_global_opts(
yaxis_opts=opts.AxisOpts(
splitline_opts=opts.SplitLineOpts(
is_show=True, linestyle_opts=opts.LineStyleOpts(width=1)
)
)
)
.render("K线图.html")
)
|