首页 > 其他分享 >数据可视化

数据可视化

时间:2024-06-20 18:54:04浏览次数:21  
标签:pyecharts title Faker add 可视化 import 数据 opts

PyEcharts学习

官网
安装

pip install pyecharts
from pyecharts.charts import Bar
bar=Bar()
bar.add_xaxis(['衬衣','短库','长袖','短袖','棉花','鞋子','裤子'])
bar.add_yaxis('商家',[2,23,45,56,34,90,12])
bar.render()#渲染

快速使用

image

简单配置

from pyecharts.charts import Bar
bar=(
    Bar()
    .add_xaxis(['衬衣','短库','长袖','短袖','棉花','鞋子','裤子'])
    .add_yaxis('商家',[2,23,45,56,34,90,12])
    #配置
    .set_global_opts(title_opts={'text':'主标题','subtext':'副标题'})
)
bar.render()#渲染

image

渲染成图片文件

安装

pip install snapshot-selenium
from pyecharts.charts import Bar
from pyecharts.render import make_snapshot
from snapshot_selenium import snapshot
bar=(
    Bar()
    .add_xaxis(['衬衣','短库','长袖','短袖','棉花','鞋子','裤子'])
    .add_yaxis('商家',[2,23,45,56,34,90,12])
)
make_snapshot(snapshot,bar.render(),'bar.png')

使用主题

from pyecharts import options as opts
from pyecharts.charts import Bar
from pyecharts.render import make_snapshot
from snapshot_selenium import snapshot
from pyecharts.globals import ThemeType
bar=(
    Bar(
        init_opts=opts.InitOpts(theme=ThemeType.DARK)
    )
    .add_xaxis(['衬衣','短库','长袖','短袖','棉花','鞋子','裤子'])
    .add_yaxis('商家',[2,23,45,56,34,90,12])
)
bar.render()

image

全局配置项

初始化配置项

from pyecharts.faker import Faker
from pyecharts.charts import Bar
from pyecharts import options as opts
from pyecharts.globals import ThemeType,RenderType
bar=(
    Bar(
        #InitOpts:初始化配置项
        init_opts=opts.InitOpts(
            width='700px',
            height='800px',#图表画布大小,css长度单位
            renderer=RenderType.CANVAS,#渲染风格,可选:canvas,svg
            page_title='网页标题',
            theme=ThemeType.DARK,#主题
            bg_color='red'#背景颜色
        )
    )
    .add_xaxis(Faker.choose())
    .add_yaxis('商家A',Faker.values())
    .add_yaxis('商家B',Faker.values())
)
bar.render()

image

标题配置项

from pyecharts.faker import Faker
from pyecharts.charts import Bar
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType

bar = (
        Bar()
        .add_xaxis(Faker.choose())
        .add_yaxis('商家A', Faker.values())
        .add_yaxis('商家B', Faker.values())
        # 全局配置项
        .set_global_opts(
        # TitleOpts:标题配置项
        title_opts=opts.TitleOpts(
            title='柱形图',  # 主标题
            title_link='https://www.baidu.com',  # 主标题点击跳转链接
            title_target='blank',  # blank新窗口打开,self 当前窗口打开
            subtitle='副标题',
            subtitle_link='https://www.baidu.com',
            subtitle_target='blank',
            # 位置
            pos_left='20px',
            pos_top='0px',
            padding=10,  # 内边距
            item_gap=4,  # 主标题与副标题的间隙

        ),


    )
)
bar.render()

image

区域缩放项

from pyecharts.faker import Faker
from pyecharts.charts import Bar
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType

bar = (
        Bar()
        .add_xaxis(Faker.choose())
        .add_yaxis('商家A', Faker.values())
        .add_yaxis('商家B', Faker.values())
        # 全局配置项
        .set_global_opts(

        #DataZoomOpts:区域缩放项
        datazoom_opts=opts.DataZoomOpts(
            is_show=True,  # 是否显行组件
            type_='slider',  # 组件的类型,slider,inside
            is_realtime=True,  # 拖动时是否实时更新图表
            range_start=20,  # 数据窗口的起始位置,百分比
            range_end=80,  # 数据窗口的结束位置,百分比
            orient='horizontal',  # 组件放置位置,默认水平horizontal或垂直vertical
            is_show_data_shadow=False  # 是否锁定选择区域
        ),

    )
)
bar.render()

image

图例配置

from pyecharts.faker import Faker
from pyecharts.charts import Bar
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType

bar = (
        Bar()
        .add_xaxis(Faker.choose())
        .add_yaxis('商家A', Faker.values())
        .add_yaxis('商家B', Faker.values())
        # 全局配置项
        .set_global_opts(

        #LegendOpts:图例配置项
        legend_opts=opts.LegendOpts(
            type_='plain',#图例类型:plain普通类型,scroll:滚动翻页类型
            is_show=True,#是否显示图例
            pos_left='20%',#图例位置
            orient='vertical',#方向
            selected_mode='single',#选择模式:True 开启图例点击,False 关闭图例点击,single 单选,multiple 多选
            align='right',#图例和图标的位置
            padding=10,#内边距
            item_gap=5,#图例中每项之间的间距
            item_width=30,#项的宽度
            item_height=15,#项的高度
            inactive_color='#ccc',#图列关闭时的颜色
            legend_icon='roundRect',#常见图标:circle,rect,roundRect,triangle,diamond,arrov
        )

    )
)
bar.render()

image

视觉映射配置

from pyecharts.faker import Faker
from pyecharts.charts import Bar
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType

bar = (
        Bar()
        .add_xaxis(Faker.choose())
        .add_yaxis('商家A', Faker.values())
        .add_yaxis('商家B', Faker.values())
        # 全局配置项
        .set_global_opts(
        #VisualMapOpts:视觉映射配置
            visualmap_opts=opts.VisualMapOpts(
                is_show=True,
                type_='color',#color 或size
                min_=0,#最小值
                max_=150,#最大值
                range_opacity=0.7,#图元和文字透明度
                range_text=['max','min'],#两段的文本
                range_color=['blue','red','pink'],#过渡颜色
                is_piecewise=True,#是否分段
                is_inverse=True,#是否反转

        )

    )
)
bar.render()

image

提示框配置项

from pyecharts.faker import Faker
from pyecharts.charts import Bar
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType

bar = (
        Bar()
        .add_xaxis(Faker.choose())
        .add_yaxis('商家A', Faker.values())
        .add_yaxis('商家B', Faker.values())
        # 全局配置项
        .set_global_opts(
       #TooltipOpts:提示框配置项
            tooltip_opts=opts.TooltipOpts(
                is_show=True,
                #触发类型:item 数据项,一般用于:散点图,柱形图,饼图
                #       :axis 坐标轴,提示线,主要用于条形图,折线图等
                trigger='item',
                #触发条件:mousemove,click,mousemove|click
                trigger_on='click',
                is_show_content=True,#是否显示提示框浮层
                #标签内容的格式
                    #字符串中的模板变量:
                        #{a}:系列名series_name
                        #{b}:数据名
                        #{c}:值
                formatter='{a}:{b}-{c}',
                border_color='pink',#边框颜色
                border_width=1,#边框宽度
                background_color='blue'#背景颜色


            )
    )
)
bar.render()

image

坐标轴配置项

from pyecharts.faker import Faker
from pyecharts.charts import Bar
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType

