PyEcharts知识点详解(每张图都有!)(pyechartsmap)

PyEcharts知识点详解(每张图都有!)1.配置项: 全局配置项: 可以通过set_global_opts方法设置 frompyechartsimportoptionsasopts frompyecharts

1. 设置项目:

全局配置项:

可以通过set_global_opts方法进行设置。

frompyechartsimportoptionsasopts

来自pyecharts.fakerimportFaker

frompyecharts.chartsimportBar、Line

frompyecharts.globalsimportCurrentConfig、RenderType、ThemeType

CurrentConfig.ONLINE_HOST=\’https://cdn.jsdelivr.net/npm/echarts@latest/dist/\’

c=(

酒吧(

#InitOpts: 初始化配置项

init_opts=opts.InitOpts(

宽度=\’700px\’,

height=\’400px\’,#图表画布大小,CSS长度单位

renderer=RenderType.CANVAS,#渲染风格,选项:Canvas、svg

page_title=\’网页标题\’,

主题=ThemeType.DARK,#主题

bg_color=\’black\’),#背景颜色

.add_xaxis(Faker.choose())

.add_yaxis(\’卖家A\’,Faker.values())

.add_yaxis(\’卖家B\’,Faker.values())

#全局设置项

.set_global_opts(

title_opts=opts.TitleOpts(title=\’条形图\’,

subtitle=\’副标题\’,

title_link=\’http://www.baidu.com\’,#点击主标题跳转链接

title_target=\’self\’,#blank打开新窗口并为self打开当前窗口

subtitle_link=\’http://www.baidu.com\’,

#标题位置

pos_left=\’20px\’,

pos_top=\’0px\’,

pos_right=\’0px\’,

pos_bottom=\’0px\’,

填充=10,#填充

item_gap=10,#主标题与副标题之间的间隙

),

#区域缩放设置项

datazoom_opts=opts.DataZoomOpts(is_show=True,#是否显示组件

type_=\’slider\’,#组件类型:滑块,内部

is_realtime=True, #拖动时是否实时更新图表

range_start=40,#数据窗口的起始位置

range_end=80,#数据窗口结束位置

orient=\’水平\’,#horizontalorveritical

is_zoom_lock=True#是否锁定选择范围?

),

#图例设置项

legend_opts=opts.LegendOpts(type_=\’plain\’,#plain: 常规图例、滚动、可滚动页面的图例

is_show=True,#是否显示图例

pos_left=\’20%\’,#图例位置

位置顶部=10,

pos_right=10,

pos_bottom=10,

orient=\’水平\’,#水平或垂直

#选择模式:True:开启图例点击,False:关闭图例点击,singe:单选,multiple:多选

selected_mode=\’多个\’,

align=\’right\’,#图标与文字对齐

填充=10,#填充

item_gap=5,#图例之间的间距

item_width=30,项目宽度#

item_height=12,#物品高度

inactive_color=\’#ccc\’,#图例关闭时的颜色

legend_icon=\’circle\’#circle,rect,roundRect,triangle,diamond,arrow 图标形状

),

#VisualMapOpts: 可视化映射配置项

Visualmap_opts=opts.VisualMapOpts(is_show=True,

type_=\’颜色\’,#colorsize

最小_=0,

最大_=255,

range_opacity=0.7,#照片和文字透明度

range_text=[\’max\’,\’min\’],#两端文本

range_color=[\’蓝色\’,\’绿色\’,\’黄色\’,\’红色\’],#多余的颜色

orient=\’vertical\’,#水平或垂直

#pos_left=\’0%\’,#位置

位置顶部=0,

pos_right=\’5%\’,

#pos_bottom=0,

is_piecewise=True,#是否分段

is_inverse=True,#是否反转

),

tooltip_opts=opts.TooltipOpts(is_show=True,

trigger=\’item\’,#触发类型item:数据项。通常用于散点图、柱形图和饼图。

#axis: 轴,提示行。主要用于条形图、折线图等。

trigger_on=\’click\’,#触发条件:mousemove、click、mousemove|click

is_show_content=True,#是否显示提示框浮层

formatter=\'{a}:{b}-{c}\’,#标签内容格式:模板变量字符为:{a}:系列名称series_name{b}:数据名称{c}:值

背景颜色=\’灰色\’,

border_color=\’白色\’,

边框宽度=1,

),

xaxis_opts=opts.AxisOpts(is_show=True,#是否显示X轴

type_=\’category\’, #axis类型:value:数值轴,用于连续数据,category:分类轴,适合周一、周二、time:等离散数据。适用于时间轴和连续时间序列数据。

),

yaxis_opts=opts.AxisOpts(axisline_opts=opts.AxisLineOpts(is_show=True),#显示y轴

axistick_opts=opts.AxisTickOpts(is_show=False)#不显示y轴刻度

),

.render(\’bar_base.html\’)

系列组成项目:

系列配置项可以使用set_series_opts方法设置

来自pyecharts.chartsimportLine

frompyechartsimportoptionsasopts

来自pyecharts.fakerimportFaker

frompyecharts.chartsimportBar、Line

frompyecharts.globalsimportCurrentConfig、RenderType、ThemeType

CurrentConfig.ONLINE_HOST=\’https://cdn.jsdelivr.net/npm/echarts@latest/dist/\’

c=(

线(

#InitOpts: 初始化配置项

init_opts=opts.InitOpts(

宽度=\’700px\’,

height=\’400px\’,#图表画布大小,CSS长度单位

.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(

itemstyle_opts=opts.ItemStyleOpts(#Item样式配置项

#图像颜色:纯色:RGB, rgb(120, 120, 120), RGBA, rgba(120, 120, 120, 0.5), hex #ccc

颜色=\’蓝色\’,

不透明度=0.6,#透明度

border_color=\’绿色\’,

边框宽度=2,

),

linestyle_opts=opts.LineStyleOpts(

is_show=true,

宽度=2,

color=\’green\’,#线条颜色

type_=\’虚线\’,#实线,虚线,虚线

),

#标签设置项

label_opts=opts.LabelOpts(

is_show=true,

位置=\’底部\’,#顶部,左,右,底部,内部,insideLeft,insideRight,insideTop,insideBottom

颜色=\’红色\’,

字体大小=14,

font_family=\’宋体\’,

font_style=\’正常\’,#斜体还是斜体?

font_weight=\’bold\’,#是否加粗

旋转=-30,#旋转角度

),

#标记点设置项

markpoint_opts=opts.MarkPointOpts(

数据=[

opts.MarkPointItem(type_=\’max\’,symbol=\’pin\’,symbol_size=50,),#min,max,average

opts.MarkPointItem(type_=\’min\’,symbol=\’pin\’,symbol_size=50,)

]

),

#标记线

markline_opts=opts.MarkLineOpts(

数据=[

opts.MarkLineItem(type_=\’average\’)

],

label_opts=opts.LabelOpts(

颜色=\’红色\’,

.render(\’line_base.html\’)

笨蛋:

Facker.choose() 随机生成7 个属性相同的名词Facker.values() 随机生成7 个数字Facker.cars() 随机生成7 个汽车名称Facker.country() #随机生成7 个国家Facker.visual_color() #随机生成七种颜色Facker.days_attrs() 星期数字Facker.days_values()# 星期数值Facker. Clock # 时钟列表Facker.animal()Facker.dogs()Facker.clothes()Facker.guangdong_city()Facker .week ()Facker。week_en() 饼图:

来自pyecharts.chartsimportLine

frompyechartsimportoptionsasopts

来自pyecharts.fakerimportFaker

frompyecharts.chartsimport 条形图、线形图、圆图

frompyecharts.globalsimportCurrentConfig、RenderType、ThemeType

CurrentConfig.ONLINE_HOST=\’https://cdn.jsdelivr.net/npm/echarts@latest/dist/\’

列表(zip(Faker.choose(),Faker.values()))

c=(pi()

.add(\’\’,[list(x)forxinzip(Faker.choose(),Faker.values())])

.set_colors([\’红色\’,\’黄色\’,\’绿色\’,\’蓝色\’,\’洋红色\’,\’青色\’,\’黑色\’])

.set_global_opts(

title_opts=opts.TitleOpts(title=\’颜色设置\’,pos_left=\’40%\’),

legend_opts=opts.LegendOpts(type_=\’滚动\’,pos_left=\’80%\’,orient=\’垂直\’,),

.set_series_opts(label_opts=opts.LabelOpts(formatter=\'{b}:{c}\’)

c.render(\’line_base.html\’)

玫瑰图:

来自pyecharts.chartsimportLine

frompyechartsimportoptionsasopts

来自pyecharts.fakerimportFaker

frompyecharts.chartsimport 条形图、线形图、圆图

frompyecharts.globalsimportCurrentConfig、RenderType、ThemeType

CurrentConfig.ONLINE_HOST=\’https://cdn.jsdelivr.net/npm/echarts@latest/dist/\’

列表(zip(Faker.choose(),Faker.values()))

v=Faker.choose()

c=(

馅饼()

.add(\’\’,[列表(i)foriinzip(v,Faker.values())],

radius=[\’30%\’,\’75%\’],#设置饼图的内、外半径

center=[\’25%\’,\’50%\’],#设置饼图在容器内的位置

玫瑰类型=\’Radis\’,

label_opts=opts.LabelOpts(is_show=False),#不显示标签

.add(\’\’,[列表(i)foriinzip(v,Faker.values())],

radius=[\’30%\’,\’75%\’],#设置饼图的内半径和外半径

center=[\’75%\’,\’50%\’],#设置饼图在容器内的位置

玫瑰类型=\’区域\’,

label_opts=opts.LabelOpts(is_show=True),#不显示标签

.set_global_opts(title_opts=opts.TitleOpts(title=\’玫瑰图片\’))

c.render(\’line_base.html\’)

柱形图:

来自pyecharts.chartsimportLine

frompyechartsimportoptionsasopts

来自pyecharts.fakerimportFaker

frompyecharts.chartsimport 条形图、线形图、圆图

frompyecharts.globalsimportCurrentConfig、RenderType、ThemeType

来自pyecharts.commons.utilsimportJsCode

CurrentConfig.ONLINE_HOST=\’https://cdn.jsdelivr.net/npm/echarts@latest/dist/\’

列表(zip(Faker.choose(),Faker.values()))

c=(

酒吧(

init_opts=opts.InitOpts(

Anime_opts=opts.AnimationOpts(

Anime_delay=1000,#动画延迟1m

Anime_easing=\’elasticOut\’#弹性动画

),

背景颜色={

\’图片\’:JsCode(\’img\’),

\’重复\’:\’不重复\’,

}

.add_xaxis(Faker.choose())

.add_yaxis(\’卖家A\’,Faker.values())

.add_yaxis(\’卖家B\’,Faker.values())

.set_global_opts(

title_opts=opts.TitleOpts(

title=\’条形图\’,

subtitle=\’副标题\’,

title_textstyle_opts=opts.TextStyleOpts(

颜色=\’白色\’

),

subtitle_textstyle_opts=opts.TextStyleOpts(

颜色=\’蓝色\’

c.add_js_funcs(

#添加js代码

””

varimg=newImage();

img.src=\’https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimage109.360doc.com%2FDownloadImg%2F2021%2F04%2F0713%2F219519055_1_20210407012803425refer=http%3A%2F%2Fimage1 9 .360doc.comapp=2002大小=f9999,10000q=a80n=0g=0nfmt=auto?sec=1724385822t=e3492f59bfb2c90695ef7bd4520bf09f\’

””

c.render(\’line_base.html\’)

使用JS:

堆条形图:

来自pyecharts.chartsimportLine

frompyechartsimportoptionsasopts

来自pyecharts.fakerimportFaker

frompyecharts.chartsimport 条形图、线形图、圆图

frompyecharts.globalsimportCurrentConfig、RenderType、ThemeType

来自pyecharts.commons.utilsimportJsCode

CurrentConfig.ONLINE_HOST=\’https://cdn.jsdelivr.net/npm/echarts@latest/dist/\’

列表(zip(Faker.choose(),Faker.values()))

c=(

酒吧()

.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=\’条形图\’,

subtitle=\’副标题\’,

),

xaxis_opts=opts.AxisOpts(

axislabel_opts=opts.LabelOpts(rotate=45),#旋转x轴数据

),

datazoom_opts=[

opts.DataZoomOpts(),

opts.DataZoomOpts(type_=\’inside\’,)#鼠标滚轮缩放

]

.set_series_opts(

label_opts=opts.LabelOpts(is_show=False)

c.render(\’line_base.html\’)

条状图:

来自pyecharts.chartsimportLine

frompyechartsimportoptionsasopts

来自pyecharts.fakerimportFaker

frompyecharts.chartsimport 条形图、线形图、圆图

frompyecharts.globalsimportCurrentConfig、RenderType、ThemeType

来自pyecharts.commons.utilsimpor

tJsCode

CurrentConfig.ONLINE_HOST=\”https://cdn.jsdelivr.net/npm/echarts@latest/dist/\”

list(zip(Faker.choose(),Faker.values()))

c=(

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(is_show=True,position=\’right\’)

)

)

c.render(\”line_base.html\”)

控制柱间的距离:

直方图:
frompyecharts.chartsimportLine

frompyechartsimportoptionsasopts

frompyecharts.fakerimportFaker

frompyecharts.chartsimportBar,Line,Pie

frompyecharts.globalsimportCurrentConfig,RenderType,ThemeType

frompyecharts.commons.utilsimportJsCode

CurrentConfig.ONLINE_HOST=\”https://cdn.jsdelivr.net/npm/echarts@latest/dist/\”

list(zip(Faker.choose(),Faker.values()))

c=(

Bar()

.add_xaxis(Faker.choose())

.add_yaxis(\’商家A\’,Faker.values(),category_gap=\’0%\’)#单个系列柱间距

.set_global_opts(

title_opts=opts.TitleOpts(title=\’直方图\’,),

)

.set_series_opts(label_opts=opts.LabelOpts(is_show=False))

)

c.render(\”line_base.html\”)

JsCode自定义柱颜色:
frompyecharts.chartsimportLine

frompyechartsimportoptionsasopts

frompyecharts.fakerimportFaker

frompyecharts.chartsimportBar,Line,Pie

frompyecharts.globalsimportCurrentConfig,RenderType,ThemeType

frompyecharts.commons.utilsimportJsCode

CurrentConfig.ONLINE_HOST=\”https://cdn.jsdelivr.net/npm/echarts@latest/dist/\”

list(zip(Faker.choose(),Faker.values()))

color_func=\”\”\”

function(params){

if(params.value>0&&params.value<80){

return\’red\’}

elseif(params.value>80&&params.value<200){

return\’green\’}

}

\”\”\”

c=(

Bar()

.add_xaxis(Faker.choose())

.add_yaxis(\’商家A\’,

Faker.values(),

category_gap=\’0%\’,

itemstyle_opts=opts.ItemStyleOpts(color=JsCode(color_func))

)#单个系列柱间距

.set_global_opts(

title_opts=opts.TitleOpts(title=\’直方图\’,),

)

.set_series_opts(label_opts=opts.LabelOpts(is_show=False))

)

c.render(\”line_base.html\”)

并行多图:
frompyecharts.chartsimportLine,Scatter,Grid

frompyechartsimportoptionsasopts

frompyecharts.fakerimportFaker

frompyecharts.chartsimportBar,Line,Pie

frompyecharts.globalsimportCurrentConfig,RenderType,ThemeType

frompyecharts.commons.utilsimportJsCode

CurrentConfig.ONLINE_HOST=\”https://cdn.jsdelivr.net/npm/echarts@latest/dist/\”

c=(

Line()

.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(pos_left=\’10%\’),

)

)

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=\’10%\’),

legend_opts=opts.LegendOpts(pos_right=\’20%\’),

)

)

grid=(

Grid()

.add(c,grid_opts=opts.GridOpts(pos_right=\’55%\’))

.add(scatter,grid_opts=opts.GridOpts(pos_left=\’55%\’))

)

grid.render(\”line_base.html\”)

雷达图:
frompyecharts.chartsimportLine,Scatter,Grid,Radar

frompyechartsimportoptionsasopts

frompyecharts.fakerimportFaker

frompyecharts.chartsimportBar,Line,Pie

frompyecharts.globalsimportCurrentConfig,RenderType,ThemeType

frompyecharts.commons.utilsimportJsCode

CurrentConfig.ONLINE_HOST=\”https://cdn.jsdelivr.net/npm/echarts@latest/dist/\”

v1=[[4300,3400,5300,4900,6200,4500]]

v2=[[6500,4300,5200,3600,6200,2900]]

c=(

Radar()

.add_schema(

schema=[opts.RadarIndicatorItem(

name=\’项目1\’,

max_=7000

),

opts.RadarIndicatorItem(

name=\’项目2\’,

max_=7000

),

opts.RadarIndicatorItem(

name=\’项目3\’,

max_=9000

),

opts.RadarIndicatorItem(

name=\’项目4\’,

max_=17000

),opts.RadarIndicatorItem(

name=\’项目5\’,

max_=20000

),

opts.RadarIndicatorItem(

name=\’项目6\’,

max_=30000

)

]

)

.add(\’数据1\’,v1)

.add(\’数据2\’,v2,color=\’blue\’)

)

c.render(\”line_base.html\”)

折线图:
d=(

Line(

init_opts=opts.InitOpts(width=\’1000px\’,height=\’500px\’)

)

.add_xaxis(xaxis_data=Faker.week)

.add_yaxis(series_name=\’\’,

y_axis=[120,200,150,80,70,110,130],

symbol=\’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_width=2,

border_color=\’blue\’,

color=\’red\’

),

#标注点

markpoint_opts=opts.MarkPointOpts(

data=[

opts.MarkPointItem(type_=\’max\’,),#最大值

opts.MarkPointItem(type_=\’min\’)

]

),

#标注线

markline_opts=opts.MarkLineOpts(

data=[

opts.MarkLineItem(

type_=\’average\’,

),

],

),

)

)

面积图:
v1=[\”周一\”,\”周二\”,\”周三\”,\”周四\”,\”周五\”,\”周六\”,\”周日\”]

v2=[650,430,520,360,620,290]

c=(

Line()

.add_xaxis(xaxis_data=v1)

.add_yaxis(\’\’,

y_axis=[650,430,520,360,620,290,500],

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)

)

)

堆叠面积图:
v1=[\”周一\”,\”周二\”,\”周三\”,\”周四\”,\”周五\”,\”周六\”,\”周日\”]

v2=[650,430,520,360,620,290]

c=(

Line()

.add_xaxis(xaxis_data=v1)

.add_yaxis(\’广告\’,

y_axis=[650,430,520,360,620,290,500],

areastyle_opts=opts.AreaStyleOpts(opacity=0.5),#面积图

stack=\’堆叠\’

)

.add_yaxis(\’价格\’,

y_axis=[450,330,220,660,320,690,200],

areastyle_opts=opts.AreaStyleOpts(opacity=0.5),#面积图

stack=\’堆叠\’

)

.add_yaxis(\’商品\’,

y_axis=[4330,3300,2200,6600,3020,6090,2000],

areastyle_opts=opts.AreaStyleOpts(opacity=0.5),#面积图

stack=\’堆叠\’

)

.set_global_opts(

title_opts=opts.TitleOpts(

title=\”面积图\”,

),

tooltip_opts=opts.TooltipOpts(trigger=\’axis\’),

xaxis_opts=opts.AxisOpts(type_=\’category\’,boundary_gap=False)

)

)

 

散点图:
c=(

Scatter()

.add_xaxis(Faker.values())

.add_yaxis(\’C\’,Faker.values(),

symbol=\’square\’,

label_opts=opts.LabelOpts(is_show=True))

.set_global_opts(

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

)

)

)

)

涟漪散点图
c=(

EffectScatter()

.add_xaxis(Faker.choose())

.add_yaxis(

\’\’,

Faker.values(),

symbol=SymbolType.ARROW

)

.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)

)

)

)

热力图:
value=[[i,j,random.randint(0,50)]foriinrange(24)forjinrange(7)]

c=(

HeatMap()

.add_xaxis(Faker.clock)

.add_yaxis(\’热力图\’,

Faker.week,

value,

label_opts=opts.LabelOpts(is_show=True,position=\’inside\’)

)

)

 

日历图:
begin=datetime.date(2023,1,1)

end=datetime.date(2023,12,31)

data=[[str(begin+datetime.timedelta(days=i)),random.randint(1000,25000)]

foriinrange((end-begin).days+1)]

c=(

Calendar()

.add(

\’\’,

data,

calendar_opts=opts.CalendarOpts(

range_=\’2023\’,

daylabel_opts=opts.CalendarDayLabelOpts(name_map=\’cn\’),

monthlabel_opts=opts.CalendarMonthLabelOpts(name_map=\’cn\’),

)

)

.set_global_opts(title_opts=opts.TitleOpts(title=\’2023日历图\’),

visualmap_opts=opts.VisualMapOpts(max_=25000,

min_=1000,

orient=\’horizontal\’,

is_piecewise=True,

pos_left=\’100px\’,

pos_top=\’230px\’)

)

)

 

箱型图:
v1=[[850,450,250,150,250,350,670,360,570,320,357],

[150,450,550,250,650,250,770,220,320,560,337]]

c=(

Boxplot()

.add_xaxis([\’demo1\’,\’demo2\’])

)

c.add_yaxis(\’A\’,c.prepare_data(v1))

 

词云图:

v1=[(\”兔子\”,100),(\”猫\”,88),(\”狗\”,45),(\”仓鼠\”,66),(\”狐狸\”,34),(\”狐2狸\”,14),(\”狐4狸\”,74),(\”狐1狸\”,64),(\”狐4狸\”,35)]

c=(

WordCloud()

.add(

\’分析\’,

data_pair=v1,

word_size_range=[6,50],

textstyle_opts=opts.TextStyleOpts(

font_family=\’cursive\’

)

)

)

漏斗图
c=(

Funnel()

.add(\’商品\’,

[list(i)foriinzip(Faker.choose(),Faker.values())]

)

.set_global_opts(title_opts=opts.TitleOpts(title=\’漏斗图\’))

)

x_data=[\’A\’,\’B\’,\’C\’,\’D\’,\’E\’]

y_data=[100,80,30,60,70]

data=[[x_data[i],y_data[i]]foriinrange(len(x_data))]

c=(

Funnel(init_opts=opts.InitOpts(width=\’600px\’,height=\’400px\’))

.add(\’商品\’,

data_pair=data,

gap=2,#间隙

tooltip_opts=opts.TooltipOpts(

trigger=\’item\’,

formatter=\'{a}<br/>{b}:{c}\’

),

label_opts=opts.LabelOpts(

is_show=True,

position=\’inside\’

)

)

.set_global_opts(title_opts=opts.TitleOpts(title=\’漏斗图\’))

)

 

极坐标图:
data=[(i,random.randint(1,100))for i in range(101)]

c=(

Polar()

.add(

\’极坐标\’,

data,

type_=\’scatter\’,

label_opts=opts.LabelOpts(

is_show=False

)

)

)

c=(

Polar()

.add_schema(

radiusaxis_opts=opts.RadiusAxisOpts(

data=Faker.week,

type_=\’category\’

),

angleaxis_opts=opts.AngleAxisOpts(

is_clockwise=True,

max_=10

)

)

.add(\’商品\’,[1,2,3,4,5,3,2],type_=\’bar\’)

)

c=(

Polar()

.add_schema(

angleaxis_opts=opts.AngleAxisOpts(

data=Faker.week,

type_=\’category\’

),

)

.add(\’商品1\’,[1,2,3,4,5,3,2],type_=\’bar\’)

.add(\’商品2\’,[2,3,1,4,6,3,2],type_=\’bar\’)

.add(\’商品3\’,[4,3,6,7,4,2,4],type_=\’bar\’)

.add(\’商品4\’,[3,5,3,1,4,3,2],type_=\’bar\’)

)

importrandom,datetime

data=[(i,random.randint(1,100))foriinrange(101)]

c=(

Polar()

.add_schema(

radiusaxis_opts=opts.RadiusAxisOpts(

data=Faker.week,

type_=\’category\’

),

)

.add(\’商品1\’,[1,2,3,4,5,3,2],type_=\’bar\’)

.add(\’商品2\’,[2,3,1,4,6,3,2],type_=\’bar\’)

.add(\’商品3\’,[4,3,6,7,4,2,4],type_=\’bar\’)

.add(\’商品4\’,[3,5,3,1,4,3,2],type_=\’bar\’)

)

data=[(i,random.randint(1,100))foriinrange(20)]

c=(

Polar()

.add(

\’极坐标\’,

data,

type_=\’effectScatter\’,

label_opts=opts.LabelOpts(

is_show=False

),

effect_opts=opts.EffectOpts(

scale=10,#涟漪范围大小

period=5#涟漪速度

)

)

)

水球图:
c=(

Liquid()

.add(

\’\’,

[0.6,0.3],

is_outline_show=False,#外边框是否显示

shape=SymbolType.DIAMOND#形状

)

)

桑基图:

nodes=[

{\’name\’:\’c1\’},

{\’name\’:\’c2\’},

{\’name\’:\’c3\’},

{\’name\’:\’c4\’},

{\’name\’:\’c5\’},

{\’name\’:\’c6\’},

{\’name\’:\’c7\’},

{\’name\’:\’c8\’},

]

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\’:\’c5\’,\’target\’:\’c6\’,\’value\’:50},

{\’source\’:\’c6\’,\’target\’:\’c7\’,\’value\’:60},

{\’source\’:\’c7\’,\’target\’:\’c8\’,\’value\’:70},

]

c=(

Sankey()

.add(

\’\’,

nodes,

links,linestyle_opt=opts.LineStyleOpts(

opacity=0.2,#透明度

curve=0.6,#曲线幅度

color=\’red\’

)

)

)

旭日图:

data=[{\”name\”:\”烟\”,\”itemStyle\”:{\”color\”:\”#da0d68\”},

\”children\”:[{\”name\”:\”黄鹤楼\”,\”value\”:10,\”itemStyle\”:{\”color\”:\”#975e6d\”},

\’children\’:[{\”name\”:\”硬\”,\”value\”:2,\”itemStyle\”:{\”color\”:\”#d78823\”}},

{\”name\”:\”软\”,\”value\”:3,\”itemStyle\”:{\”color\”:\”#da5c1f\”}},

{\”name\”:\”1919\”,\”value\”:5,\”itemStyle\”:{\”color\”:\”#f89a80\”}}]},

{\”name\”:\”南京\”,\”value\”:12,\”itemStyle\”:{\”color\”:\”#e0719c\”}},

{\”name\”:\”白鲨\”,\”value\”:15,\”itemStyle\”:{\”color\”:\”#dd4c51\”}},

{\”name\”:\”泰山\”,\”value\”:17,\”itemStyle\”:{\”color\”:\”#c94a44\”}}]},

{\”name\”:\”酒\”,\”itemStyle\”:{\”color\”:\”#c94a44\”},

\”children\”:[{\”name\”:\”茅台\”,\”value\”:7,\”itemStyle\”:{\”color\”:\”#e65656\”}},

{\”name\”:\”五粮液\”,\”value\”:9,\”itemStyle\”:{\”color\”:\”#4eb849\”}},

{\”name\”:\”酒鬼酒\”,\”value\”:21,\”itemStyle\”:{\”color\”:\”#f68a5c\”}},

{\”name\”:\”白云边\”,\”value\”:13,\”itemStyle\”:{\”color\”:\”#baa635\”}}]},

{\”name\”:\”茶\”,\”itemStyle\”:{\”color\”:\”##ebb40f\”},

\”children\”:[{\”name\”:\”大红袍\”,\”value\”:3,\”itemStyle\”:{\”color\”:\”#e2631e\”}},

{\”name\”:\”碧螺春\”,\”value\”:6,\”itemStyle\”:{\”color\”:\”#fde404\”}},

{\”name\”:\”毛尖\”,\”value\”:12,\”itemStyle\”:{\”color\”:\”#7eb138\”}},

{\”name\”:\”白茶\”,\”value\”:15,\”itemStyle\”:{\”color\”:\”#d0b24f\”}}]}

]

c=(Sunburst(init_opts=opts.InitOpts(width=\”1000px\”,height=\”600px\”))

.add(

\”\”,

data_pair=data,

highlight_policy=\”ancestor\”,

radius=[0,\”95%\”],

sort_=\”null\”,

levels=[

{},

{

\”r0\”:\”15%\”,

\”r\”:\”35%\”,

\”itemStyle\”:{\”borderWidth\”:2},

\”label\”:{\”rotate\”:\”tangential\”},

},

{\”r0\”:\”35%\”,\”r\”:\”70%\”,\”label\”:{\”align\”:\”right\”}},

{

\”r0\”:\”70%\”,

\”r\”:\”72%\”,

\”label\”:{\”position\”:\”outside\”,\”padding\”:3,\”silent\”:False},

\”itemStyle\”:{\”borderWidth\”:3},

},

],

)

.set_global_opts(title_opts=opts.TitleOpts(title=\”旭日图\”),)

.set_series_opts(label_opts=opts.LabelOpts(formatter=\”{b}\”))

)

仪表盘
c=(

Gauge()

.add(\”销售额\”,

[(\’\’,60)],

radius=\’60%\’

)

)

树图:
data=[

{

\”children\”:[

{\”name\”:\”B\”},

{

\”children\”:[{\”children\”:[{\”name\”:\”I\”}],\”name\”:\”E\”},{\”name\”:\”F\”}],

\”name\”:\”C\”,

},

{

\”children\”:[

{\”children\”:[{\”name\”:\”J\”},{\”name\”:\”K\”}],\”name\”:\”G\”},

{\”name\”:\”H\”},

],

\”name\”:\”D\”,

},

],

\”name\”:\”A\”,

}

]

c=(

Tree()

.add(\”\”,

data,)

.set_global_opts(title_opts=opts.TitleOpts(title=\’树图\’))

)

矩形树图
data=[

{\’value\’:40,\’name\’:\’伯伯\’},

{

\’value\’:180,

\’name\’:\’父亲\’,

\’children\’:[

{\’value\’:12,\’name\’:\’大儿子\’},

{\’value\’:23,\’name\’:\’二儿子\’},

{\’value\’:24,\’name\’:\’三儿子\’},

{\’value\’:34,\’name\’:\’四儿子\’},

]

}

]

c=(

TreeMap()

.add(\’\’,data)

)

关系图1:
data=[

{\’name\’:\’node1\’,\’symbolSize\’:10},

{\’name\’:\’node2\’,\’symbolSize\’:20},

{\’name\’:\’node3\’,\’symbolSize\’:30},

{\’name\’:\’node4\’,\’symbolSize\’:40},

{\’name\’:\’node5\’,\’symbolSize\’:50},

{\’name\’:\’node6\’,\’symbolSize\’:30},

{\’name\’:\’node7\’,\’symbolSize\’:40},

{\’name\’:\’node8\’,\’symbolSize\’:20},

]

links=[]

foriindata:

forjindata:

links.append({\’source\’:i.get(\’name\’),\’target\’:j.get(\’name\’)})

c=(

Graph()

.add(\’\’,data,links,repulsion=8000#排斥力,越大分的越开

)

)

关系图2:
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),

]

links_data=[

opts.GraphLink(source=\’node1\’,target=\’node2\’,value=2),

opts.GraphLink(source=\’node2\’,target=\’node3\’,value=3),

opts.GraphLink(source=\’node3\’,target=\’node4\’,value=4),

opts.GraphLink(source=\’node4\’,target=\’node5\’,value=5),

opts.GraphLink(source=\’node5\’,target=\’node6\’,value=6),

opts.GraphLink(source=\’node6\’,target=\’node1\’,value=7),

]

c=(

Graph()

.add(\’\’,

nodes_data,

links_data,

repulsion=5000,#排斥力,越大分的越开

edge_label=opts.LabelOpts(

is_show=True,

position=\’middle\’

)

)

)

关系图3:

c=(

Graph()

.add(\’\’,

nodes=nodes,

links=links,

categories=categories,

layout=\’circular\’,#布局方式圆

is_rotate_label=True,

linestyle_opts=opts.LineStyleOpts(color=\’source\’,#使用节点颜色

curve=0.3#曲度

)

)

)

K线图
data=[

[2320.26,2320.26,2287.3,2362.94],

[2300,2291.3,2288.26,2308.38],

[2295.35,2346.5,2295.35,2345.92],

[2347.22,2358.98,2337.35,2363.8],

[2360.75,2382.48,2347.89,2383.76],

[2383.43,2385.42,2371.23,2391.82],

[2377.41,2419.02,2369.57,2421.15],

[2425.92,2428.15,2417.58,2440.38],

[2411,2433.13,2403.3,2437.42],

[2432.68,2334.48,2427.7,2441.73],

[2430.69,2418.53,2394.22,2433.89],

[2416.62,2432.4,2414.4,2443.03],

[2441.91,2421.56,2418.43,2444.8],

[2420.26,2382.91,2373.53,2427.07],

[2383.49,2397.18,2370.61,2397.94],

[2378.82,2325.95,2309.17,2378.82],

[2322.94,2314.16,2308.76,2330.88],

[2320.62,2325.82,2315.01,2338.78],

[2313.74,2293.34,2289.89,2340.71],

[2297.77,2313.22,2292.03,2324.63],

[2322.32,2365.59,2308.92,2366.16],

[2364.54,2359.51,2330.86,2369.65],

[2332.08,2273.4,2259.25,2333.54],

[2274.81,2326.31,2270.1,2328.14],

[2333.61,2347.18,2321.6,2351.44],

[2340.44,2324.29,2304.27,2352.02],

[2326.42,2318.61,2314.59,2333.67],

[2314.68,2310.59,2296.58,2320.96],

[2309.16,2286.6,2264.83,2333.29],

[2282.17,2263.97,2253.25,2286.33],

[2255.77,2270.28,2253.31,2276.22],

]

 

c=(

Kline()

.add_xaxis([\’2017/1/{}\’.format(i+1)foriinrange(31)])

.add_yaxis(\’K线图\’,data)

)

 

地图:
c=(

Map()

.add(

\’\’,

[list(i)foriinzip(Faker.guangdong_city,Faker.values())],

\’广东\’

)

.set_global_opts(

visualmap_opts=opts.VisualMapOpts(

max_=200,

is_piecewise=True,

)

)

)

地理坐标图:
c=(

Geo()

.add_schema(maptype=\’china\’)

.add(

\’geo\’,

[list(i)foriinzip(Faker.provinces,Faker.values())],

type_=ChartType.EFFECT_SCATTER

)

.set_series_opts(label_opts=opts.LabelOpts(is_show=True))

)

c=(

Geo()

.add_schema(maptype=\’china\’)

.add(

\’geo\’,

[(\’广州\’,50),(\’重庆\’,80),(\’北京\’,60),(\’杭州\’,70)],

type_=ChartType.EFFECT_SCATTER

)

.add(

\’\’,

[(\’广州\’,\’上海\’),(\’广州\’,\’北京\’),(\’广州\’,\’杭州\’),(\’广州\’,\’重庆\’)],

type_=ChartType.LINES,

effect_opts=opts.EffectOpts(

symbol=SymbolType.ARROW,

symbol_size=6,

color=\’blue\’

),

linestyle_opts=opts.LineStyleOpts(curve=0.2)

)

.set_series_opts(label_opts=opts.LabelOpts(is_show=False))

)

3D折线图:
hours=[

\”12a\”,

\”1a\”,

\”2a\”,

\”3a\”,

\”4a\”,

\”5a\”,

\”6a\”,

\”7a\”,

\”8a\”,

\”9a\”,

\”10a\”,

\”11a\”,

\”12p\”,

\”1p\”,

\”2p\”,

\”3p\”,

\”4p\”,

\”5p\”,

\”6p\”,

\”7p\”,

\”8p\”,

\”9p\”,

\”10p\”,

\”11p\”,

]

days=[\”Saturday\”,\”Friday\”,\”Thursday\”,\”Wednesday\”,\”Tuesday\”,\”Monday\”,\”Sunday\”]

data=[

[0,0,5],

[0,1,1],

[0,2,0],

[0,3,0],

[0,4,0],

[0,5,0],

[0,6,0],

[0,7,0],

[0,8,0],

[0,9,0],

[0,10,0],

[0,11,2],

[0,12,4],

[0,13,1],

[0,14,1],

[0,15,3],

[0,16,4],

[0,17,6],

[0,18,4],

[0,19,4],

[0,20,3],

[0,21,3],

[0,22,2],

[0,23,5],

[1,0,7],

[1,1,0],

[1,2,0],

[1,3,0],

[1,4,0],

[1,5,0],

[1,6,0],

[1,7,0],

[1,8,0],

[1,9,0],

[1,10,5],

[1,11,2],

[1,12,2],

[1,13,6],

[1,14,9],

[1,15,11],

[1,16,6],

[1,17,7],

[1,18,8],

[1,19,12],

[1,20,5],

[1,21,5],

[1,22,7],

[1,23,2],

[2,0,1],

[2,1,1],

[2,2,0],

[2,3,0],

[2,4,0],

[2,5,0],

[2,6,0],

[2,7,0],

[2,8,0],

[2,9,0],

[2,10,3],

[2,11,2],

[2,12,1],

[2,13,9],

[2,14,8],

[2,15,10],

[2,16,6],

[2,17,5],

[2,18,5],

[2,19,5],

[2,20,7],

[2,21,4],

[2,22,2],

[2,23,4],

[3,0,7],

[3,1,3],

[3,2,0],

[3,3,0],

[3,4,0],

[3,5,0],

[3,6,0],

[3,7,0],

[3,8,1],

[3,9,0],

[3,10,5],

[3,11,4],

[3,12,7],

[3,13,14],

[3,14,13],

[3,15,12],

[3,16,9],

[3,17,5],

[3,18,5],

[3,19,10],

[3,20,6],

[3,21,4],

[3,22,4],

[3,23,1],

[4,0,1],

[4,1,3],

[4,2,0],

[4,3,0],

[4,4,0],

[4,5,1],

[4,6,0],

[4,7,0],

[4,8,0],

[4,9,2],

[4,10,4],

[4,11,4],

[4,12,2],

[4,13,4],

[4,14,4],

[4,15,14],

[4,16,12],

[4,17,1],

[4,18,8],

[4,19,5],

[4,20,3],

[4,21,7],

[4,22,3],

[4,23,0],

[5,0,2],

[5,1,1],

[5,2,0],

[5,3,3],

[5,4,0],

[5,5,0],

[5,6,0],

[5,7,0],

[5,8,2],

[5,9,0],

[5,10,4],

[5,11,1],

[5,12,5],

[5,13,10],

[5,14,5],

[5,15,7],

[5,16,11],

[5,17,6],

[5,18,0],

[5,19,5],

[5,20,3],

[5,21,4],

[5,22,2],

[5,23,0],

[6,0,1],

[6,1,0],

[6,2,0],

[6,3,0],

[6,4,0],

[6,5,0],

[6,6,0],

[6,7,0],

[6,8,0],

[6,9,0],

[6,10,1],

[6,11,0],

[6,12,2],

[6,13,1],

[6,14,3],

[6,15,4],

[6,16,0],

[6,17,0],

[6,18,0],

[6,19,0],

[6,20,1],

[6,21,2],

[6,22,2],

[6,23,6],

]

data=[[d[1],d[0],d[2]]fordindata]

c=(

Line3D()

.add(

\’\’,

data,

xaxis3d_opts=opts.Axis3DOpts(type_=\”category\”,data=hours),

yaxis3d_opts=opts.Axis3DOpts(type_=\”category\”,data=days),

zaxis3d_opts=opts.Axis3DOpts(type_=\”value\”),

grid3d_opts=opts.Grid3DOpts(

width=100,

depth=100,

rotate_speed=50,

is_rotate=True,

)

)

.set_global_opts(

visualmap_opts=opts.VisualMapOpts(

is_show=True,

max_=30,

min_=0,

),

)

)

3D柱状图
data=[(i,j,random.randint(0,12))foriinrange(6)forjinrange(24)]

c=(

Bar3D()

.add(

\’\’,

[[d[1],d[0],d[2]]fordindata],

xaxis3d_opts=opts.Axis3DOpts(Faker.clock,type_=\’category\’),

yaxis3d_opts=opts.Axis3DOpts(Faker.week,type_=\’category\’),

)

.set_global_opts(

visualmap_opts=opts.VisualMapOpts(

is_show=True,

max_=15,

min_=0,

)

)

)

时间轮播图

#以上关于PyEcharts知识点详解(每张图都有!)的相关内容来源网络仅供参考,相关信息请以官方公告为准!

原创文章,作者:CSDN,如若转载,请注明出处:https://www.sudun.com/ask/93899.html

(0)
CSDN's avatarCSDN
上一篇 2024年7月26日 下午1:39
下一篇 2024年7月26日 下午1:39

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注