pyecharts数值型变量的常用可视化方法

数值型变量

二维数值型变量相关性可视化——散点图

import pandas as pd 
import random
import  pyecharts.options as opts 
from pyecharts.charts import Scatter
x = range(15)                             #  适用数据结构
y = [random.randint(1, 30) for i in x ]
(
    Scatter(opts.InitOpts(
        width = '900px', height='500px'),
        )
    .add_xaxis(xaxis_data=x)
    .add_yaxis(series_name='随机生成数据',
               y_axis=y,
               is_selected=True,
               color='#4B0082')
    .set_global_opts(
        title_opts=opts.TitleOpts(title="散点图示例"),
        xaxis_opts=opts.AxisOpts(splitline_opts=opts.SplitLineOpts(is_show=True)),
        yaxis_opts=opts.AxisOpts(splitline_opts=opts.SplitLineOpts(is_show=True)),)
    .render("scatter_chart.html"))

在这里插入图片描述

数值型变量相关性展示——气泡图

from pyecharts.charts import Scatter 
x = range(15)                       #  适用数据结构
y = [random.choice(x) for i in x ]

(
    Scatter(opts.InitOpts(
        width = '900px', height='500px'))
    .add_xaxis(xaxis_data=x)
    .add_yaxis('气泡大小代表y值大小',
               y_axis=y,
               is_selected = True, 
               color = '#FFA07A')
    .set_global_opts(
        title_opts=opts.TitleOpts(title="气泡图示例"),
        visualmap_opts=opts.VisualMapOpts(type_="size", max_=15, min_=1),
    )
    .render('bubbel_chart.html')  
)

在这里插入图片描述

时间序列数据——折线图

from pyecharts.charts import Line # 导入Line类 
# 随机生成画图所需数据 
time = pd.date_range('2020.01.01', '2020.01.30')   #  适用数据结构
y = random.choices(list(range(10,50)),k=30) 
(
     Line(opts.InitOpts(          # 初始化配置
         width= '900px', height= '500px'),
          ) # line 初始化配置
     .add_xaxis(xaxis_data=time)  # 喂数据 
     .add_yaxis(series_name = '消费金额', 
                 y_axis = y,
                 is_selected =True, 
                 color = '#00FFFF' )
     .set_global_opts(            # 配置
        title_opts=opts.TitleOpts(title='一月份消费金额', subtitle="随机生成数据"),)
     .render("consumption_line_chart.html")
)

在这里插入图片描述

少项目多维数据对比——雷达图

from pyecharts.charts import Radar
x1 = [[4300, 10000, 28000, 35000, 50000, 19000]]    #  适用数据结构
x2 = [[5000, 14000, 28000, 31000, 42000, 21000]]
(
    Radar(init_opts=opts.InitOpts(width="1280px", height="720px", bg_color="#CCCCCC"))
    .add_schema(
        schema=[
            opts.RadarIndicatorItem(name="销售", max_=6500),
            opts.RadarIndicatorItem(name="管理", max_=16000),
            opts.RadarIndicatorItem(name="信息技术", max_=30000),
            opts.RadarIndicatorItem(name="客服", max_=38000),
            opts.RadarIndicatorItem(name="研发", max_=52000),
            opts.RadarIndicatorItem(name="市场", max_=25000),
        ],
        splitarea_opt=opts.SplitAreaOpts(
            is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)
        ),
        textstyle_opts=opts.TextStyleOpts(color="#fff"),
    )
    .add(
        series_name="预算分配",
        data=x1,
        linestyle_opts=opts.LineStyleOpts(color="#CD0000"),
    )
    .add(
        series_name="实际开销",
        data=x2,
        linestyle_opts=opts.LineStyleOpts(color="black"),
    )
    .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
    .set_global_opts(
        title_opts=opts.TitleOpts(title="基础雷达图示例",subtitle='模拟数据'), 
        legend_opts=opts.LegendOpts()
    )
    .render("radar_chart.html")
)

在这里插入图片描述

多个数值型变量离散程度对比——箱线图

from pyecharts.charts import Boxplot
y =[ [random.gauss(i,1) for j in range(1000)] for i in range(4)]  
(
    Boxplot(init_opts=opts.InitOpts(
        width="900px", height="500px"))
    .add_xaxis(xaxis_data = ["mu=1", 'mu=2', "mu=3", "mu=4"])
    .add_yaxis('高斯分布', y_axis = Boxplot.prepare_data(y))
    .set_global_opts(
        title_opts=opts.TitleOpts(
        title="箱线图示例",subtitle = '模拟数据'),
        tooltip_opts=opts.TooltipOpts(trigger="item", axis_pointer_type="shadow"),
        xaxis_opts=opts.AxisOpts(splitline_opts=opts.SplitLineOpts(is_show=True)),
        yaxis_opts=opts.AxisOpts(splitline_opts=opts.SplitLineOpts(is_show=True)),) 
    .render("boxplot_chart.html")
 )

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_43705953/article/details/109024496