bar = (
        Bar()
        .add_xaxis(Faker.choose())
        .add_yaxis('商家A', Faker.values())
        .add_yaxis('商家B', Faker.values())
        # 全局配置项
        .set_global_opts(
            #AxisOpts:坐标轴配置项
            xaxis_opts=opts.AxisOpts(
                is_show=True,#是否显示X轴
                #坐标轴类型:
                #   value:数值轴,用于连续数据
                #   category:类目轴,适用于离散数据,比如,星期一,星期二等
                #   time:时间轴,适用于连续的时序数据
                type_='category'
            ),
            yaxis_opts=opts.AxisOpts(
                is_show=True,
                #不显示y轴的线
                axisline_opts=opts.AxisLineOpts(is_show=False),
                #不显示y轴的刻度
                axistick_opts=opts.AxisTickOpts(is_show=False)
            )
    )
)
bar.render()

image

系列配置项

图元样式配置项

from pyecharts.faker import Faker
from pyecharts.charts import Bar,Line
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType

bar = (
        Line()
        .add_xaxis(Faker.choose())
        .add_yaxis('商家A', Faker.values())
        .add_yaxis('商家B', Faker.values())
        #全局配置
        .set_global_opts(
            title_opts=opts.TitleOpts(title='折线图'),
            #提示线
            tooltip_opts=opts.TooltipOpts(trigger='axis')
        )
    #系列配置项
    .set_series_opts(
            #ItemStyleOpts:图元样式配置项
            #图的颜色
            # 使用纯色
            # RGB,rgb(120,120,120)
            # RGBA,rgba(120,120,120,0.5)
            # 十六进制:#ccc
            color='blue',
            opacity=0.6,
            border_color='green',
            border_width=2
        )


)
bar.render()

image

线样式配置项

from pyecharts.faker import Faker
from pyecharts.charts import Bar,Line
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType

bar = (
        Line()
        .add_xaxis(Faker.choose())
        .add_yaxis('商家A', Faker.values())
        .add_yaxis('商家B', Faker.values())
        #全局配置
        .set_global_opts(
            title_opts=opts.TitleOpts(title='折线图'),
            #提示线
            tooltip_opts=opts.TooltipOpts(trigger='axis')
        )
    #系列配置项
    .set_series_opts(
         #LineStyleOpts:线样式配置项
            linestyle_opts=opts.LineStyleOpts(
                is_show=True,
                width=2,#线宽
                color='green',#线颜色
                type_='dashed',#直线solid,虚线dashed,点线dotted
            )
        )


)
bar.render()

image

标签配置项

from pyecharts.faker import Faker
from pyecharts.charts import Bar,Line
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType

bar = (
        Line()
        .add_xaxis(Faker.choose())
        .add_yaxis('商家A', Faker.values())
        .add_yaxis('商家B', Faker.values())
        #全局配置
        .set_global_opts(
            title_opts=opts.TitleOpts(title='折线图'),
            #提示线
            tooltip_opts=opts.TooltipOpts(trigger='axis')
        )
    #系列配置项
    .set_series_opts(
       #LabelOpts:标签配置项
            label_opts=opts.LabelOpts(
                is_show=True,
                position='top',#位置
                color='red',#颜色
                font_size=14,#大小
                font_family='Arial',#字体
                font_style='italic',#是否斜体,italic
                font_weight='bold',#是否加粗 bold
                #标签旋转,-90到90
                rotate=-40

            )
        )


)
bar.render()

image

标记点配置项

from pyecharts.faker import Faker
from pyecharts.charts import Bar,Line
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType

bar = (
        Line()
        .add_xaxis(Faker.choose())
        .add_yaxis('商家A', Faker.values())
        .add_yaxis('商家B', Faker.values())
        #全局配置
        .set_global_opts(
            title_opts=opts.TitleOpts(title='折线图'),
            #提示线
            tooltip_opts=opts.TooltipOpts(trigger='axis')
        )
    #系列配置项
    .set_series_opts(
        #MarkPointOpts:标记点配置项
            markpoint_opts=opts.MarkPointOpts(
                data=[
                    #type_:特殊标记类型,min,max,average
                    #symbol:标记点的图形
                    #symbol_size:标记点的大小
                    opts.MarkPointItem(type_='max',symbol='pin',symbol_size=50),
                    opts.MarkPointItem(type_='min')
                ]
            )

        )


)
bar.render()

image

标记线

from pyecharts.faker import Faker
from pyecharts.charts import Bar,Line
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType

bar = (
        Line()
        .add_xaxis(Faker.choose())
        .add_yaxis('商家A', Faker.values())
        .add_yaxis('商家B', Faker.values())
        #全局配置
        .set_global_opts(
            title_opts=opts.TitleOpts(title='折线图'),
            #提示线
            tooltip_opts=opts.TooltipOpts(trigger='axis')
        )
    #系列配置项
    .set_series_opts(
       #MarkLineOpts:标记线
            markline_opts=opts.MarkLineOpts(
                data=[
                    opts.MarkLineItem(type_='average')
                ],
                label_opts=opts.LabelOpts(
                    color='red'
                )
            )
        )


)
bar.render()

image

饼图

from pyecharts.faker import Faker
from pyecharts.charts import Bar,Line,Pie
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType
pie=(
    Pie()
    .add('',[list(i) for i in zip(Faker.choose(),Faker.values())])
    .set_colors(['red','blue','green','orange','yellow','pink','black'])
    .set_global_opts(
        title_opts=opts.TitleOpts(title='设置颜色'),
        legend_opts=opts.LegendOpts(type_='scroll',pos_left='80%',orient='vertical')
    )
	.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}:{c}"))
)

pie.render()

image

玫瑰图

from pyecharts.faker import Faker
from pyecharts.charts import Bar,Line,Pie
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType
pie=(
    Pie()
    .add('',[list(i) for i in zip(Faker.choose(),Faker.values())],
         radius=['30%','75%'],
         center=['25%','50%'],
         rosetype='radius'
         )
    .set_global_opts(
        title_opts=opts.TitleOpts(title='玫瑰图'),
        legend_opts=opts.LegendOpts(type_='scroll',pos_left='80%',orient='vertical')
    )
    .set_series_opts(label_opts=opts.LabelOpts(formatter="{b}:{c}"))
)

pie.render()

image

柱形图

from pyecharts.faker import Faker
from pyecharts.charts import Bar,Line,Pie
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType
bar=(
    Bar(
        init_opts=opts.InitOpts(
            animation_opts=opts.AnimationOpts(
                animation_delay=1000,#动画延时1秒钟
                animation_easing='elasticOut'#弹性动画
            )
        )
    )
    .add_xaxis(Faker.choose())
    .add_yaxis('商家A',Faker.values())
    .add_yaxis('商家B',Faker.values())
    .set_global_opts(
        title_opts=opts.TitleOpts(title='柱形图'),
        legend_opts=opts.LegendOpts(type_='scroll',pos_left='80%',orient='vertical')
    )
    .set_series_opts(label_opts=opts.LabelOpts(formatter="{b}:{c}"))
)

bar.render()

image

添加js代码

