pyecharts 简介
- 绘制第一个图表
from pyecharts import Bar
bar = Bar("我的第一个图表","这里是副标题")
bar.add("服装",["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"],[5,20,40,20,90,75])
bar.show_config()
bar.render()
- add():用于添加图表的数据和设置各种配置项
- show_config():打印输出图表的所有配置项
- render():默认在根目录下生成一个render.html文件
pyecharts 绘制基础配置项
- add()
add()
数据一般为两个列表(长度一直),若数据为字典或者带元组的字典,可利用cast()
方法转换
@staticcmethod
cast(seq)
`转换数据序列,将带字典和元组类型的序列转换为k_lst,v_lst`
- 图表类初始化所接受的参数
参数名称 | 参数类型 | 默认值 | 参数作用 |
---|---|---|---|
title | str | "" | 主标题文本支持\n换行 |
subtitle | str | "" | 副标题文本,支持\n换行 |
width | int | 800(px) | 画布宽度 |
height | int | 400(px) | 画布高度 |
title_pos | str | auto | 标题位置 |
title_color | str | #000 | 主标题文本颜色 |
subtitle_color | str | #aaa | 副标题文本颜色 |
title_text_size | int | 18 | 主标题文本字体大小 |
subtitle_text_size | int | 12 | 副标题文本字体大小 |
background_color | str | #fff | 画布背景颜色 |
- 通用配置项
通用配置项均在
add()
中设置
xyAxis:直角坐标系中的x/y轴(Line、Bar、Scatter、EffectScatter)
参数名称 | 参数类型 | 参数含义 |
---|---|---|
is_convert | bool | 是否交换x轴与y轴 |
xy_text_size | int | x轴和y轴的字体大小 |
namegap | int | 坐标轴名称与轴线之间的距离 |
x_axis | list | x轴数据项 |
xaxis_name | str | x轴名称 |
xaxis_name_pos | str | x轴名称位置('start','middle','end') |
yaxis_formatter | str | y轴标签格式器 |
interval | int | 坐标轴刻度标签的显示间隔,在类目轴中有效,默认设置为0,强制显示所有标签[1-隔一个显示] |
legend:图例组件,图例组件展现了不同系列的标记(symbol),颜色和名字。可通过点击图例控制那些系列不显示
参数名称 | 参数类型 | 参数含义 |
---|---|---|
is_legend_show | bool | 是否显示顶端图例,默认为True |
legend_orient | str | 图例列表的布局朝向,默认为center |
legend_top | str | 图例组件离容器上侧的距离,默认为top |
label:图形上的文本标签,可用于说明图形的一些数据信息
参数名称 | 参数类型 | 参数含义 |
---|---|---|
is_label_show | bool | 是否正常显示标签,默认不显示,标签即各点的数据项信息 |
is_emphasis | bool | 是否高亮显示标签,默认显示,高亮标签即选中数据时显示的信息项 |
label_pos | str | 标签位置,bar图默认有top |
label_text_color | str | 标签字体颜色,默认为#000 |
label_text_size | int | 标签字体大小,默认为12 |
is_random | bool | 是否随机排列颜色列表,默认为False |
label_color | list | 自定义标签颜色 |
formatter | list | 标签内容格式器,series:图例名称,name:数据项名称,value:数据项,percent:数据的百分比 |
lineStyle:带线图形的线段风格(line、polar、radar、graph、parallel)
参数名称 | 参数类型 | 参数含义 |
---|---|---|
line_width | int | 线的宽度默认为1 |
line_opacity | float | 线的透明度,0为完全透明,1为不透明,默认为1 |
line_curve | float | 线的弯曲程度,0为不弯曲,1为最弯曲,默认为0 |
line_type | str | 线的类型'solid'/'dashed'/'dotted',默认为'solid' |