peycharts数据可视化

 pyecharts的数据可视化各种图表的展示

 通过给定的数据来进行图表的绘画

由于pyecharts给定的教程较为简略,并且有时候还会有一些bug,需要对语句进行些变化才能得到想要的结果,以下是完整代码:

#添加背景图片
from pyecharts.components import Image
图片网址='https://i.postimg.cc/9fgCzhZX/2.png'
宽0='100%'
高0='100%'
def 背景图片(图片网址):
    图片=(
        Image()
        .add(图片网址,
            style_opts={"width":宽0,"height":高0})
    )
    图片.chart_id=0
    return 图片
背景图片(图片网址).render_notebook()



#主标题
import pyecharts.options as opts                                                                  # 调用图表配置选项库 
from pyecharts.charts import Pie                                                                  # 调用画图库

主标题名称数据 = "大数据管理与应用专业-学生数据可视化"                                                    # 设置数据

宽1='615px'                                                                                      # 设置图片宽度高度变量 
高1='40px'

def 主标题(主标题名称数据):                                                                          # 定义函数,便于可视化大屏调用

    标题 = (
        
        Pie(init_opts=opts.InitOpts(width=宽1, height=高1, chart_id=1))                           # 绘图,设置图片大小、图表id
        
        .set_global_opts(
            title_opts=opts.TitleOpts(
                            title=主标题名称数据,                                                   # 设置标题
                            title_textstyle_opts=opts.TextStyleOpts(font_size=35,                 # 字体大小
                                                                    color='white'))))             # 字体颜色
    
    return 标题                                                                                    # 将图表作为函数返回值

主标题(主标题名称数据).render_notebook()                                                              # 展示图片


#副标题
import pyecharts.options as opts                                                                  # 调用图表配置选项库 
from pyecharts.charts import Pie                                                                  # 调用画图库

副标题名称数据 = '夏佳奇 2022-5-21'                                                                         # 设置数据

宽2='172px'                                                                                        # 设置图片宽度高度变量 
高2='30px'   

def 副标题(副标题名称数据):                                                                           # 定义函数,便于可视化大屏调用
    
    标题 = (
        
        Pie(init_opts=opts.InitOpts(width=宽2, height=高2,chart_id=2))                             # 绘图,设置图片大小、图表id
        
        .set_global_opts(
            title_opts=opts.TitleOpts(
                            title=副标题名称数据,                                                    # 设置标题
                            title_textstyle_opts=opts.TextStyleOpts(font_size=20,                  # 字体大小
                                                                    color='white'))))              # 字体颜色
    
    return 标题                                                                                     # 将图表作为函数返回值

副标题(副标题名称数据).render_notebook()                                                              # 展示图片


#热力图
from pyecharts import options as opts                                                       # 调用图表配置选项库  
from pyecharts.charts import HeatMap                                                        # 调用画图库

课程安排数据 = [[0, 2, 2], [1, 2, 1], [2, 2, 2], [3, 2, 1], [4, 2, 2], [5, 2, 0], [6, 2, 0],  # 设置数据
              [0, 1, 1], [1, 1, 2], [2, 1, 2], [3, 1, 2], [4, 1, 1], [5, 1, 0], [6, 1, 0],
              [0, 0, 0], [1, 0, 1], [2, 0, 0], [3, 0, 1], [4, 0, 0], [5, 0, 0], [6, 0, 0]]

热力图横坐标 = ['周一', '周二', '周三', '周四', '周五', '周六', '周日']                            # x轴坐标数据
热力图纵坐标 = ['晚上','下午','上午']                                                           # y轴坐标数据

宽3='410px'                                                                                 # 设置图片宽度高度变量
高3='250px'

def 课程安排热力图(课程安排数据):                                                               # 定义函数,便于可视化大屏调用
    
    热力图 = (                                                                 
        HeatMap(init_opts=opts.InitOpts(width=宽3, height=高3, chart_id=3))                 # 绘图,设置图片大小、图表id
        
        .add_xaxis(热力图横坐标)                                                             # 设置x轴坐标名
        
        .add_yaxis("", 热力图纵坐标, 课程安排数据,                                             # 设置y轴坐标名,添加数据
                   label_opts=opts.LabelOpts(color="white",                                # 标签字体颜色
                                             font_size=13,                                 # 字体大小
                                             position="inside"),                           # 位置
                   itemstyle_opts=opts.ItemStyleOpts(border_color='white',                 # 边界线颜色
                                                     border_width=3))                      # 边界线宽度

        .set_global_opts(
            visualmap_opts=opts.VisualMapOpts(max_=2,is_show=False),                       # 设置视觉映射配置项,最大值为600 
            
            xaxis_opts = opts.AxisOpts(                                                  
                              axislabel_opts = opts.LabelOpts(font_size = 13,              # 坐标轴字体大小
                                                              color='white'),              # 坐标轴字体颜色
                              axisline_opts = opts.AxisLineOpts(                           
                                                    linestyle_opts=opts.LineStyleOpts(
                                                                            color='white', # 坐标轴线颜色
                                                                            width=3))),    # 坐标轴线宽度
            yaxis_opts = opts.AxisOpts(                                                  
                              axislabel_opts = opts.LabelOpts(font_size = 13,              # 坐标轴字体大小
                                                              color='white'),              # 坐标轴字体颜色
                              axisline_opts = opts.AxisLineOpts(                           
                                                    linestyle_opts=opts.LineStyleOpts(
                         
  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值