from pyecharts.faker import Faker
from pyecharts.charts import Bar,Line,Pie
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType
from pyecharts.commons.utils import JsCode
bar=(
    Bar(
        init_opts=opts.InitOpts(
           bg_color={
               'image':JsCode('img'),
               'repeat':'no-repeat'
           }
        )
    )
    .add_xaxis(Faker.choose())
    .add_yaxis('商家A',Faker.values())
    .add_yaxis('商家B',Faker.values())
    .set_global_opts(
        title_opts=opts.TitleOpts(title='柱形图添加JS代码'),
        legend_opts=opts.LegendOpts(type_='scroll',pos_left='80%',orient='vertical')
    )
    .set_series_opts(label_opts=opts.LabelOpts(formatter="{b}:{c}"))
    #添加js代码
    .add_js_funcs(
        """
        var img=new Image();
        img.src='https://ts3.cn.mm.bing.net/th?id=OSK.HEROAswkkmw5w3FXgT4DZB0RybGod_LpTISZPIztKg7SV0Q&w=472&h=280&c=13&rs=2&o=6&oif=webp&dpr=1.3&pid=SANGAM'
        """
    )
)

bar.render()

image

堆叠柱形图

from pyecharts.faker import Faker
from pyecharts.charts import Bar,Line,Pie
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType
from pyecharts.commons.utils import JsCode
bar=(
    Bar(

    )
    .add_xaxis(Faker.choose())
    .add_yaxis('商家A',Faker.values(),stack='abc')
    .add_yaxis('商家B',Faker.values(),stack='abc')
    .set_global_opts(
        title_opts=opts.TitleOpts(title='堆叠柱形图'),
        legend_opts=opts.LegendOpts(type_='scroll',pos_left='80%',orient='vertical'),
        xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=45)),
        datazoom_opts=[
            opts.DataZoomOpts(),#x轴缩放
            opts.DataZoomOpts(type_='inside')#鼠标缩放
        ]
    )
    .set_series_opts(label_opts=opts.LabelOpts(formatter="{b}:{c}"))


)

bar.render()

image

条形图

from pyecharts.faker import Faker
from pyecharts.charts import Bar,Line,Pie
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType
from pyecharts.commons.utils import JsCode
bar=(
    Bar()
    .add_xaxis(Faker.choose())
    .add_yaxis('商家A',Faker.values())
    .add_yaxis('商家B',Faker.values())
    .reversal_axis()#翻转轴,条形图
    .set_global_opts(
        title_opts=opts.TitleOpts(title='条形图'),
    )
    .set_series_opts(
        label_opts=opts.LabelOpts(position='right')
    )



)

bar.render()

image

from pyecharts.faker import Faker
from pyecharts.charts import Bar,Line,Pie
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType
from pyecharts.commons.utils import JsCode
bar=(
    Bar()
    .add_xaxis(Faker.choose())
    .add_yaxis('商家A',Faker.values(),gap='0%')
    .add_yaxis('商家B',Faker.values(),gap='0%')
    .set_global_opts(
        title_opts=opts.TitleOpts(title='不同系列柱子之间的距离'),
    )
    .set_series_opts(
        label_opts=opts.LabelOpts(position='right')
    )



)

bar.render()

image

直方图

from pyecharts.faker import Faker
from pyecharts.charts import Bar,Line,Pie
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType
from pyecharts.commons.utils import JsCode
bar=(
    Bar()
    .add_xaxis(Faker.choose())
    .add_yaxis('商家A',Faker.values(),category_gap=0)
    .set_global_opts(
        title_opts=opts.TitleOpts(title='单系列柱子之间的距离,直方图'),
    )
)

bar.render()

image

JsCode自定义柱状颜色

from pyecharts.faker import Faker
from pyecharts.charts import Bar,Line,Pie
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType
from pyecharts.commons.utils import JsCode
color_fun="""
    function(params){
        if(params.value >0 && params.value<50){
            return 'red';
            }
        else if (params.value >50 && params.value<100){
            return 'green';
            }
            else{
            return 'blue';
            }
    }
"""
bar=(
    Bar()
    .add_xaxis(Faker.choose())
    .add_yaxis('商家A',Faker.values(),itemstyle_opts=opts.ItemStyleOpts(color=JsCode(color_fun)))
    .set_global_opts(
        title_opts=opts.TitleOpts(title='JsCode自定义柱状颜色'),
    )
)

bar.render()

image

象形柱状图

from pyecharts.faker import Faker
from pyecharts.charts import Bar,Line,Pie,PictorialBar
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType,SymbolType
from pyecharts.commons.utils import JsCode

bar=(
    PictorialBar()
    .add_xaxis(Faker.choose())
    .add_yaxis('商家A',
               Faker.values(),
               label_opts=opts.LabelOpts(is_show=False),
               symbol_size=10,#符号大小
               is_symbol_clip=True,#符号裁剪
               symbol_repeat='fixed',#重复方式
               symbol=SymbolType.ROUND_RECT,#符号类型

               )
    .reversal_axis()
    .set_global_opts(
        title_opts=opts.TitleOpts(title='象形柱状图'),
        xaxis_opts=opts.AxisOpts(is_show=False),#不显示X轴
        yaxis_opts=opts.AxisOpts(
            axistick_opts=opts.AxisOpts(is_show=False),#不显示y轴刻度
            axisline_opts=opts.AxisOpts(is_show=False)#不显示y轴的线
        )
    )
)

bar.render()

image

雷达图

from pyecharts.faker import Faker
from pyecharts.charts import Bar,Line,Pie,PictorialBar,Radar
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType,SymbolType
from pyecharts.commons.utils import JsCode
v1=[[4300,10000,28000,35000,50000,19000]]
v2=[[5000,14000,28000,31000,50000,19000]]
bar=(
    Radar()
    .add_schema(
        schema=[
            opts.RadarIndicatorItem(name='项目1',max_=6000),
            opts.RadarIndicatorItem(name='项目2',max_=16000),
            opts.RadarIndicatorItem(name='项目3',max_=30000),
            opts.RadarIndicatorItem(name='项目4',max_=38000),
            opts.RadarIndicatorItem(name='项目5',max_=60000),
            opts.RadarIndicatorItem(name='项目6',max_=22000),
        ]
    )
   .set_global_opts(title_opts=opts.TitleOpts(title='雷达图'))
   .add('数据1',v1,color='blue')
   .add('数据2',v2)
   .set_series_opts(label_opts=opts.LabelOpts(is_show=True))
)

bar.render()

image

拆线图

from pyecharts.faker import Faker
from pyecharts.charts import Bar,Line,Pie,PictorialBar,Radar
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType,SymbolType
from pyecharts.commons.utils import JsCode

line=(
   Line(
       init_opts=opts.InitOpts(width='1000px',height='500px')
   )
   .add_xaxis(Faker.week)
    .add_yaxis('商家A',
               Faker.values(),
               symbol='triangle',#点符号类型:triangle三角形
               symbol_size=20,#点的大小
               linestyle_opts=opts.LineStyleOpts(
                   color='green',width=2,type_='dashed'
               ),#线条样式
               label_opts=opts.LabelOpts(
                   is_show=False
               ),#标签
               itemstyle_opts=opts.ItemStyleOpts(
                    border_color='green',border_width=2,color='yellow'
               ),#点的属性
               markpoint_opts=opts.MarkPointOpts(
                   data=[
                       opts.MarkPointItem(type_='max'),#最大值
                       opts.MarkPointItem(type_='mih'),#最小值
                   ]
               ),#标注点
               markline_opts=opts.MarkLineOpts(
                   data=[
                       opts.MarkLineItem(type_='average'),#平均值
                   ]
               ),#标注线
               )
    .add_yaxis('商家A',Faker.values(),is_smooth=True)#平滑曲线
    .set_global_opts(
       title_opts=opts.TitleOpts(title='拆线图'),
       tooltip_opts=opts.TooltipOpts(trigger='axis'),#提示线
        yaxis_opts=opts.AxisOpts(
            type_='value',
            splitline_opts=opts.SplitAreaOpts(is_show=True),#显示分隔线
        )
   )
)

