目录

1. PyEcharts:初始化配置、全局配置项(标题配置、缩放配置)

2. PyEcharts:全局配置项(图例配置项、视觉映射配置项、提示框配置项、坐标轴配置项)

3. PyEcharts:系列配置项(图元样式配置项、线条样式配置项、标签配置项、标记点配置项、标记线配置项)

4. PyEcharts:使用Faker得到数据

5. PyEcharts:饼图

6. PyEcharts:玫瑰图

7. PyEcharts:柱形图

8. PyEcharts:堆叠柱形图

9. PyEcharts:条形图

10. PyEcharts:直方图

11. PyEcharts:象形柱状图

12. PyEcharts:雷达图

13. PyEcharts:折线图

14. PyEcharts:面积图

15. PyEcharts:散点图

16. PyEcharts:涟漪散点图

17. PyEcharts:热力图

18. PyEcharts:日历图

19. PyEcharts:箱型图

20. PyEcharts:词云图

21. PyEcharts:漏斗图

22. PyEcharts:极坐标图

23. PyEcharts:水球图

24. PyEcharts:涟漪散点图

25. PyEcharts:桑基图

26. PyEcharts:旭日图

27. PyEcharts:仪表盘

28. PyEcharts:树图

29. PyEcharts:矩形树图

30. PyEcharts:关系图

31. PyEcharts:K线图

32. PyEcharts:地图

33. PyEcharts:地理坐标图

34. PyEcharts:3D折线图

35. PyEcharts:3D柱状图

36. PyEcharts:时间轮播多图

37. PyEcharts:多图布局

38. PyEcharts:天猫订单数据可视化

39. PyEcharts:双十一销售数据可视化


视频连接:千锋教育PyEcharts数据可视化快速入门教程,大数据分析Python交互绘图实用利器_哔哩哔哩_bilibili