line.render()

image

面积图

from pyecharts.faker import Faker
from pyecharts.charts import Bar,Line,Pie,PictorialBar,Radar
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType,SymbolType
from pyecharts.commons.utils import JsCode

line=(
   Line()
   .add_xaxis(Faker.week)
    .add_yaxis('',y_axis=[1,23,34,56,34,78,33],
               areastyle_opts=opts.AreaStyleOpts(opacity=0.5),#面积图
               )
    .set_global_opts(
       title_opts=opts.TitleOpts(
           title='面积图'
       ),
       tooltip_opts=opts.TooltipOpts(trigger='axis'),#提示线
       xaxis_opts=opts.AxisOpts(type_='category',boundary_gap=False),#boundary_gap:没有间隙
   )

)

line.render()

image

堆叠面积图

from pyecharts.faker import Faker
from pyecharts.charts import Bar,Line,Pie,PictorialBar,Radar
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType,SymbolType
from pyecharts.commons.utils import JsCode

line=(
   Line()
   .add_xaxis(Faker.week)
    .add_yaxis('广告',y_axis=[1,23,34,56,34,78,33],
               areastyle_opts=opts.AreaStyleOpts(opacity=0.5),#面积图
               stack='堆叠',
               label_opts=opts.LabelOpts(is_show=False)
               )
.add_yaxis('流量',y_axis=[1,23,34,56,34,78,33],
               areastyle_opts=opts.AreaStyleOpts(opacity=0.5),#面积图
               stack='堆叠',
               label_opts=opts.LabelOpts(is_show=False)
               )
    .set_global_opts(
       title_opts=opts.TitleOpts(
           title='堆叠面积图'
       ),
       tooltip_opts=opts.TooltipOpts(trigger='axis'),#提示线
       xaxis_opts=opts.AxisOpts(type_='category',boundary_gap=False),#boundary_gap:没有间隙
   )

)

line.render()

image

散点图

from pyecharts.faker import Faker
from pyecharts.charts import Bar,Line,Pie,PictorialBar,Radar,Scatter
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType,SymbolType
from pyecharts.commons.utils import JsCode
data=[
    [1,3],
    [1,5],
    [4,5],
    [4,5.8],
    [4.9,5.8],
    [8,5.8],
    [8.9,5.8],
    [2,5.8],

]
data.sort(key=lambda x:x[0])
x_data=[i[0] for i in data]
y_data=[y[0] for y in data]
scatter=(
   Scatter(
       init_opts=opts.InitOpts(width='800px',height='400px')
   )
    .add_xaxis(xaxis_data=x_data)
    .add_yaxis('',y_axis=y_data,symbol_size=20,label_opts=opts.LabelOpts(is_show=True))
    .set_global_opts(
       title_opts=opts.TitleOpts(
           title='散点图'
       ),
       xaxis_opts=opts.AxisOpts(
           type_='value',
           splitline_opts=opts.SplitLineOpts(is_show=True)
       ),
        yaxis_opts=opts.AxisOpts(
                   type_='value',
                   splitline_opts=opts.SplitLineOpts(is_show=True)
               )
   )


)

scatter.render()

image

涟漪散点图

from pyecharts.faker import Faker
from pyecharts.charts import Bar,Line,Pie,PictorialBar,Radar,Scatter,EffectScatter
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType,SymbolType
from pyecharts.commons.utils import JsCode

effectscatter=(
   EffectScatter()
   .add_xaxis(Faker.choose())
   .add_yaxis('',Faker.values(),symbol=SymbolType.ARROW)
    .set_global_opts(
       title_opts=opts.TitleOpts(
           title='涟漪散点图'
       )
   )


)

effectscatter.render()

image

热力图

import random
from pyecharts.faker import Faker
from pyecharts.charts import Bar,Line,Pie,PictorialBar,\
Radar,Scatter,EffectScatter,HeatMap
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType,SymbolType
from pyecharts.commons.utils import JsCode
value=[[i,j,random.randint(0,50)]for i in range(24) for j in range(7)]
effectscatter=(
   HeatMap()
   .add_xaxis(Faker.clock)#clock:时钟
   .add_yaxis('热力图',Faker.week,value,label_opts=opts.LabelOpts(is_show=True,position='inside'))
    .set_global_opts(
       title_opts=opts.TitleOpts(
           title='热力图'
       )
   )


)

effectscatter.render()

image

日历图

import random,datetime
from pyecharts.faker import Faker
from pyecharts.charts import Bar,Line,Pie,PictorialBar,\
Radar,Scatter,EffectScatter,HeatMap,Calendar
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType,SymbolType
from pyecharts.commons.utils import JsCode
begin=datetime.date(2024,1,1)
end=datetime.date(2024,12,31)
data=[[str(begin+datetime.timedelta(days=i)),random.randint(1000,25000)]
      for i in range((end-begin).days)]
calendar=(
   Calendar()
    .add('',
         data,
         calendar_opts=opts.CalendarOpts(
             range_='2024',
             daylabel_opts=opts.CalendarDayLabelOpts(name_map='cn'),#中文
             monthlabel_opts=opts.CalendarMonthLabelOpts(name_map='cn'),#中文
         ))
    .set_global_opts(
       title_opts=opts.TitleOpts(
           title='日历图'
       ),
       visualmap_opts=opts.VisualMapOpts(
           max_=25000,
           min_=1000,
           orient='horizontal',#水平方向
           is_piecewise=True,#显示方式
           pos_left='100px',
           pos_top='230px'
       )
   )


)

calendar.render()

image

箱型图

import random,datetime
from pyecharts.faker import Faker
from pyecharts.charts import Bar,Line,Pie,PictorialBar,\
Radar,Scatter,EffectScatter,HeatMap,Calendar,Boxplot
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType,SymbolType
from pyecharts.commons.utils import JsCode
v1=[[23,234,4353,23432,654,89,98798],[23,2342,435,2332,6534,89,9898]]
boxplot=Boxplot()
boxplot.add_xaxis(['demo1','demo2'])
boxplot.add_yaxis('A',boxplot.prepare_data(v1))
boxplot.render()

image

词云图

import random,datetime
from pyecharts.faker import Faker
from pyecharts.charts import Bar,Line,Pie,PictorialBar,\
Radar,Scatter,EffectScatter,HeatMap,Calendar,Boxplot,WordCloud
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType,SymbolType
from pyecharts.commons.utils import JsCode
data=[(i,random.randint(1,1000))  for i in Faker.choose() ]
wordcloud=(
    WordCloud()
    .add(
        '热点分析',
        data_pair=data,
        word_size_range=[6,60],#字体大小范围
        textstyle_opts=opts.TextStyleOpts(
            font_family='cursive'#字体
        )
    )
    .set_global_opts(
        title_opts=opts.TitleOpts(title='词云图')
    ))
wordcloud.render()

image

漏斗图

import random,datetime
from pyecharts.faker import Faker
from pyecharts.charts import Bar,Line,Pie,PictorialBar,\
Radar,Scatter,EffectScatter,HeatMap,Calendar,Boxplot,WordCloud,\
Funnel
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType,SymbolType
from pyecharts.commons.utils import JsCode
data=[(i,random.randint(1,1000))  for i in Faker.choose() ]
funnel=(
    Funnel()
    .add(
        '商品',
        [list(i) for i in zip(Faker.choose(),Faker.values())],
        gap=2,#间隙
        tooltip_opts=opts.TooltipOpts(
            trigger='item',
            formatter='{a}<br/> {b}:{c}'
        )
    )
    .set_global_opts(
        title_opts=opts.TitleOpts(title='漏斗图')
    ))
funnel.render()

image

极坐标图

import random,datetime
from pyecharts.faker import Faker
from pyecharts.charts import Bar,Line,Pie,PictorialBar,\
Radar,Scatter,EffectScatter,HeatMap,Calendar,Boxplot,WordCloud,\
Funnel,Polar
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType,SymbolType
from pyecharts.commons.utils import JsCode

polar=(
    Polar()
    .add_schema(
        radiusaxis_opts=opts.RadiusAxisOpts(
            data=Faker.week,
            type_='category'
        )
    )
    .add('商品A',[1,24,34,45,76,12,90],type_='bar',stack='abc')
    .add('商品B',[1,30,34,45,76,13,90],type_='bar',stack='abc')
    .add('商品C',[1,24,34,56,76,12,90],type_='bar',stack='abc')
    .set_global_opts(
        title_opts=opts.TitleOpts(title='极坐标图+堆叠柱形图')
    ))
polar.render()

image

import random,datetime
from pyecharts.faker import Faker
from pyecharts.charts import Bar,Line,Pie,PictorialBar,\
Radar,Scatter,EffectScatter,HeatMap,Calendar,Boxplot,WordCloud,\
Funnel,Polar
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType,SymbolType
from pyecharts.commons.utils import JsCode
data=[(i,random.randint(1,100))for i in range(101)]
polar=(
    Polar()
    .add(
        '极坐标',
        data,
        type_='scatter',#散点图
        label_opts=opts.LabelOpts(is_show=False)
    )
    .set_global_opts(
        title_opts=opts.TitleOpts(title='极坐标图')
    ))
polar.render()

image

水球图

import random,datetime
from pyecharts.faker import Faker
from pyecharts.charts import Bar,Line,Pie,PictorialBar,\
Radar,Scatter,EffectScatter,HeatMap,Calendar,Boxplot,WordCloud,\
Funnel,Polar,Liquid
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType,SymbolType
from pyecharts.commons.utils import JsCode

liquid=(
    Liquid()
    .add('',[0.2,0.7])
    .set_global_opts(
        title_opts=opts.TitleOpts(title='水球图')
    ))
liquid.render()

image

桑基图

import random, datetime
from pyecharts.faker import Faker
from pyecharts.charts import Bar, Line, Pie, PictorialBar, \
    Radar, Scatter, EffectScatter, HeatMap, Calendar, Boxplot, WordCloud, \
    Funnel, Polar, Liquid, Sankey
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType, SymbolType
from pyecharts.commons.utils import JsCode

nodes = [
    {'name': 'c1'},
    {'name': 'c2'},
    {'name': 'c3'},
    {'name': 'c4'},
    {'name': 'c5'},
    {'name': 'c6'},
    {'name': 'c7'},
]
links=[
    {'source':'c1','target':'c2','value':10},
    {'source':'c2','target':'c3','value':20},
    {'source':'c3','target':'c4','value':30},
    {'source':'c4','target':'c5','value':40},
    {'source':'c6','target':'c7','value':50},
]
sankey = (
    Sankey()
        .add('',
             nodes,#所有节点
             links,#节点之间的链接关系
             linestyle_opt=opts.LineStyleOpts(
                 opacity=0.2,#透明度
                 curve=0.6,#曲线幅度0~1
                 color='red'
             )
             )
        .set_global_opts(
        title_opts=opts.TitleOpts(title='桑基图')
    ))
sankey.render()

image

旭日图

import random, datetime
from pyecharts.faker import Faker
from pyecharts.charts import Bar, Line, Pie, PictorialBar, \
    Radar, Scatter, EffectScatter, HeatMap, Calendar, Boxplot, WordCloud, \
    Funnel, Polar, Liquid, Sankey,Sunburst
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType, SymbolType
from pyecharts.commons.utils import JsCode
data=[
    opts.SunburstItem(
        name='Grandpa',
        children=[
            opts.SunburstItem(
                name='Uncle',
                value=15,
                children=[
                    opts.SunburstItem(name='Jack',value=2),
                    opts.SunburstItem(
                        name='Mary',
                        value=5,
                        children=[opts.SunburstItem(name='Jackson',value=2)]
                    )
                ]
            )
        ],
    ),
    opts.SunburstItem(
        name='Father',
        value=10,
        children=[
            opts.SunburstItem(name='Me',value=5),
            opts.SunburstItem(name='Peter',value=1),
        ]
    ),
    opts.SunburstItem(
        name='Nancy',
        children=[
            opts.SunburstItem(
                name='Nike',
                children=[
                    opts.SunburstItem(name='Betty',value=1),
                    opts.SunburstItem(name='Jenny',value=2)
                ]
            )
        ]
    )
]

sunburst = (
    Sunburst(
        init_opts=opts.InitOpts(
            width='800px',height='400px'
        )
    )
        .add('',data_pair=data)
        .set_global_opts(
        title_opts=opts.TitleOpts(title='旭日图')
    ))
sunburst.render()

image

仪表盘

import random, datetime
from pyecharts.faker import Faker
from pyecharts.charts import Bar, Line, Pie, PictorialBar, \
    Radar, Scatter, EffectScatter, HeatMap, Calendar, Boxplot, WordCloud, \
    Funnel, Polar, Liquid, Sankey,Sunburst,Gauge
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType, SymbolType
from pyecharts.commons.utils import JsCode


gauge = (
    Gauge()
        .add('指标',data_pair=[('','66')],radius='60%')
        .set_global_opts(
        title_opts=opts.TitleOpts(title='仪表盘')
    ))
gauge.render()

image

树图

import random, datetime
from pyecharts.faker import Faker
from pyecharts.charts import Bar, Line, Pie, PictorialBar, \
    Radar, Scatter, EffectScatter, HeatMap, Calendar, Boxplot, WordCloud, \
    Funnel, Polar, Liquid, Sankey,Sunburst,Gauge,Tree
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType, SymbolType
from pyecharts.commons.utils import JsCode
data=[
    {
        'children':[
            {'name':'叔叔'},
            {'children':[{'name':'小华'}],'name':'伯伯'},
            {'name':'父亲',
             'children':[
                 {'name':'我'},
                 {'name':'姐姐'}
             ]}
        ],
        'name':'祖父母'
    }
]

tree = (
    Tree()
        .add('指标',data)
        .set_global_opts(
        title_opts=opts.TitleOpts(title='树图')
    ))
tree.render()

image

矩形树图