1. PyEcharts:初始化配置、全局配置项(标题配置、缩放配置

初始化配置项:InitOpts
编号 参数 功能 附加
1 width 图片画布的宽度 css长度单位
2 height 图片画布的高度
3 renderer 渲染风格,默认CANVAS,默认即可 SVG
4 page_title 网页标题
5 theme 图片主题
6 bg_color 背景颜色
全局配置项(标题配置项:TitleOpts)
编号 参数 功能 附加
1 title 设置主标题
2 title_link 设置主标题连接,点击主标题触发
3 title_target 点击主标题,是否创建新的窗口,默认创建

blank(默认)

self

4 subtitle 设置副标题
5 subtitle_target 点击主标题,是否创建新的窗口,默认创建

blank(默认)

self

6 pos_left 标题距离画布左边的距离(几种输入方式,看下边程序)

right

top

bottom

7 padding 标题距离画布的内边距
8 item_gap 主标题和副标题之间的间距
全局配置项(区域缩放置项:DataZoomOpts)
编号 参数 功能 附加
1 is_show 是否显示下方拖拽条
2 type_ 拖拽条的方式

slider(拖拽条)

inside(鼠标滚轮)

3 is_realtime 拖拽时是否实时更新
4 range_start 数据窗口起始位置 百分比数据
5 range_end 数据窗口终点位置 百分比数据
6 orient 拖拽条布置的方式

horizontal(水平布置)

vertical(竖直布置)

7 is_zoom_lock

是否锁定选择区域,

只能拖拽不能滚轮

slider(拖拽条可用)

inside(鼠标滚轮不可用)

from pyecharts.charts import Bar
from pyecharts import options as opts
from pyecharts.faker import Faker
from pyecharts.globals import ThemeType, RenderTypec = (Bar(#InitOpts:初始化配置项init_opts=opts.InitOpts(width='700px',   # 图表画布大小,css长度单位height='400px',renderer=RenderType.CANVAS,    # 渲染风格,这是默认,CANVAS/SVGpage_title='网页标题',theme=ThemeType.WHITE,    # 主题bg_color='white',          # 背景色)).add_xaxis(Faker.choose())    #生成同一属性7个值.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',   # 默认blank,默认新窗口打开。self:当前窗口打开。对应上边的连接pos_left='20px',# pos_left='20%'  # 画布的20%# pos_left='left'   # left,right,center# pos_right# pos_bottompadding=10,   # 内边距item_gap=10,  # 主副标题之间的间隙),# 区域缩放配置项datazoom_opts=opts.DataZoomOpts(is_show=True,  # 是否显示缩放组件,处理横坐标下边,数据非常多type_='slider',  # 组件,拖拽条的默认。还有inside:用鼠标滚轮缩放is_realtime=True,  # 拖动的时候是否实时更新图表,默认range_start=20,   # 数据窗口的起始位置,是一个百分比数据range_end=80,     # 数据窗口的结束位置,是一个百分比数据orient='horizontal', # 拖拽条的默认位置。vertical:垂直放置is_zoom_lock=True,  # 是否锁定选择区域,只能拖拽不能平移))
)
c.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0425\0425_6.html')

成品图片

2. PyEcharts:全局配置项(图例配置项视觉映射配置项、提示框配置项、坐标轴配置项)

全局配置项(图例配置项:legend_opts)
编号 参数 功能 附加
1
type_
图例类型
plain(默认):普通图例
scroll:滚动翻页图例(图例数量多)
2
is_show
图例是否显示
3
pos_left
图例位置
pos_left='20px'
pos_left='left'。left,right,centerpos_right
pos_bottom
pos_top
4
orient
图例放置位置
horizontal:水平放置
vertical:垂直放置
5
selected_mode
选择模式
Ture:开启图例点击
False:关闭图例点击
single:单选
multiple:多选
6
align
文字和图标的位置
auto、left、right
7
padding
内边距
8
item_gap
图例之间的间隙
9
item_width
图例宽度
10
item_height
图例高度
11
inactive_color
图例关闭时的颜色
默认#ccc:灰色
12
legend_icon
图例图标形状
circle
rect(矩形)
roundRect(带圆角矩形)
triangle(三角形)
diamond(菱形)
arrow(箭头)
自定义图标路径也可以
全局配置项(视觉映射配置项:visualmap_opts)
编号 参数 功能 附加
1
is_show
是否显示颜色条
2
type_
类型选择
color(默认)
size
3
min_
type_最小值
4 max_ type_最大值
5
range_opacity
全局透明度
6
range_text
颜色条上下文本 列表
7
range_color
自定义过度颜色
列表
8
orient
视觉映射的位置
horizontal:水平放置
vertical:垂直放置
9
pos_right
颜色条位置 pos_left='20px'
pos_left='left'。left,right,center

pos_right
pos_bottom
pos_top

10
is_piecewise
是否把视觉映射分段
11
is_inverse
是否翻转视觉映射
全局配置项(提示框配置项:tooltip_opts)
编号 参数 功能 附加
1
is_show
是否显示提示框
2
trigger
触发类型
item(默认):数据项。一般用于:散点图,柱形图,饼图
axis:坐标轴,提示线。一般用于:条形图,折线图
3
trigger_on
触发条件
mousemove
click
mousemove|click
4
is_show_content
是否显示提示悬浮框
5
formatter
标签内容格式
字符串中的模板变量:
{a}:系列名series_name
{b}:数据名
{c}:值
6
background_color
背景颜色
7
border_color
边框颜色
8
border_width
边框宽度
全局配置项(坐标轴配置项:x/yaxis_opts)
编号 参数 功能 附加
1
is_show
是否显示坐标轴
2
axisline_opts
是否显示坐标线
3
axistick_opts
是否显示坐标刻度值
4
type_
坐标轴类型
value:数值轴,连续数据
category:类目轴,离散数据
time:时间轴,适用于连续的时间,时序数据
from pyecharts.charts import Bar
from pyecharts import options as opts
from pyecharts.faker import Faker
from pyecharts.globals import ThemeType, RenderTypec = (Bar(# InitOpts:初始化配置项init_opts=opts.InitOpts(width='700px',  # 图表画布大小,css长度单位height='400px',renderer=RenderType.CANVAS,  # 渲染风格,这是默认,CANVAS/SVGpage_title='网页标题',theme=ThemeType.WHITE,  # 主题bg_color='white',  # 背景色)).add_xaxis(Faker.choose())  # 生成同一属性7个值.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',  # 默认blank,默认新窗口打开。self:当前窗口打开。对应上边的连接pos_left='20px',# pos_left='20%'  # 画布的20%# pos_left='left'   # left,right,center# pos_right# pos_bottompadding=10,  # 内边距item_gap=10,  # 主副标题之间的间隙),# 区域缩放配置项datazoom_opts=opts.DataZoomOpts(is_show=True,  # 是否显示缩放组件,处理横坐标下边,数据非常多type_='slider',  # 组件,拖拽条的默认。还有inside:用鼠标滚轮缩放is_realtime=True,  # 拖动的时候是否实时更新图表,默认range_start=20,  # 数据窗口的起始位置,是一个百分比数据range_end=80,  # 数据窗口的结束位置,是一个百分比数据orient='horizontal',  # 拖拽条的默认位置。vertical:垂直放置is_zoom_lock=True,  # 是否锁定选择区域,只能拖拽不能平移),# 图例配置项legend_opts=opts.LegendOpts(type_='plain',  # 图例类型,plain(默认):普通图例。scroll:滚动翻页的图例(图例数量多)---->商家A和商家Bis_show=True,  # 图例是否显示pos_left='20%',  # 画布的20%# pos_left='20px',# pos_left='left'   # left,right,center# pos_right# pos_bottomorient='horizontal',  # 图例的默认位置。vertical:垂直放置# Ture:开启图例点击# False:关闭图例点击# single:单选# multiple:多选selected_mode='multiple',  # 选择模式align='right',   # 文字和图标的位置,默认auto=leftpadding=10,      # 内边距item_gap=5,      # 图例之间的间隙item_width=30,   # 图例的宽度item_height=30,  # 图例的高度inactive_color='#ccc',   # 图例关闭的时候,默认#ccc:灰色# PyEcharts 常见的图标:circle,rect(矩形),roundRect(带圆角矩形),#                    triangle(三角形),diamond(菱形),arrow(箭头)# 自定义的图标的路径也可以legend_icon='roundRect',),# 视觉映射配置项visualmap_opts=opts.VisualMapOpts(is_show=True,      # 是否显示颜色条type_='color',     # 类型选择:color或者sizemin_=0,       # 针对于type_max_=100,     # 默认100range_opacity=0.5,  # 全局透明度:是所有都透明range_text=['max', 'min'],   # 两端的文本,type_='color', 不用数字显示,变成设定的参数range_color=['blue', 'green', 'red'],   # 自定义过度颜色orient='vertical',  # 视觉映射的位置。vertical:垂直放置。horizontal:水平放置pos_right='5%',pos_top='5%',is_piecewise=True,   # 是否把视觉映射分段is_inverse=True,   # 是否翻转视觉映射),# 提示框配置项tooltip_opts=opts.TooltipOpts(is_show=True,      # 是否显示提示框# 触发类型# item(默认):数据项,一般用于:散点图,柱形图,饼图# axis:坐标轴,提示线,一般用于:条形图,折线图trigger='item',# 触发条件# mousemove,click,mousemove|clicktrigger_on='mousemove|click',is_show_content=True,   # 是否显示提示悬浮框# 标签内容的格式# 字符串中的模板变量:# {a}:系列名series_name# {b}:数据名# {c}:值formatter='{a}:{b} - {c}',background_color='black',  # 背景颜色border_color='white',   # 边框颜色border_width=1,         # 边框宽度),# 坐标轴配置项xaxis_opts=opts.AxisOpts(is_show=True,      # 是否显示X轴# 坐标轴类型# value:数值轴,连续数据# category:类目轴,离散数据,比如星期一、星期二# time:时间轴,适用于连续的时间,时序数据type_='category'),yaxis_opts=opts.AxisOpts(is_show=False,    # 包含下边的两个axisline_opts=opts.AxisLineOpts(is_show=False),   # Y轴不显示axistick_opts=opts.AxisTickOpts(is_show=False),   # Y轴刻度不显示))
)
c.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0426\0426_1.html')

成品图片

3. PyEcharts:系列配置项(图元样式配置项、线条样式配置项、标签配置项、标记点配置项、标记线配置项)

系列配置项(图元样式配置项:itemstyle_opts)
编号 参数 功能 附加
1
color
图元颜色
可以纯色,可以RGB
RGB,rgb(120,120,120)
RGBA,rgba(120,120,120,0.5)
最后一项为透明度十六进制: #ccc
2
opacity
透明度单独设置
3
border_color
数据点边框颜色
4
border_width
数据点边框宽度
系列配置项(线条样式配置项:linestyle_opts)
编号 参数 功能 附加
1
is_show
是否显示线条
2
width
线条宽度
3
color
线的颜色
4
type_
线型
solid(实线)
dashed(虚线)
dotted(点线)
系列配置项(标签配置项:label_opts)
编号 参数 功能 附加
1       
is_show
是否显示标签数据
2
position
标签数据位置
top,left,right,bottom
inside,insideLeft,insideRight,
insideTop,insideBottom
3
color
标签数据颜色
4
font_size
标签数据字体大小
5
font_family
标签数据字体
6
font_style
标签数据字体风格
italic(斜体)
7
font_weight
标签数据字体风格
bold(加粗)
8
rotate
标签
旋转 (-90,90)
顺负逆正
系列配置项(标记点配置项:markpoint_opts)
编号 参数 参数 功能 附加 格式
date
opts.MarkPointItem
type_
特殊标记类型
min
max
average
列表
symbol
标记形状默认就好
pin
symbol_size
标记大小
系列配置项(标记线配置项:markline_opts)
编号 参数 参数 功能 附加 格式
data
opts.MarkLineItem
type_
特殊标记类型
min
max
average
列表
name
标记名字
label_opts
opts.LabelOpts
color
标签数据颜色
from pyecharts.charts import Line
from pyecharts import options as opts
from pyecharts.faker import Faker
from pyecharts.globals import ThemeType, RenderTypec = (Line(init_opts=opts.InitOpts(width='700px',height='400px')).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(color='blue',# 可以纯色,可以RGB# RGB,rgb(120,120,120)# RGBA,rgba(120,120,120,0.5) 最后一项为透明度# 十六进制: #cccopacity=0.6,   # 透明度单独设置border_color='green',  # 数据点边框颜色border_width=2,  # 数据点边框宽度),# 线条样式配置项linestyle_opts=opts.LineStyleOpts(is_show=True,  # 是否显示线条width=2,    # 线条宽度color='green',  # 线的颜色type_='dashed',   # 线型:solid(实线),dashed(虚线),dotted(点线)),# 标签配置项label_opts=opts.LabelOpts(is_show=True,  # 是否显示标签数据# 标签数据位置:top,left,right,bottom#             inside,insideLeft,insideRight,insideTop,insideBottomposition='top',  # 标签数据位置color='red',  # 标签数据颜色font_size=14,  # 标签数据字体大小font_family='Arial',  # 标签数据字体font_style='normal',     # 标签数据字体风格。italic(斜体)font_weight='normal',    # 标签数据字体风格。bold(加粗)# 标签旋转 -90,90 , 顺负逆正rotate=-40),# 标记点配置项markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(# type_:特殊标记类型,min,max,averagetype_='max',symbol='pin',   # 标记形状,默认就好symbol_size=50   # 标记大小),opts.MarkPointItem(# type_:特殊标记类型,min,max,averagetype_='min',symbol='pin',   # 标记图形,默认就好symbol_size=50   # 标记点大小)],),# 标记线配置项markline_opts=opts.MarkLineOpts(data=[opts.MarkLineItem(type_='average',name='平均值'    # 标记名字)],label_opts=opts.LabelOpts(color='red'  # 标签数据颜色)))
)
c.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0426\0426_2.html')

成品图片

4. PyEcharts:使用Faker得到数据

from pyecharts.faker import Fakerprint("Faker.choose():\n", Faker.choose(), '\n')   # 随机产生7个同属性的名词
print("Faker.values():\n", Faker.values(), '\n')   # 随机产生7个数字
print("Faker.cars:\n", Faker.cars, '\n')   # 生成7个车名
print("Faker.country:\n", Faker.country, '\n')   # 生成7个国家
print("Faker.visual_color:\n", Faker.visual_color, '\n')   # 生成颜色
print("Faker.days_attrs:\n", Faker.days_attrs, '\n')   # 生成0到29天
print("Faker.days_values:\n", Faker.days_values, '\n')   # 0到29天数据的随机排列
print("Faker.clock:\n", Faker.clock, '\n')   # 时钟的列表
print("Faker.animal:\n", Faker.animal, '\n')   # 生成动物
print("Faker.dogs:\n", Faker.dogs, '\n')   # 生成狗
print("Faker.clothes:\n", Faker.clothes, '\n')   # 生成衣服
print("Faker.guangdong_city:\n", Faker.guangdong_city, '\n')   # 生成广东城市
print("Faker.week:\n", Faker.week, '\n')   # 生成中文星期
print("Faker.week_en:\n", Faker.week_en, '\n')   # 生成英文星期

成品图片:输出结果

5. PyEcharts:饼图

from pyecharts.charts import Pie
import pyecharts.options as opts
from pyecharts.faker import Faker
# 饼图
c = (Pie().add('', [list(x) for x 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}')))
c.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0427\0427_1.html')

成品图片

6. PyEcharts:玫瑰图

from pyecharts.charts import Pie
import pyecharts.options as opts
from pyecharts.faker import Faker# 玫瑰图
v = Faker.choose()
c = (Pie().add('', [list(x) for x in zip(v, Faker.values())],radius=['30%', '75%'],  # 中间空心白圆的百分比,外边圆的百分比center=['30%', '50%'],  # x轴百分比,y轴百分比rosetype='radius',label_opts=opts.LabelOpts(is_show=False)    # 不显示标签).add('', [list(x) for x in zip(v, Faker.values())],radius=['20%', '55%'],  # 中间空心白圆的百分比,外边圆的百分比center=['75%', '50%'],  # x轴百分比,y轴百分比rosetype='area',label_opts=opts.LabelOpts(is_show=True)  # 显示标签).set_global_opts(title_opts=opts.TitleOpts(title='玫瑰图')).set_series_opts(label_opts=opts.LabelOpts(formatter='{b}:{c}')))
c.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0427\0427_2.html')

成品图片

7. PyEcharts:柱形图

from pyecharts.charts import Bar
import pyecharts.options as opts
from pyecharts.faker import Faker
from pyecharts.globals import ThemeType# 带动画柱形图
c = (Bar(init_opts=opts.InitOpts(animation_opts=opts.AnimationOpts(animation_delay=5000,  # 动画延时5秒钟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='柱形图',subtitle='我是副标题'))
)
c.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0427\0427_3.html')

成品图片

8. PyEcharts:堆叠柱形图

from pyecharts.charts import Bar
import pyecharts.options as opts
from pyecharts.faker import Faker
from pyecharts.globals import ThemeType# 堆叠柱形图
c = (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='堆叠柱形图',subtitle='我是副标题'),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(is_show=True))
)
c.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0427\0427_4.html')

成品图片

9. PyEcharts:条形图

from pyecharts.charts import Bar
import pyecharts.options as opts
from pyecharts.faker import Faker
from pyecharts.globals import ThemeType
from pyecharts.commons.utils import JsCode# 条形图
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(position='right')))
c.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0427\0427_5.html')

成品图片

10. PyEcharts:直方图

from pyecharts.charts import Bar
import pyecharts.options as opts
from pyecharts.faker import Faker
from pyecharts.globals import ThemeType
from pyecharts.commons.utils import JsCode# 直方图
c = (Bar().add_xaxis(Faker.choose()).add_yaxis('商家A', Faker.values(), category_gap=0)  # 单系列柱子间的距离.set_global_opts(title_opts=opts.TitleOpts(title='直方图'),)
)
c.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0427\0427_6.html')

成品图片

11. PyEcharts:象形柱状图

from pyecharts.charts import PictorialBar
import pyecharts.options as opts
from pyecharts.faker import Faker
from pyecharts.globals import ThemeTypelocation = ['山西', '四川', '西藏', '北京', '上海', '内蒙古', '云南', '黑龙江', '广州', '福建']
values = [13, 42, 67, 81, 86, 94, 166, 220, 249, 262]# 象形柱状图
c = (PictorialBar().add_xaxis(location).add_yaxis('',values,label_opts=opts.LabelOpts(is_show=False),symbol_repeat='fixed',  # 重复方式symbol_size=16,   # 符号的大小is_symbol_clip=True   # 裁剪).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.AxisTickOpts(is_show=False),  # 不显示y轴刻度axisline_opts=opts.AxisLineOpts(is_show=False),  # 不显示y线))
)
c.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0427\0427_8.html')

成品图片

12. PyEcharts:雷达图

from pyecharts.charts import Radar
import pyecharts.options as opts# 雷达图
v1 = [[4300, 10000, 28000, 35000, 50000, 19000]]
v2 = [[5000, 14000, 28000, 31000, 42000, 21000]]
c = (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)]).add('数据1', v1, color='red').add('数据2', v2, color='green').set_series_opts(label_opts=opts.LabelOpts(is_show=False))  # 标签不显示
)
c.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0428\0428_1.html')

成品图片

13. PyEcharts:折线图

from pyecharts.charts import Line
import pyecharts.options as opts
from pyecharts.faker import Faker# 折线图
c = (Line(init_opts=opts.InitOpts(width='1000px', height='500px')).add_xaxis(Faker.week).add_yaxis('', [120, 200, 150, 80, 70, 110, 130],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_width=2,border_color='blue',color='pink'),# 标注点markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_='max'),  # 最大值opts.MarkPointItem(type_='min'),  # 最小值]),# 标注线markline_opts=opts.MarkLineOpts(data=[opts.MarkLineItem(type_='average')  # 平均值]),tooltip_opts=opts.TooltipOpts(trigger='axis')  # 提示线).set_global_opts(title_opts=opts.TitleOpts(title='折线图'),# 提示线tooltip_opts=opts.TooltipOpts(trigger='axis'),yaxis_opts=opts.AxisOpts(type_='value',splitline_opts=opts.SplitLineOpts(is_show=False)  # y轴网格横线关闭),xaxis_opts=opts.AxisOpts(splitline_opts=opts.SplitLineOpts(is_show=False)  # x轴网格横线关闭),))
c.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0428\0428_2.html')

成品图片

14. PyEcharts:面积图

from pyecharts.charts import Line
import pyecharts.options as opts
from pyecharts.faker import Fakerc = (Line().add_xaxis(Faker.week).add_yaxis('广告',stack='堆叠',y_axis=[820, 932, 901, 934, 1290, 1330, 1320],areastyle_opts=opts.AreaStyleOpts(opacity=0.5    # 透明度设置),label_opts=opts.LabelOpts(is_show=False)).add_yaxis('销售',stack='堆叠',y_axis=[1000, 950, 950, 980, 290, 330, 320],areastyle_opts=opts.AreaStyleOpts(opacity=0.5  # 透明度设置),label_opts=opts.LabelOpts(is_show=False)).add_yaxis('流量',stack='堆叠',y_axis=[1000, 950, 950, 980, 290, 330, 320],areastyle_opts=opts.AreaStyleOpts(opacity=0.5  # 透明度设置),label_opts=opts.LabelOpts(is_show=False)).add_yaxis('浏览',stack='堆叠',y_axis=[1000, 950, 950, 980, 290, 330, 320],areastyle_opts=opts.AreaStyleOpts(opacity=0.5  # 透明度设置),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  # 面积图从y轴开始,没有间隙))
)
c.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0428\0428_3.html')

成品图片

15. PyEcharts:散点图

from pyecharts.charts import Scatter
import pyecharts.options as opts
from pyecharts.faker import Fakerdata = [[10.0, 8.04],[8.0, 6.95],[13.0, 7.58],[9.0, 8.81],[11.0, 8.33],[14.0, 9.96],[6.0, 7.24],[4.0, 4.26],[12.0, 10.84],[7.0, 4.82],[5.0, 5.68]]# 把data中x数据排个顺序
data.sort(key=lambda x: x[0])x_data = [d[0] for d in data]
y_data = [d[1] for d in data]c = (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, position='top')).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)),title_opts=opts.TitleOpts(title='散点图'))
)
c.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0428\0428_4.html')

成品图片

16. PyEcharts:涟漪散点图

from pyecharts.charts import EffectScatter
import pyecharts.options as opts
from pyecharts.faker import Faker
from pyecharts.globals import SymbolTypec = (EffectScatter().add_xaxis(Faker.choose()).add_yaxis('',Faker.values(),symbol=SymbolType.DIAMOND,label_opts=opts.LabelOpts(position='top'),color='red').set_global_opts(title_opts=opts.TitleOpts(title='涟漪散点图'),xaxis_opts=opts.AxisOpts(splitline_opts=opts.SplitLineOpts(is_show=True)),  # x轴网格线yaxis_opts=opts.AxisOpts(splitline_opts=opts.SplitLineOpts(is_show=True))   # y轴网格线))
c.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0428\0428_5.html')

成品图片

17. PyEcharts:热力图

from pyecharts.charts import *
import pyecharts.options as opts
from pyecharts.faker import Faker
import randomvalue = [[i, j, random.randint(0, 50)] for i in range(24) for j in range(7)]
c = (HeatMap().add_xaxis(Faker.clock).add_yaxis('热力图',Faker.week,value,label_opts=opts.LabelOpts(is_show=True, position='inside')   # 在内部显示数值).set_global_opts(title_opts=opts.TitleOpts(title='热力图'))    # 设置标题
)
c.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0430\0430_1.html')

成品图片

18. PyEcharts:日历图

from pyecharts.charts import *
import pyecharts.options as opts
import random
import datetime# 2023年
begin = datetime.date(2023, 1, 1)
end = datetime.date(2023, 12, 31)data = [[str(begin + datetime.timedelta(days=i)), random.randint(1000, 25000)]for i in range((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')))
c.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0430\0430_2.html')

成品图片

19. PyEcharts:箱型图

from pyecharts.charts import *
import pyecharts.options as optsv1 = [[890, 810, 810, 820, 800, 770, 760, 740, 750, 760, 910, 920],[890, 840, 780, 810, 760, 810, 790, 810, 820, 850, 870, 870]
]v2 = [[850, 740, 900, 1070, 930, 850, 950, 980, 980, 880, 1000, 980],[960, 940, 960, 940, 880, 800, 850, 880, 900, 840, 830, 790]
]c = Boxplot()
c.add_xaxis(['demo1', 'demo2'])
c.add_yaxis('A', c.prepare_data(v1))
c.add_yaxis('B', c.prepare_data(v1))c.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0430\0430_3.html')

成品图片

20. PyEcharts:词云图

from pyecharts.charts import *
import pyecharts.options as opts
from pyecharts.globals import SymbolType
import random
data = [('小猫', random.randint(500, 1000)),('小狗', random.randint(500, 1000)),('小猪', random.randint(500, 1000)),('小鸡', random.randint(500, 1000)),('小鸭', random.randint(500, 1000)),('小脑斧', random.randint(500, 1000)),('小牛', random.randint(500, 1000)),('小马', random.randint(500, 1000)),('小跳蚤', random.randint(500, 1000)),('小蛇', random.randint(500, 1000)),('小羊', random.randint(500, 1000)),('小龙', random.randint(500, 1000)),('小鼠', random.randint(500, 1000)),('小兔子', random.randint(500, 1000)),('小壁虎', random.randint(500, 1000)),('小飞机', random.randint(500, 1000)),('小花', random.randint(500, 1000))
]
c = (WordCloud().add('小动物',data_pair=data,word_size_range=[15, 60],  # 字体大小的范围word_gap=5,   # 字之间的间隙textstyle_opts=opts.TextStyleOpts(font_family='cursive'  # 字体))
)
c.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0430\0430_4.html')

成品图片

21. PyEcharts:漏斗图

from pyecharts.charts import *
import pyecharts.options as opts
from pyecharts.faker import Fakerc = (Funnel(init_opts=opts.InitOpts(width='800px',height='400px',)).add('漏斗图',[list(i) for i in zip(Faker.choose(), Faker.values())],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='漏斗图'))
)
c.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0430\0430_5.html')

成品图片

22. PyEcharts:极坐标图

from pyecharts.charts import *
import pyecharts.options as opts
from pyecharts.faker import Faker
import random# data = [(i, random.randint(1, 100)) for i in range(101)]
# c = (
#     Polar()
#     .add(
#         '极坐标',
#         data,
#         type_='effectScatter',  # 散点图
#         # label_opts=opts.LabelOpts(is_show=False)
#         effect_opts=opts.EffectOpts(scale=10,  # 涟漪的范围大小
#                                     period=5,  # 动画的速度,动画周期
#                                     )
#     )
#     .set_global_opts(title_opts=opts.TitleOpts(title='极坐标涟漪散点图'))
# )
# c.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0430\0430_6.html')# 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, 3, 5, 1],
#          type_='bar',  # 散点图
#          )
#     .set_global_opts(title_opts=opts.TitleOpts(title='极坐标柱状图图'))
#
# )
# c.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0430\0430_7.html')c = (Polar()# 按照半径堆叠# .add_schema(radiusaxis_opts=opts.RadiusAxisOpts(data=Faker.week,#                                                 type_='category',   # 分类#                                                 ),# 按照角度堆叠.add_schema(angleaxis_opts=opts.AngleAxisOpts(data=Faker.week,type_='category',  # 分类),).add('商品A',[1, 2, 3, 4, 3, 5, 1],type_='bar',  # 散点图stack='abc').add('商品B',[2, 2, 4, 4, 8, 6, 3],type_='bar',  # 散点图stack='abc').add('商品C',[5, 2, 3, 4, 6, 1, 3],type_='bar',  # 散点图stack='abc').set_global_opts(title_opts=opts.TitleOpts(title='极坐标堆叠图')))
c.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0430\0430_8.html')

成品图片

23. PyEcharts:水球图

from pyecharts.charts import *
from pyecharts import options as opts
from pyecharts.globals import SymbolTypec = (Liquid(init_opts=opts.InitOpts(width='400px',height='400px',)).add('',[0.6, 0.3],  # 有两层波浪,对应的比例分别是0.6,0.3is_outline_show=True,  # 显示外边框shape=SymbolType.DIAMOND,  # 菱形形状).set_global_opts(title_opts=opts.TitleOpts(title='水球图'))
)
c.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0430\0430_9.html')

成品图片

24. PyEcharts:桑基图

from pyecharts.charts import *
from pyecharts import options as optsnodes = [{'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': 'c5', 'target': 'c6', 'value': 40},{'source': 'c6', 'target': 'c7', 'value': 50},{'source': 'c7', 'target': 'c1', 'value': 60},]c = (Sankey().add('',nodes,  # 所有节点links,  # 节点之间的连接关系linestyle_opt=opts.LineStyleOpts(opacity=0.2,  # 透明度curve=0.6,    # 曲线幅度0-1color='red'),label_opts=opts.LabelOpts(position='right')).set_global_opts(title_opts=opts.TitleOpts(title='桑基图'))
)
c.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0430\0430_10.html')

成品图片

25. PyEcharts:旭日图

from pyecharts.charts import Sunburst
from pyecharts import options as optsdata = [{"name": "Fruity","itemStyle": {"color": "#da1d23"},"children": [{"name": "Berry","itemStyle": {"color": "#dd4c51"},"children": [{"name": "Blackberry","value": 1,"itemStyle": {"color": "#3e0317"},},{"name": "Raspberry","value": 1,"itemStyle": {"color": "#e62969"},},{"name": "Blueberry","value": 1,"itemStyle": {"color": "#6569b0"},},{"name": "Strawberry","value": 1,"itemStyle": {"color": "#ef2d36"},},],},{"name": "Dried Fruit","itemStyle": {"color": "#c94a44"},"children": [{"name": "Raisin", "value": 1, "itemStyle": {"color": "#b53b54"}},{"name": "Prune", "value": 1, "itemStyle": {"color": "#a5446f"}},],},{"name": "Other Fruit","itemStyle": {"color": "#dd4c51"},"children": [{"name": "Coconut", "value": 1, "itemStyle": {"color": "#f2684b"}},{"name": "Cherry", "value": 1, "itemStyle": {"color": "#e73451"}},{"name": "Pomegranate","value": 1,"itemStyle": {"color": "#e65656"},},{"name": "Pineapple","value": 1,"itemStyle": {"color": "#f89a1c"},},{"name": "Grape", "value": 1, "itemStyle": {"color": "#aeb92c"}},{"name": "Apple", "value": 1, "itemStyle": {"color": "#4eb849"}},{"name": "Peach", "value": 1, "itemStyle": {"color": "#f68a5c"}},{"name": "Pear", "value": 1, "itemStyle": {"color": "#baa635"}},],},{"name": "Citrus Fruit","itemStyle": {"color": "#f7a128"},"children": [{"name": "Grapefruit","value": 1,"itemStyle": {"color": "#f26355"},},{"name": "Orange", "value": 1, "itemStyle": {"color": "#e2631e"}},{"name": "Lemon", "value": 1, "itemStyle": {"color": "#fde404"}},{"name": "Lime", "value": 1, "itemStyle": {"color": "#7eb138"}},],},],},{"name": "Green/\nVegetative","itemStyle": {"color": "#187a2f"},"children": [{"name": "Olive Oil", "value": 1, "itemStyle": {"color": "#a2b029"}},{"name": "Raw", "value": 1, "itemStyle": {"color": "#718933"}},{"name": "Green/\nVegetative","itemStyle": {"color": "#3aa255"},"children": [{"name": "Under-ripe","value": 1,"itemStyle": {"color": "#a2bb2b"},},{"name": "Peapod", "value": 1, "itemStyle": {"color": "#62aa3c"}},{"name": "Fresh", "value": 1, "itemStyle": {"color": "#03a653"}},{"name": "Dark Green","value": 1,"itemStyle": {"color": "#038549"},},{"name": "Vegetative","value": 1,"itemStyle": {"color": "#28b44b"},},{"name": "Hay-like", "value": 1, "itemStyle": {"color": "#a3a830"}},{"name": "Herb-like","value": 1,"itemStyle": {"color": "#7ac141"},},],},{"name": "Beany", "value": 1, "itemStyle": {"color": "#5e9a80"}},],},
]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="Sunburst-官方示例")).set_series_opts(label_opts=opts.LabelOpts(formatter="{b}"))
)
c.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0430\0430_11.html')

成品图片

26. PyEcharts:仪表盘

from pyecharts.charts import *
from pyecharts import options as optsc = (Gauge().add('指标',data_pair=[('', '66')],radius='40%',   # 仪表盘整体大小).set_global_opts(title_opts=opts.TitleOpts(title="仪表盘")))
c.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0430\0430_12.html')

成品图片

27. PyEcharts:树图

from pyecharts.charts import *
from pyecharts import options as optsdata = [{'children': [{'name': '叔叔'},{'name': '伯伯','children': [{'name': '小红'}],},{'name': '父亲','children': [{'name': '我'},{'name': '姐姐'}]}],'name': '祖父母'}
]c = (Tree().add('', data).set_global_opts(title_opts=opts.TitleOpts(title='树图'))
)
c.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0501\0501_1.html')

成品图片

28. PyEcharts:矩形树图

from pyecharts.charts import *
from pyecharts import options as optsdata = [{'value': 40, 'name': '伯伯', 'children': [{'value': 76,'name': '她','children': [{'value': 12, 'name': '大儿子'},{'value': 28, 'name': '二儿子'},{'value': 20, 'name': '三女儿'},{'value': 16, 'name': '四女儿'},]}]},{'value': 180, 'name': '父亲', 'children': [{'value': 76,'name': '我','children': [{'value': 12, 'name': '大儿子'},{'value': 28, 'name': '二儿子'},{'value': 20, 'name': '三女儿'},{'value': 16, 'name': '四女儿'},]}]}]
c = (TreeMap().add('', data).set_global_opts(title_opts=opts.TitleOpts(title='矩形树图'))
)
c.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0501\0501_2.html')

成品图片

39. PyEcharts:关系图

# from pyecharts.charts import *
# from pyecharts import options as opts# nodes = [
#     {"name": "结点1", "symbolSize": 10},
#     {"name": "结点2", "symbolSize": 20},
#     {"name": "结点3", "symbolSize": 30},
#     {"name": "结点4", "symbolSize": 40},
#     {"name": "结点5", "symbolSize": 50},
#     {"name": "结点6", "symbolSize": 40},
#     {"name": "结点7", "symbolSize": 30},
#     {"name": "结点8", "symbolSize": 20},
# ]
# links = []
# for i in nodes:
#     for j in nodes:
#         links.append({"source": i.get("name"), "target": j.get("name")})
# c = (
#     Graph()
#     .add("",
#          nodes,
#          links,
#          repulsion=8000,   # 排斥力,越大分的越开
#          )
#     .set_global_opts(title_opts=opts.TitleOpts(title="关系图"))
# )
#
# c.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0501\0501_3.html')# 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=8000,   # 排斥力,越大分的越开
#
#          #
#          edge_label=opts.LabelOpts(is_show=True, position='middle', formatter='{b}的数据:{c}')
#          )
#     .set_global_opts(title_opts=opts.TitleOpts(title="关系图"))
# )
#
# c.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0501\0501_4.html')import jsonfrom pyecharts import options as opts
from pyecharts.charts import Graphwith open("les-miserables.json", "r", encoding="utf-8") as f:j = json.load(f)nodes = j["nodes"]links = j["links"]categories = j["categories"]c = (Graph(init_opts=opts.InitOpts(width="1000px", height="600px")).add("",nodes=nodes,links=links,categories=categories,layout="circular",   # 布局方式:圆is_rotate_label=True,  # 旋转标签linestyle_opts=opts.LineStyleOpts(color="source",  # 使用节点颜色curve=0.3  # 线的弯曲程度),label_opts=opts.LabelOpts(position="right"),).set_global_opts(title_opts=opts.TitleOpts(title="关系图"),legend_opts=opts.LegendOpts(orient="vertical", pos_left="2%", pos_top="20%"),)
)
c.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0501\0501_5.html')

成品图片

30. PyEcharts:K线图

from pyecharts import options as opts
from pyecharts.charts import Klinedata = [#  开盘价,收盘价,最低价,最高价[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/7/{}".format(i + 1) for i in range(31)]).add_yaxis("K线图",data,itemstyle_opts=opts.ItemStyleOpts(color="#ec0000",color0="#00da3c",border_color="#8A0000",border_color0="#008F28",),).set_global_opts(xaxis_opts=opts.AxisOpts(is_scale=True),yaxis_opts=opts.AxisOpts(is_scale=True,splitarea_opts=opts.SplitAreaOpts(is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)),),datazoom_opts=[opts.DataZoomOpts(type_="inside")],title_opts=opts.TitleOpts(title="K线图"),)
)
#  开盘价,收盘价,最低价,最高价
# 阳线:红色,收盘价>=开盘价
# 阴线:收盘价<=开盘价c.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0501\0501_6.html')

成品图片

31. PyEcharts:地图

from pyecharts import options as opts
from pyecharts.charts import *
from pyecharts.faker import Faker
from pyecharts.faker import POPULATION# provinces = Faker.provinces
# c = (
#     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,
#                                                        is_piecewise=True
#                                                        )
#                      )
# )
# c.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0501\0501_7.html')# city = Faker.guangdong_city
# c = (
#     Map()
#     .add('',
#          [list(i) for i in zip(city, Faker.values())],
#          '广东',  # 地图类型
#          )
#     .set_global_opts(title_opts=opts.TitleOpts(title='广东地图'),
#                      visualmap_opts=opts.VisualMapOpts(max_=200,
#                                                        is_piecewise=True
#                                                        )
#                      )
# )
# c.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0501\0501_8.html')# c = (
#     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
#                                                        )
#                      )
#     .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
# )
# c.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0501\0501_9.html')data = [x for _, x in POPULATION[1:]]  # 人口数据
low, height = min(data), max(data)
c = (MapGlobe().add_schema().add(series_name='世界人口',maptype='world',  # 地图类型data_pair=POPULATION[1:],  # 人口数据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_=height,min_=low,is_piecewise=True,range_text=['Max', 'Min'],is_calculable=True,range_color=['lightskyblue', 'yellow', 'orange']))
)
c.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0501\0501_10.html')

成品图片

32. PyEcharts:地理坐标图

from pyecharts.charts import *
from pyecharts import options as opts
from pyecharts.faker import Faker
from pyecharts.globals import ChartType, SymbolType# c = (
#     Geo()
#     .add_schema(maptype='china')
#     .add(
#         'geo',
#         [list(i) for i in zip(Faker.provinces, Faker.values())],
#         # type_=ChartType.EFFECT_SCATTER  # 涟漪散点图
#         type_=ChartType.HEATMAP  # 热力图
#
#     )
#     .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
#     .set_global_opts(title_opts=opts.TitleOpts(title='GEO + 涟漪散点/热力图'),
#                      visualmap_opts=opts.VisualMapOpts())
# )
# c.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0501\0501_11.html')c = (Geo().add_schema(maptype='china').add('geo',[('广州', 50), ('北京', 60), ('杭州', 70), ('重庆', 80)],# type_=ChartType.EFFECT_SCATTER  # 涟漪散点图type_=ChartType.EFFECT_SCATTER,  # 涟漪散点图color='pink').add('',[('广州', '上海'), ('广州', '北京'), ('广州', '杭州'), ('广州', '重庆')],type_=ChartType.LINES,  # 线连起来# 箭头effect_opts=opts.EffectOpts(symbol=SymbolType.ARROW,symbol_size=6,color='green'),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'))
)
c.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0501\0501_12.html')

成品图片

33. PyEcharts:3D折线图

from pyecharts.charts import *
from pyecharts import options as opts
from pyecharts.faker import Faker
import numpy as np
import mathdata = []
for t in range(0, 25000):_t = t/1000x = (1 + 0.25 * math.cos(75 * _t)) * math.cos(_t)y = (1 + 0.25 * math.cos(75 * _t)) * math.sin(_t)z = _t + 2 * math.sin(75 * _t)data.append([x, y, z])
# print(np.array(data).shape)  # 查看列表的维度c = (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_global_opts(visualmap_opts=opts.VisualMapOpts(min_=0,  # 视觉映射最小值max_=30,  # 视觉映射最大值range_color=Faker.visual_color  # 颜色范围))
)c.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0505\0505_1.html')

成品图片

34. PyEcharts:3D柱状图

from pyecharts.charts import *
from pyecharts import options as opts
from pyecharts.faker import Faker
import random# data = [(i, j, random.randint(0, 12)) for i in range(0, 5) for j in range(24)]
#
# c = (
#     Bar3D()
#     .add('柱状图',
#          [[d[1], d[0], d[2]] for d in data],
#          xaxis3d_opts=opts.Axis3DOpts(Faker.clock, type_='category'),   # 离散数据用'category'
#          yaxis3d_opts=opts.Axis3DOpts(Faker.week, type_='category'),
#          zaxis3d_opts=opts.Axis3DOpts(type_='value'),
#          )
#     .set_global_opts(visualmap_opts=opts.VisualMapOpts(max_=15,  # 视觉映射最大值
#                                                        )
#                      )
# )
# c.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0505\0505_2.html')x_data = y_data = list(range(0, 9))def generate_data():   # 调用数据的函数,每次运行数据都不一样data = []for j in range(10):for k in range(10):value = random.randint(0, 9)data.append([j, k, value * 2 + 4])return databar3d = Bar3D()
for _ in range(10):  # 用_接收数据,但是不使用这个变量bar3d.add('',generate_data(),shading='lambert',  # 更清晰xaxis3d_opts=opts.Axis3DOpts(x_data, type_='value'),   # 连续数据用'value'yaxis3d_opts=opts.Axis3DOpts(y_data, type_='value'),zaxis3d_opts=opts.Axis3DOpts(type_='value'),)
bar3d.set_global_opts(title_opts=opts.TitleOpts(title='3D堆叠柱状图'))
bar3d.set_series_opts(stack='abc')   # 堆叠
bar3d.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0505\0505_3.html')

成品图片

35. PyEcharts:时间轮播多图

from pyecharts.charts import *
from pyecharts import options as opts
from pyecharts.faker import Fakerx = 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='某商家第{}年的营业额'.format(i))))tl.add(bar, '{}年'.format(i))
tl.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0505\0505_4.html')# attr = Faker.choose()
# tl = Timeline()
#
# for i in range(2020, 2025):
#     pie = (
#         Pie()
#         .add('',
#              [list(z) for z in zip(attr, Faker.values())],
#              rosetype='radius',  # 玫瑰图
#              radius=['30%', '55%']
#              )
#         .set_global_opts(title_opts=opts.TitleOpts(title='某商家第{}年的营业额'.format(i))
#                          )
#     )
#     tl.add(pie, '{}年'.format(i))
# tl.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0505\0505_5.html')

成品图片

36. PyEcharts:多图布局

from pyecharts.charts import *
from pyecharts import options as opts
from pyecharts.faker import Fakerline = (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%'),  # 调控AB的位置)
)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%'),  # 调控CD的位置)
)# 多图布局
grid = (Grid().add(line, grid_opts=opts.GridOpts(pos_right='55%')).add(scatter, grid_opts=opts.GridOpts(pos_left='55%'))
)
grid.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0505\0505_6.html')

成品图片

37. PyEcharts:天猫订单数据可视化

import pandas as pd
from pyecharts.charts import *
from pyecharts import options as optsdata = pd.read_csv('tmall_order_report.csv')
print(data.info(), '\n')   # 返回表格的基本信息
print(data.columns, '\n')  # 查看类名# ----------------------------各个省份的订单量--------------------------------# 去除列明中的空格
data.columns = data.columns.str.strip()   # str.strip() 方法用于移除字符串头尾指定的字符(默认为空格或换行符)或字符序列
print(data.columns, '\n')  # 查看类名# 重复值查看
print(data.duplicated().sum(), '\n')   # False对应值为0# 缺失值查看
print(data.isnull().sum(), '\n')# 各省份的订单量
data.head()
print(data.收货地址.value_counts(), '\n')   # 查看各省分的订单量def province_map(p):if p in ['北京', '天津', '上海', '重庆']:return p + '市'return pdata.收货地址 = data.收货地址.map(province_map)
print(data.收货地址.value_counts(), '\n')   # 查看各省分的订单量result_1 = data.订单付款时间.notnull()  # 查看订单付款时间不为空的数据
data = data[result_1]  # 过滤掉(删掉)没有付款的数据
print(data, '\n')# 统计各个省份的订单量
result = data.groupby('收货地址')[['订单编号']].count()  # 根据收货地址分组
print(result, '\n')result_2 = result.to_dict()['订单编号']   # 变成字典结构result_2 = [*result_2.items()]   # 变成列表,用list也行
print(result_2, '\n')# c = (
#     Map()
#     .add('各个省份的订单量',
#          result_2,
#          'china',
#          is_map_symbol_show=False
#          )
#     .set_series_opts(label_opts=opts.LabelOpts(is_show=True))
#     .set_global_opts(title_opts=opts.TitleOpts(title='各个省份的订单量'),
#                      visualmap_opts=opts.VisualMapOpts(max_=2000)
#                      )
# )
# c.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0505\0505_7.html')# ----------------------------每一天的订单量--------------------------------# 订单创建时间和订单付款时间首先都变成时间类型
data.订单创建时间 = pd.to_datetime(data.订单创建时间)
data.订单付款时间 = pd.to_datetime(data.订单付款时间)# 每天订单量统计可视化
order_add_time = data.订单创建时间.map(lambda x: x.strftime('%Y-%m-%d'))  # 更改时间的格式
print(order_add_time, '\n')# 按照订单的创建时间来进行分组,得到每一天的订单量
result_3 = data.groupby(order_add_time).agg({'订单编号': 'count'}).to_dict()['订单编号']
print(result_3, '\n')# c = (
#     Line()
#     .add_xaxis(list(result_3.keys()))
#     .add_yaxis('订单量',
#                list(result_3.values())
#                )
#     .set_series_opts(label_opts=opts.LabelOpts(is_show=False),
#                      markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_='max')])
#                      )
#     .set_global_opts(title_opts=opts.TitleOpts(title='每一天的订单量'),
#                      visualmap_opts=opts.VisualMapOpts(max_=2000)
#                      )
# )
# c.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0505\0505_8.html')# ----------------------------每小时的订单量--------------------------------
order_add_time2 = data.订单创建时间.map(lambda x: x.strftime('%H'))
print(order_add_time2.value_counts(), '\n')result_4 = data.groupby(order_add_time2).agg({'订单编号': 'count'}).to_dict()['订单编号']
print(result_4, '\n')c = (Bar().add_xaxis(list(result_4.keys())).add_yaxis('订单量',list(result_4.values())).set_series_opts(label_opts=opts.LabelOpts(is_show=False),markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_='max')])).set_global_opts(title_opts=opts.TitleOpts(title='每小时的订单量'),visualmap_opts=opts.VisualMapOpts(max_=2000)))
c.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0505\0505_9.html')

成品图片

38. PyEcharts:双十一销售数据可视化

import pandas as pd
from pyecharts.charts import *
from pyecharts import options as opts# update_time:更新时间
# id:编号
# title:商品标题
# price:价格
# sale_count:销售量
# comment_count:评论数量
# 店名:店铺名称data = pd.read_csv('double11beautysales.csv')
print('data.head():', data.head(), '\n')
print('data.shape:', data.shape, '\n')
print('data.info():', data.info(), '\n')# 重复值处理
print('data.duplicated():', data.duplicated(), '\n')
print('data.duplicated().sum():', data.duplicated().sum(), '\n')  # 86条数据重复了
data.drop_duplicates(inplace=True)  # 删除重复值,但是删除之后,最前方的编号不会是连续的,直接跳过删除的
data.reset_index(drop=True, inplace=True)  # 重置索引
print('data.duplicated().sum():', data.duplicated().sum(), '\n')  # 0条数据重复了# 缺失值处理
print('data.isnull():', data.isnull(), '\n')
print('data.isnull().sum():', data.isnull().sum(), '\n')
data.fillna(0, inplace=True)
print('data.isnull().sum():', data.isnull().sum(), '\n')# 时间序列分析
data.update_time = pd.to_datetime(data.update_time).map(lambda x: x.strftime('%Y-%m-%d'))# 加一列数据,销售额
data['sale_amount'] = data.price * data.sale_count# 按照销量排序
# data[data.sale_count > 0].sort_values(by=['sale_count'])# 每天销售额统计分析
result = data.groupby('update_time').agg({'sale_count': 'sum'}).to_dict()['sale_count']
print('result:', result, '\n')# c = (
#     Line()
#     .add_xaxis(list(result.keys()))
#     .add_yaxis('销量', list(result.values()))
#     .set_global_opts(title_opts=opts.TitleOpts(title='每一天的销售量'))
#     .set_series_opts(areastyle_opts=opts.AreaStyleOpts(opacity=0.5),
#                      label_opts=opts.LabelOpts(is_show=False),
#                      markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_='max', name='最大值'),
#                                                              opts.MarkPointItem(type_='min', name='最小值')
#                                                              ]
#                                                        )
#                      )
# )
# c.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0512\0512_1.html')# 时间升序
times = list(data.update_time.unique())
times.reverse()
print('times:', times, '\n')# 时间轮播图
tl = Timeline()
tl.add_schema(is_auto_play=True,  # 是否自动播放is_loop_play=True,  # 是否循环播放play_interval=2000  # 每隔两秒钟
)
for dt in times:item = data[data.update_time <= dt].groupby('店名'). \agg({'sale_count': 'sum', 'sale_amount': 'sum'}) \.sort_values(by='sale_count', ascending=False)[:10] \.sort_values(by='sale_count') \.to_dict()# print(item)#     bar = (
#         Bar()
#         .add_xaxis(list(item['sale_count'].keys()))
#         .add_yaxis('销售量',
#                    [round(val/1000000, 1) for val in item['sale_count'].values()],
#                    label_opts=opts.LabelOpts(position='right',
#                                              formatter='{@[1]/}百万件')
#                    )
#         .add_yaxis('销售额',
#                    [round(val / 100000000, 1) for val in item['sale_amount'].values()],
#                    label_opts=opts.LabelOpts(position='right',
#                                              formatter='{@[1]/}亿元')
#                    )
#         .reversal_axis()  # 条形图
#         .set_global_opts(title_opts=opts.TitleOpts(title='累计销售量Top10'))
#
#     )
#     tl.add(bar, dt)
# tl.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0512\0512_2.html')item = data.groupby('店名'). \agg({'sale_count': 'sum'}) \.sort_values(by='sale_count', ascending=False)[:10] \.to_dict()['sale_count']
item = {k: round(v/10000, 1) for k, v in item.items()}# c = (
#     Pie()
#     .add('销售量',
#          list(item.items()),)
#     .set_series_opts(label_opts=opts.LabelOpts(formatter='{b}:{c} k({d})%'))
# )
# c.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0512\0512_3.html')# 价格排序
item = data.groupby('店名'). \agg({'price': 'mean'}) \.sort_values(by='price', ascending=True)[:20] \.to_dict()['price']c = (Bar().add_xaxis(list(item.keys())).add_yaxis('价格',[round(v, 2) for v in item.values()],label_opts=opts.LabelOpts(position='right')).reversal_axis().set_global_opts(title_opts=opts.TitleOpts(title='各店铺的平局价格Top20'))
)
c.render(r'D:\PyEcharts\PyEcharts-课程资料\绘制图片\0512\0512_4.html')

成品图片

PyEcharts学习笔记整理,基于B站千锋教育相关推荐

  1. python学习,王者荣耀管理系统(千锋教育)

    #_*_cording.utf-8_*_ # 开发团队:开心科研 # 开发人员:Administrator # 开发时间:2021/6/19 001917:01 # 文件名称:Goverment_of ...

  2. 天猫整站SSM-后台分类管理-增加(做个人学习笔记整理用)

    天猫整站SSM-后台分类管理-增加(做个人学习笔记整理用) CategoryController: request.getSession().getServletContext()// 获取的是pag ...

  3. 天猫整站SSM-分页-总结(做个人学习笔记整理用)

    天猫整站SSM-分页-herf(做个人学习笔记整理用) 先写Page.java package com.how2java.tmall.util;public class Page {private i ...

  4. 天猫整站SSM-分页-herf(做个人学习笔记整理用)

    天猫整站SSM-分页-(做个人学习笔记整理用) <li ><a href="?start=${page.start-page.count}" aria-label ...

  5. 【转载】Deep Learning(深度学习)学习笔记整理系列

    Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net/zouxy09 作者:Zouxy version 1.0  2013-0 ...

  6. Deep Learning(深度学习)学习笔记整理系列 | @Get社区

    Deep Learning(深度学习)学习笔记整理系列 | @Get社区 Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net ...

  7. Deep Learning(深度学习)学习笔记整理系列之(二)

    Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net/zouxy09 作者:Zouxy version 1.0 2013-04 ...

  8. Deep Learning(深度学习)学习笔记整理系列之(八)

     Deep Learning(深度学习)学习笔记整理系列之(八) 分类: Deep Learning 机器学习 Linux驱动2013-04-10 11:4257652人阅读评论(25)收藏举报 ...

  9. Deep Learning(深度学习)学习笔记整理系列三

    Deep Learning(深度学习)学习笔记整理系列 声明: 1)该Deep Learning的学习系列是整理自网上很大牛和机器学习专家所无私奉献的资料的.具体引用的资料请看参考文献.具体的版本声明 ...

最新文章

  1. zabbix_get 无法获取值(解决思路)
  2. JPA基础(二)(转)
  3. JS简单循环遍历json数组的方法
  4. eclipse下查看maven下载的源码中文乱码问题
  5. 【机器学习】一文全览机器学习建模流程(Python代码)
  6. 1亿人点赞的晚会,如何做技术沉淀?
  7. Python中的GIL锁
  8. 基于SpringCloud的微服务架构演变史?
  9. matlab gul介绍及串口通信实现,Matlab - GUl介绍及串口通信实现(转)
  10. echarts中矢量图片路径设置
  11. 第011讲 选择器使用细节 块元素和行内元素 盒子模型
  12. 小程序嵌套h5界面,在h5界面调用小程序的扫一扫功能
  13. 微信公众号推送模板跳转小程序
  14. Stata:各类全要素生产率TFP估算方法
  15. python中对字符串进行左、中、右对齐操作
  16. 视频教程-Spring Data JPA项目-Java
  17. 微信第三方服务平台开发(一)
  18. 八种酒吧里最IN喝酒法PartyOK版
  19. 基于控制台的c语言游戏常用操作
  20. 亚马逊宣布与大自然保护协会合作,投资巴西基于自然的碳移除解决方案

热门文章

  1. MSI和MSI-X区别
  2. 设计计算机配置方案技术参数,广西科学技术信息技术七年级上册_《设计计算机配置方案》教案1...
  3. 特斯拉向监管机构承认FSD只是L2,激光雷达或是最大硬伤
  4. 已停止访问该网页 的原因及解决方案
  5. 一文看懂推荐系统:召回02:Swing 模型,和itemCF很相似,区别在于计算相似度的方法不一样
  6. SQL学习—基础查询
  7. 阿里云视频点播服务Vod工具类——实现视频上传、删除、播放
  8. python求协方差矩阵_用numpy计算协方差(covariance)
  9. android notifydatasetchanged 刷新错误,Android中适配器的notifyDataSetChanged()为何有时不刷新...
  10. python从集思录获取最近新发可转债信息