import random, datetime
from pyecharts.faker import Faker
from pyecharts.charts import Bar, Line, Pie, PictorialBar, \
    Radar, Scatter, EffectScatter, HeatMap, Calendar, Boxplot, WordCloud, \
    Funnel, Polar, Liquid, Sankey,Sunburst,Gauge,Tree,TreeMap
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType, SymbolType
from pyecharts.commons.utils import JsCode
data=[
    {'value':40,'name':'伯伯'},
    {
        'value':180,
        'name':'父亲',
        'children':[
            {'value':70,
             'name':'我',
             'children':[
                 {'value':12,'name':'大儿子'},
                 {'value':28,'name':'二儿子'},
                 {'value':18,'name':'三女儿'},
                 {'value':16,'name':'四女儿'},
             ]}
        ]
    }
]

treemap = (
    TreeMap()
        .add('',data)
        .set_global_opts(
        title_opts=opts.TitleOpts(title='矩形树图')
    ))
treemap.render()

image

关系图

import random, datetime
from pyecharts.faker import Faker
from pyecharts.charts import Bar, Line, Pie, PictorialBar, \
    Radar, Scatter, EffectScatter, HeatMap, Calendar, Boxplot, WordCloud, \
    Funnel, Polar, Liquid, Sankey,Sunburst,Gauge,Tree,TreeMap,Graph
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType, SymbolType
from pyecharts.commons.utils import JsCode
nodes=[
    {'name':'node1','symbolSize':10},
    {'name':'node2','symbolSize':20},
    {'name':'node3','symbolSize':30},
    {'name':'node4','symbolSize':40},
    {'name':'node5','symbolSize':50},
    {'name':'node6','symbolSize':60},
    {'name':'node7','symbolSize':10},
]
links=[]
for i in nodes:
    for j in nodes:
        links.append({'source':i.get('name'),'target':j.get('name')})


graph = (
    Graph()
        .add('',
             nodes,
             links,
             repulsion=8000#排斥力:越大分的越开
             )
        .set_global_opts(
        title_opts=opts.TitleOpts(title='关系图')
    ))
graph.render()

image

import random, datetime
from pyecharts.faker import Faker
from pyecharts.charts import Bar, Line, Pie, PictorialBar, \
    Radar, Scatter, EffectScatter, HeatMap, Calendar, Boxplot, WordCloud, \
    Funnel, Polar, Liquid, Sankey,Sunburst,Gauge,Tree,TreeMap,Graph
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType, SymbolType
from pyecharts.commons.utils import JsCode
nodes_data=[
    opts.GraphNode(name='node1',symbol_size=10),
    opts.GraphNode(name='node2',symbol_size=20),
    opts.GraphNode(name='node3',symbol_size=30),
    opts.GraphNode(name='node4',symbol_size=40),
    opts.GraphNode(name='node5',symbol_size=50),
    opts.GraphNode(name='node6',symbol_size=60),
]
link_data=[
    opts.GraphLink(source='node1',target='node2',value=1),
    opts.GraphLink(source='node2',target='node3',value=2),
    opts.GraphLink(source='node3',target='node4',value=3),
    opts.GraphLink(source='node4',target='node5',value=4),
    opts.GraphLink(source='node5',target='node6',value=5),
    opts.GraphLink(source='node6',target='node1',value=6),
]


graph = (
    Graph()
        .add('',
             nodes_data,
             link_data,
             repulsion=3000,#排斥力:越大分的越开
             edge_label=opts.LabelOpts(
                 is_show=True,
                 position='middle',
                 formatter='{b}的数据:{c}'
             )
             )
        .set_global_opts(
        title_opts=opts.TitleOpts(title='关系图2')
    ))
graph.render()

image

K线图

import random, datetime
from pyecharts.faker import Faker
from pyecharts.charts import Bar, Line, Pie, PictorialBar, \
    Radar, Scatter, EffectScatter, HeatMap, Calendar, Boxplot, WordCloud, \
    Funnel, Polar, Liquid, Sankey, Sunburst, Gauge, Tree, TreeMap, Graph, Kline
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType, SymbolType
from pyecharts.commons.utils import JsCode

data = [
    # 开盘价,收盘价,最低价,最高价
    [2320.20, 2320.26, 2287, 2363],
    [2320.21, 2320.26, 2287, 2363],
    [2320.22, 2320.27, 2284, 2362],
    [2320.20, 2320.27, 2283, 2363],
    [2320.23, 2320.20, 2282, 2364],
    [2320.24, 2320.22, 2281, 2365],
]

kline = (
    Kline()
        .add_xaxis(['2024/1/{}'.format(i + 1) for i in range(31)])
        .add_yaxis('K线图', data)
        .set_global_opts(
        title_opts=opts.TitleOpts(title='K线图')
    ))
kline.render()

image

地图

import random, datetime
from pyecharts.faker import Faker
from pyecharts.charts import Bar, Line, Pie, PictorialBar, \
    Radar, Scatter, EffectScatter, HeatMap, Calendar, Boxplot, WordCloud, \
    Funnel, Polar, Liquid, Sankey, Sunburst, Gauge, Tree, TreeMap, Graph, \
    Kline,Map
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType, SymbolType
from pyecharts.commons.utils import JsCode

provinces=[p+"市" if p=='上海'else p+'省' for p in Faker.provinces]

map = (
    Map()
     .add(
        '',
        [list(i) for i in zip(provinces,Faker.values())],
        'china'#地图类型
    )
        .set_global_opts(
        title_opts=opts.TitleOpts(title='地图'),
        visualmap_opts=opts.VisualMapOpts(max_=200)
    ))
map.render()

image

import random, datetime
from pyecharts.faker import Faker
from pyecharts.charts import Bar, Line, Pie, PictorialBar, \
    Radar, Scatter, EffectScatter, HeatMap, Calendar, Boxplot, WordCloud, \
    Funnel, Polar, Liquid, Sankey, Sunburst, Gauge, Tree, TreeMap, Graph, \
    Kline,Map
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType, SymbolType
from pyecharts.commons.utils import JsCode


map = (
    Map()
     .add(
        '',
        [list(i) for i in zip(Faker.guangdong_city,Faker.values())],
        '广东'#地图类型
    )
        .set_global_opts(
        title_opts=opts.TitleOpts(title='广东地图'),
        visualmap_opts=opts.VisualMapOpts(max_=200,is_piecewise=True)
    ))
map.render()

image

import random, datetime
from pyecharts.faker import Faker
from pyecharts.charts import Bar, Line, Pie, PictorialBar, \
    Radar, Scatter, EffectScatter, HeatMap, Calendar, Boxplot, WordCloud, \
    Funnel, Polar, Liquid, Sankey, Sunburst, Gauge, Tree, TreeMap, Graph, \
    Kline,Map
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType, SymbolType
from pyecharts.commons.utils import JsCode


map = (
    Map()
     .add(
        '',
        [list(i) for i in zip(Faker.country,Faker.values())],
        'world'#地图类型
    )
        .set_global_opts(
        title_opts=opts.TitleOpts(title='世界地图'),
        visualmap_opts=opts.VisualMapOpts(max_=200,is_piecewise=True)
    ))
map.render()

image

import random, datetime
from pyecharts.faker import Faker
from pyecharts.charts import Bar, Line, Pie, PictorialBar, \
    Radar, Scatter, EffectScatter, HeatMap, Calendar, Boxplot, WordCloud, \
    Funnel, Polar, Liquid, Sankey, Sunburst, Gauge, Tree, TreeMap, Graph, \
    Kline,Map,MapGlobe
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType, SymbolType
from pyecharts.commons.utils import JsCode
POPULATION=[
    ['china',1322343243],
    ['India',132343243],
    ['Indonesia',1322343243],
    ['Mexico',1022343243],
    ['Japan',122343243],
    ['Ethiopia',1122343243],
            ]
data=[i for _,i in POPULATION]
low,high=min(data),max(data)
mapglobe = (
    MapGlobe()
    .add_schema()
     .add(
        maptype='world',
        series_name='世界人口',
        data_pair=POPULATION,#人口数据
        is_map_symbol_show=False,#地图中各个国家的符号是否显示
        label_opts=opts.LabelOpts(is_show=True)#显示国家名称
    )

        .set_global_opts(
        title_opts=opts.TitleOpts(title='地球'),
        visualmap_opts=opts.VisualMapOpts(max_=high,min_=low,range_text=['Max','Min'],is_piecewise=True)
    ))
mapglobe.render()

地理坐标图

import random, datetime
from pyecharts.faker import Faker
from pyecharts.charts import Bar, Line, Pie, PictorialBar, \
    Radar, Scatter, EffectScatter, HeatMap, Calendar, Boxplot, WordCloud, \
    Funnel, Polar, Liquid, Sankey, Sunburst, Gauge, Tree, TreeMap, Graph, \
    Kline, Map, MapGlobe, Geo
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType, SymbolType, ChartType
from pyecharts.commons.utils import JsCode

geo = (
    Geo()
        .add_schema(maptype='china')
        .add('',
             [('广州', 50), ('北京', 60), ('杭州', 70), ('重庆', 80)],
             type_=ChartType.EFFECT_SCATTER, color='red')
        .add(
        '',
        [('广州', '上海'), ('广州', '北京'), ('广州', '杭州'), ('广州', '重庆')],
        type_=ChartType.LINES,  # 线
        #箭头
        effect_opts=opts.EffectOpts(
            symbol_size=6,
            symbol=SymbolType.ARROW,
            color='blue'
        ),
        linestyle_opts=opts.LineStyleOpts(curve=0.2)

    )
        .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
        .set_global_opts(
        title_opts=opts.TitleOpts(title='地理坐标图'),

    ))
geo.render()

image

import random, datetime
from pyecharts.faker import Faker
from pyecharts.charts import Bar, Line, Pie, PictorialBar, \
    Radar, Scatter, EffectScatter, HeatMap, Calendar, Boxplot, WordCloud, \
    Funnel, Polar, Liquid, Sankey, Sunburst, Gauge, Tree, TreeMap, Graph, \
    Kline, Map, MapGlobe, Geo
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType, SymbolType, ChartType
from pyecharts.commons.utils import JsCode

geo = (
    Geo()
        .add_schema(maptype='china')
        .add('geo',
             [list(i) for i in zip(Faker.provinces,Faker.values())],
             type_=ChartType.HEATMAP#热力图
             )
        .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
        .set_global_opts(
        title_opts=opts.TitleOpts(title='地理坐标图+热力图'),
        visualmap_opts=opts.VisualMapOpts()

    ))
geo.render()

image

import random, datetime
from pyecharts.faker import Faker
from pyecharts.charts import Bar, Line, Pie, PictorialBar, \
    Radar, Scatter, EffectScatter, HeatMap, Calendar, Boxplot, WordCloud, \
    Funnel, Polar, Liquid, Sankey, Sunburst, Gauge, Tree, TreeMap, Graph, \
    Kline, Map, MapGlobe, Geo
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType, SymbolType, ChartType
from pyecharts.commons.utils import JsCode

geo = (
    Geo()
        .add_schema(maptype='china')
        .add('geo',
             [list(i) for i in zip(Faker.provinces,Faker.values())],
             type_=ChartType.EFFECT_SCATTER#涟漪散点图
             )
        .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
        .set_global_opts(
        title_opts=opts.TitleOpts(title='地理坐标图+涟漪散点图'),
        visualmap_opts=opts.VisualMapOpts()

    ))
geo.render()

image

3D拆线图

import random, datetime,math
from pyecharts.faker import Faker
from pyecharts.charts import Bar, Line, Pie, PictorialBar, \
    Radar, Scatter, EffectScatter, HeatMap, Calendar, Boxplot, WordCloud, \
    Funnel, Polar, Liquid, Sankey, Sunburst, Gauge, Tree, TreeMap, Graph, \
    Kline, Map, MapGlobe, Geo,Line3D
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType, SymbolType, ChartType
from pyecharts.commons.utils import JsCode
data=[]
for i in range(0,25000):
    _i=i/1000
    x=(1+0.25*math.cos(75*_i))*math.cos(_i)
    y=(1+0.25*math.cos(75*_i))*math.sin(_i)
    z=_i+2.0*math.sin(75*_i)
    data.append([x,y,z])

line3d = (
    Line3D()

        .add('',
             data,
             xaxis3d_opts=opts.Axis3DOpts(Faker.clock,type_='value'),
             yaxis3d_opts=opts.Axis3DOpts(Faker.week,type_='value'),
             grid3d_opts=opts.Grid3DOpts(
                 width=100,
                 depth=100,
                 rotate_speed=150,
                 is_rotate=True
             )
             )
        .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
        .set_global_opts(
        title_opts=opts.TitleOpts(title='3D拆线图'),
        visualmap_opts=opts.VisualMapOpts(
            min_=0,
            max_=30,
            range_color=Faker.visual_color
        )

    ))
line3d.render()

image

3D柱状图

import random, datetime,math
from pyecharts.faker import Faker
from pyecharts.charts import Bar, Line, Pie, PictorialBar, \
    Radar, Scatter, EffectScatter, HeatMap, Calendar, Boxplot, WordCloud, \
    Funnel, Polar, Liquid, Sankey, Sunburst, Gauge, Tree, TreeMap, Graph, \
    Kline, Map, MapGlobe, Geo,Line3D,Bar3D
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType, SymbolType, ChartType
from pyecharts.commons.utils import JsCode
data=[(i,j,random.randint(0,12)) for i in range(6) for j in range(24)]


bar3d = (
    Bar3D()
        .add('',
             [[d[1],d[0],d[2] ]for d in data],
             xaxis3d_opts=opts.Axis3DOpts(Faker.clock,type_='category'),
             yaxis3d_opts=opts.Axis3DOpts(Faker.week,type_='category'),
             zaxis3d_opts=opts.Axis3DOpts(type_='value')
             )
        .set_global_opts(
        title_opts=opts.TitleOpts(title='3D柱状图'),
        visualmap_opts=opts.VisualMapOpts(
            max_=15,
        )

    ))
bar3d.render()

image

3D堆叠柱状图

import random, datetime, math
from pyecharts.faker import Faker
from pyecharts.charts import Bar, Line, Pie, PictorialBar, \
    Radar, Scatter, EffectScatter, HeatMap, Calendar, Boxplot, WordCloud, \
    Funnel, Polar, Liquid, Sankey, Sunburst, Gauge, Tree, TreeMap, Graph, \
    Kline, Map, MapGlobe, Geo, Line3D, Bar3D
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType, SymbolType, ChartType
from pyecharts.commons.utils import JsCode

x_data = y_data = list(range(10))


def generate_data():
    data = []
    for i in range(10):
        for j in range(10):
            value = random.randint(0, 9)
            data.append([i, j, value * 2 + 4])
    return data


bar3d = Bar3D()
for _ in range(10):
    bar3d.add('',
              generate_data(),
              xaxis3d_opts=opts.Axis3DOpts(x_data, type_='value'),
              yaxis3d_opts=opts.Axis3DOpts(y_data, type_='value'),
              zaxis3d_opts=opts.Axis3DOpts(type_='value'),
              shading='lambert'  # 清晰
              )
bar3d.set_global_opts(
    title_opts=opts.TitleOpts(title='3D堆叠柱状图'),
    visualmap_opts=opts.VisualMapOpts(
        max_=15,
    )
)

bar3d.set_series_opts(stack='abc')
bar3d.render()

image

时间轮播图

import random, datetime, math
from pyecharts.faker import Faker
from pyecharts.charts import Bar, Line, Pie, PictorialBar, \
    Radar, Scatter, EffectScatter, HeatMap, Calendar, Boxplot, WordCloud, \
    Funnel, Polar, Liquid, Sankey, Sunburst, Gauge, Tree, TreeMap, Graph, \
    Kline, Map, MapGlobe, Geo, Line3D, Bar3D,Timeline
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType, SymbolType, ChartType
from pyecharts.commons.utils import JsCode

x=Faker.choose()
tl=Timeline()
for i in range(2020,2025):
    bar=(
        Bar()
        .add_xaxis(x)
        .add_yaxis('A',Faker.values())
        .add_yaxis('B',Faker.values())
        .set_global_opts(
            title_opts=opts.TitleOpts(title='时间轮播图')
        )
    )
    tl.add(bar,'{}年'.format(i))
tl.render()

image

并行布局

import random, datetime, math
from pyecharts.faker import Faker
from pyecharts.charts import Bar, Line, Pie, PictorialBar, \
    Radar, Scatter, EffectScatter, HeatMap, Calendar, Boxplot, WordCloud, \
    Funnel, Polar, Liquid, Sankey, Sunburst, Gauge, Tree, TreeMap, Graph, \
    Kline, Map, MapGlobe, Geo, Line3D, Bar3D,Timeline,Grid
from pyecharts import options as opts
from pyecharts.globals import ThemeType, RenderType, SymbolType, ChartType
from pyecharts.commons.utils import JsCode
line=(
    Line()
    .add_xaxis(Faker.choose())
    .add_yaxis('A',Faker.values())
    .add_yaxis('B',Faker.values())
    .set_global_opts(
        title_opts=opts.TitleOpts(title='拆线图',pos_left='5%'),
        legend_opts=opts.LegendOpts(pos_left='20%')
    )
)
scatter=(
    Scatter()
    .add_xaxis(Faker.choose())
    .add_yaxis('C',Faker.values())
    .add_yaxis('D',Faker.values())
    .set_global_opts(
        title_opts=opts.TitleOpts(title='散点图',pos_right='40%'),
        legend_opts=opts.LegendOpts(pos_right='20%')
    )
)
grid=(
    Grid()
    .add(line,grid_opts=opts.GridOpts(pos_right='55%'))
    .add(scatter,grid_opts=opts.GridOpts(pos_left='55%'))
)
grid.render()

image

标签:pyecharts,title,Faker,add,可视化,import,数据,opts
From: https://www.cnblogs.com/ytmjcmn/p/18113008

相关文章

  • 腾讯云部署的java服务,访问阿里云的mysql数据库,带宽异常偏高,可能是什么原因
    个人名片......
  • 【CS.DS】数据结构 —— 图结构:图的三种表示方法之邻接表(Adjacency List)
    文章目录1概念2无向图的邻接表2.1示例2.2Mermaid图示例2.3C++实现2.3.1简单实现2.3.2优化封装2.4总结3有向图的邻接表3.1示例3.2C++实现3.3总结4邻接图的遍历5拓展补充References数据结构1概念优点:空间效率高,适合稀疏图。动态性强,可以方便地......
  • 最快方式搭建docker大数据 测试集群
    平时搭建一套测试集群找包找的累死,现在使用docker搭建cdh版本的 1.首先在服务器上安装dockeryuminstalldocker2.配置国内阿里云docker仓库服务 https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors 换成地址,重启docker服务sudomkdir-p/etc/dockers......
  • Oracle系列---【数据库账号频繁被锁定,如何定位到是哪台服务器器导致的?】
    1.问题描述接审计要求,已上线的数据库的密码属于弱口令,需要更改成严格的,但是服务又不能停机,这种情况下,只能在原有用户名上新增代理用户,这里不能用新建用户的方案,因为用户间不能共用schema,所以只能用新增代理用户的方案。切换到代理用户的过程中发现,"ORA-28000:Theaccountisl......
  • 一文带你了解STM32F4中断的概念,串口的概念,DMA的转运,以及如何运用在串口的收发上,串口收
    本篇主要实现的是用UART的接收中断接收数据,用DMA接收不定长的数据并发送回给电脑,接收信息控制LED灯的亮灭,成为点灯大师。什么是中断(EXIT)EXIT 外部中断/事件控制器,管理了控制器的20个中断/事件线。每个中断/事件线都对应有一个边沿检测器,可以实现输入信号的上升沿检测和下......
  • 数据处理技术-Hive的表与数据类型
    Hive数据模型Hive的数据模型主要由表构成,包括内部表,外部表,分区表和桶表。我也将从这四个方面介绍。在这之前先介绍另外一个概念:DDL,DataDefinitionLanguage数据定义语言,是SQL语言集中对数据库内部的对象结构进行创建,删除,修改等的操作语言。核心语法由CREATE,ALTER,DROP......
  • Java智慧工地源码 5G智慧工地系统源码 使用SAAS部署 三维可视化管理,与一线生产过程相
    Java智慧工地源码5G智慧工地系统源码使用SAAS部署三维可视化管理,与一线生产过程相融合,集成数据后台,统一前端入口,呈现多方项目信息;智慧工地是指运用信息化手段,通过三维设计平台对工程项目进行精确设计和施工模拟,围绕施工过程管理,建立互联协同、智能生产、科学管理的施工项......
  • 【廉颇老矣,尚能饭否】传统的数据仓库是否还能发挥作用?
    引言:随着数字化转型的深入和大数据技术的发展,大数据平台、数据中台和和数据湖技术不断涌现,给人感觉传统的数据仓库技术已经过时,廉颇老矣,不能应对新的挑战,在数字化转型中,不能发挥重要作用;传统数仓,尚能饭否?客观来说,传统数仓的优势还是可以在数字化转型中发挥重要的作用,如预算不......
  • linux可视化监控:Grafana+Prometheus+node_exporter
    原理node_exporter:它的作用主要是收集性能测试的数据,如cpu、内存磁盘网络等信息,然后将数据保存到prometheus,相当于将数据存入到数据库中;想要监控不同的内容,就使用不同的exporter,比如mysqld_exporterPrometheus:虽然说是监控平台,但是实际上是一套数据库,用于做数据存储,不能做展......
  • 业务数据脱敏
    业务数据脱敏一、什么是数据脱敏先来看看什么是数据脱敏?数据脱敏也叫数据的去隐私化,在我们给定脱敏规则和策略的情况下,对敏感数据比如手机号、银行卡号等信息,进行转换或者修改的一种技术手段,防止敏感数据直接在不可靠的环境下使用。像政府、医疗行业、金融机构、移动运营商是......