赞
踩
class Calendar(
# 初始化配置项,参考 `global_options.InitOpts`
init_opts: opts.InitOpts = opts.InitOpts()
)
def add( # 系列名称,用于 tooltip 的显示,legend 的图例筛选。 series_name: str, # 系列数据,格式为 [(date1, value1), (date2, value2), ...] yaxis_data: Sequence, # 是否选中图例 is_selected: bool = True, # 标签配置项,参考 `series_options.LabelOpts` label_opts: Union[opts.LabelOpts, dict] = opts.LabelOpts(), # 日历坐标系组件配置项,参考 `CalendarOpts` calendar_opts: Union[opts.CalendarOpts, dict, None] = None, # 提示框组件配置项,参考 `series_options.TooltipOpts` tooltip_opts: Union[opts.TooltipOpts, dict, None] = None, # 图元样式配置项,参考 `series_options.ItemStyleOpts` itemstyle_opts: Union[opts.ItemStyleOpts, dict, None] = None, )
class CalendarOpts( # calendar组件离容器左侧的距离。 # left 的值可以是像 20 这样的具体像素值,可以是像 '20%' 这样相对于容器高宽的百分比, # 也可以是 'left', 'center', 'right'。 # 如果 left 的值为'left', 'center', 'right',组件会根据相应的位置自动对齐。 pos_left: Optional[str] = None, # calendar组件离容器上侧的距离。 # top 的值可以是像 20 这样的具体像素值,可以是像 '20%' 这样相对于容器高宽的百分比, # 也可以是 'top', 'middle', 'bottom'。 # 如果 top 的值为'top', 'middle', 'bottom',组件会根据相应的位置自动对齐。 pos_top: Optional[str] = None, # calendar组件离容器右侧的距离。 # right 的值可以是像 20 这样的具体像素值,可以是像 '20%' 这样相对于容器高宽的百分比。 # 默认自适应。 pos_right: Optional[str] = None, # calendar组件离容器下侧的距离。 # bottom 的值可以是像 20 这样的具体像素值,可以是像 '20%' 这样相对于容器高宽的百分比。 # 默认自适应。 pos_bottom: Optional[str] = None, # 日历坐标的布局朝向。可选: # 'horizontal', 'vertical' orient: Optional[str] = None, # 必填,日历坐标的范围 支持多种格式,使用示例: # 某一年 range: 2017 # 某个月 range: '2017-02' # 某个区间 range: ['2017-01-02', '2017-02-23'] # 注意 此写法会识别为['2017-01-01', '2017-02-01'] # range: ['2017-01', '2017-02'] range_: Union[str, Sequence, int] = None, # 星期轴的样式,参考 `series_options.LabelOpts` daylabel_opts: Union[LabelOpts, dict, None] = None, # 月份轴的样式,参考 `series_options.LabelOpts` monthlabel_opts: Union[LabelOpts, dict, None] = None, # 年份的样式,参考 `series_options.LabelOpts` yearlabel_opts: Union[LabelOpts, dict, None] = None, )
import random import datetime import pyecharts.options as opts from pyecharts.charts import Calendar begin = datetime.date(2017, 1, 1) end = datetime.date(2017, 12, 31) data = [ [str(begin + datetime.timedelta(days=i)), random.randint(1000, 25000)] for i in range((end - begin).days + 1) ] ( Calendar(init_opts=opts.InitOpts(width="1600px", height="1000px")) .add( series_name="", yaxis_data=data, calendar_opts=opts.CalendarOpts( pos_top="120", pos_left="30", pos_right="30", range_="2017", yearlabel_opts=opts.CalendarYearLabelOpts(is_show=False), ), ) .set_global_opts( title_opts=opts.TitleOpts(pos_top="30", pos_left="center", title="2017年步数情况"), visualmap_opts=opts.VisualMapOpts( max_=20000, min_=500, orient="horizontal", is_piecewise=False ), ) .render("calendar_heatmap.html") )
import datetime import random from pyecharts import options as opts from pyecharts.charts import Calendar begin = datetime.date(2017, 1, 1) end = datetime.date(2017, 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_="2017", daylabel_opts=opts.CalendarDayLabelOpts(name_map="cn"), monthlabel_opts=opts.CalendarMonthLabelOpts(name_map="cn"), ), ) .set_global_opts( title_opts=opts.TitleOpts(title="Calendar-2017年微信步数情况(中文 Label)"), visualmap_opts=opts.VisualMapOpts( max_=20000, min_=500, orient="horizontal", is_piecewise=True, pos_top="230px", pos_left="100px", ), ) .render("calendar_label_setting.html") )
import datetime import random from pyecharts import options as opts from pyecharts.charts import Calendar begin = datetime.date(2017, 1, 1) end = datetime.date(2017, 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_="2017")) .set_global_opts( title_opts=opts.TitleOpts(title="Calendar-2017年微信步数情况"), visualmap_opts=opts.VisualMapOpts( max_=20000, min_=500, orient="horizontal", is_piecewise=True, pos_top="230px", pos_left="100px", ), ) .render("calendar_base.html") )
class Funnel(
# 初始化配置项,参考 `global_options.InitOpts`
init_opts: opts.InitOpts = opts.InitOpts()
)
def add( # 系列名称,用于 tooltip 的显示,legend 的图例筛选。 series_name: str, # 系列数据项,格式为 [(key1, value1), (key2, value2)] data_pair: Sequence, # 是否选中图例 is_selected: bool = True, # 系列 label 颜色 color: Optional[str] = None, # 数据排序, 可以取 'ascending','descending','none'(表示按 data 顺序) sort_: str = "descending", # 数据图形间距 gap: Numeric = 0, # 标签配置项,参考 `series_options.LabelOpts` label_opts: Union[opts.LabelOpts, dict] = opts.LabelOpts(), # 提示框组件配置项,参考 `series_options.TooltipOpts` tooltip_opts: Union[opts.TooltipOpts, dict, None] = None, # 图元样式配置项,参考 `series_options.ItemStyleOpts` itemstyle_opts: Union[opts.ItemStyleOpts, dict, None] = None, )
from pyecharts import options as opts from pyecharts.charts import Funnel from pyecharts.faker import Faker c = ( Funnel() .add( "商品", [list(z) for z in zip(Faker.choose(), Faker.values())], sort_="ascending", label_opts=opts.LabelOpts(position="inside"), ) .set_global_opts(title_opts=opts.TitleOpts(title="Funnel-Sort(ascending)")) .render("funnel_sort_ascending.html") )
from pyecharts import options as opts from pyecharts.charts import Funnel from pyecharts.faker import Faker c = ( Funnel() .add( "商品", [list(z) for z in zip(Faker.choose(), Faker.values())], sort_="ascending", label_opts=opts.LabelOpts(position="inside"), ) .set_global_opts(title_opts=opts.TitleOpts(title="Funnel-Sort(ascending)")) .render("funnel_sort_ascending.html") )
from pyecharts import options as opts
from pyecharts.charts import Funnel
from pyecharts.faker import Faker
c = (
Funnel()
.add("商品", [list(z) for z in zip(Faker.choose(), Faker.values())])
.set_global_opts(title_opts=opts.TitleOpts(title="Funnel-基本示例"))
.render("funnel_base.html")
)
import pyecharts.options as opts from pyecharts.charts import Funnel """ Gallery 使用 pyecharts 1.1.0 参考地址: https://echarts.apache.org/examples/editor.html?c=funnel 目前无法实现的功能: 1、暂时无法对漏斗图的长宽等范围操作进行修改 """ x_data = ["展现", "点击", "访问", "咨询", "订单"] y_data = [100, 80, 60, 40, 20] data = [[x_data[i], y_data[i]] for i in range(len(x_data))] ( Funnel(init_opts=opts.InitOpts(width="1600px", height="800px")) .add( series_name="", 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"), itemstyle_opts=opts.ItemStyleOpts(border_color="#fff", border_width=1), ) .set_global_opts(title_opts=opts.TitleOpts(title="漏斗图", subtitle="纯属虚构")) .render("funnel_chart.html") )
from pyecharts import options as opts from pyecharts.charts import Funnel from pyecharts.faker import Faker c = ( Funnel() .add( "商品", [list(z) for z in zip(Faker.choose(), Faker.values())], label_opts=opts.LabelOpts(position="inside"), ) .set_global_opts(title_opts=opts.TitleOpts(title="Funnel-Label(inside)")) .render("funnel_label_inside.html") )
class Gauge(
# 初始化配置项,参考 `global_options.InitOpts`
init_opts: opts.InitOpts = opts.InitOpts()
)
def add( # 系列名称,用于 tooltip 的显示,legend 的图例筛选。 series_name: str, # 系列数据项,格式为 [(key1, value1), (key2, value2)] data_pair: Sequence, # 是否选中图例 is_selected: bool = True, # 最小的数据值 min_: Numeric = 0, # 最大的数据值 max_: Numeric = 100, # 仪表盘平均分割段数 split_number: Numeric = 10, # 仪表盘半径,可以是相对于容器高宽中较小的一项的一半的百分比,也可以是绝对的数值。 radius: types.Union[types.Numeric, str] = "75%", # 仪表盘起始角度。圆心 正右手侧为0度,正上方为 90 度,正左手侧为 180 度。 start_angle: Numeric = 225, # 仪表盘结束角度。 end_angle: Numeric = -45, # 仪表盘刻度是否是顺时针增长。 is_clock_wise: bool = True, # 轮盘内标题文本项标签配置项,参考 `chart_options.GaugeTitleOpts` title_label_opts: types.GaugeTitle = opts.GaugeTitleOpts(), # 轮盘内数据项标签配置项,参考 `chart_options.GaugeDetailOpts` detail_label_opts: types.GaugeDetail = opts.GaugeDetailOpts(formatter="{value}%"), # 仪表盘指针配置项目,参考 `chart_options.GaugePointerOpts` pointer: types.GaugePointer = opts.GaugePointerOpts(), # 提示框组件配置项,参考 `series_options.TooltipOpts` tooltip_opts: Union[opts.TooltipOpts, dict, None] = None, # 图元样式配置项,参考 `series_options.ItemStyleOpts` itemstyle_opts: Union[opts.ItemStyleOpts, dict, None] = None, )
class GaugeTitleOpts(
)
class GaugeDetailOpts( # 是否显示详情。 is_show: bool = True, # 文字块背景色。 # 可以是直接的颜色值,例如:'#123234', 'red', 'rgba(0,23,11,0.3)'。 background_color: str = "transparent", # 文字块边框宽度。 border_width: Numeric = 0, # 文字块边框颜色。 border_color: str = "transparent", # 相对于仪表盘中心的偏移位置,数组第一项是水平方向的偏移,第二项是垂直方向的偏移。 # 可以是绝对的数值,也可以是相对于仪表盘半径的百分比。 offset_center: Sequence = [0, "-40%"], # 格式化函数或者字符串 formatter: Optional[JSFunc] = None, # 文字的颜色。 color: str = "auto", # 文字字体的风格。可选:'normal','italic','oblique' font_style: str = "normal", # 文字字体的粗细。可选:'normal','bold','bolder', 'lighter', 100 | 200 | 300 | 400... font_weight: str = "normal", # 文字的字体系列。还可以是 'serif' , 'monospace', 'Arial', 'Courier New', 'Microsoft YaHei', ... font_family: str = "sans-serif", # 文字的字体大小 font_size: Numeric = 15, # 文字块的圆角。 border_radius: Numeric = 0, # 文字块的内边距。例如: # padding: [3, 4, 5, 6]:表示 [上, 右, 下, 左] 的边距。 # padding: 4:表示 padding: [4, 4, 4, 4]。 # padding: [3, 4]:表示 padding: [3, 4, 3, 4]。 # 注意,文字块的 width 和 height 指定的是内容高宽,不包含 padding。 padding: Numeric = 0, # 文字块的背景阴影颜色。 shadow_color: Optional[str] = "transparent", # 文字块的背景阴影长度。 shadow_blur: Optional[Numeric] = 0, # 文字块的背景阴影 X 偏移。 shadow_offset_x: Numeric = 0, # 文字块的背景阴影 Y 偏移。 shadow_offset_y: Numeric = 0, )
class GaugePointerOpts(
# 是否显示指针。
is_show: bool = True,
# 指针长度,可以是绝对数值,也可以是相对于半径的半分比。
length: Union[str, Numeric] = "80%",
# 指针宽度。
width: Numeric = 8,
)
import pyecharts.options as opts from pyecharts.charts import Gauge """ Gallery 使用 pyecharts 1.1.0 参考地址: https://echarts.apache.org/examples/editor.html?c=gauge 目前无法实现的功能: 1、暂无 """ ( Gauge(init_opts=opts.InitOpts(width="1600px", height="800px")) .add(series_name="业务指标", data_pair=[["完成率", 55.5]]) .set_global_opts( legend_opts=opts.LegendOpts(is_show=False), tooltip_opts=opts.TooltipOpts(is_show=True, formatter="{a} <br/>{b} : {c}%"), ) .render("gauge.html") )
from pyecharts import options as opts
from pyecharts.charts import Gauge
c = (
Gauge()
.add("", [("完成率", 66.6)])
.set_global_opts(title_opts=opts.TitleOpts(title="Gauge-基本示例"))
.render("gauge_base.html")
)
from pyecharts import options as opts from pyecharts.charts import Gauge c = ( Gauge() .add( "业务指标", [("完成率", 55.5)], axisline_opts=opts.AxisLineOpts( linestyle_opts=opts.LineStyleOpts( color=[(0.3, "#67e0e3"), (0.7, "#37a2da"), (1, "#fd666d")], width=30 ) ), ) .set_global_opts( title_opts=opts.TitleOpts(title="Gauge-不同颜色"), legend_opts=opts.LegendOpts(is_show=False), ) .render("gauge_color.html") )
## 54.4 Gauge - Gauge_label_title_setting
链接
from pyecharts import options as opts from pyecharts.charts import Gauge c = ( Gauge() .add( "", [("完成率", 66.6)], title_label_opts=opts.LabelOpts( font_size=40, color="blue", font_family="Microsoft YaHei" ), ) .set_global_opts(title_opts=opts.TitleOpts(title="Gauge-改变轮盘内的字体")) .render("gauge_label_title_setting.html") )
import pyecharts.options as opts from pyecharts.charts import Gauge """ Gallery 使用 pyecharts 1.1.0 参考地址: https://gallery.echartsjs.com/editor.html?c=xH1vxib94f 目前无法实现的功能: 1、暂无 """ ( Gauge(init_opts=opts.InitOpts(width="1600px", height="800px")) .add(series_name="业务指标", data_pair=[["完成率", 55.5]]) .set_global_opts( legend_opts=opts.LegendOpts(is_show=False), tooltip_opts=opts.TooltipOpts(is_show=True, formatter="{a} <br/>{b} : {c}%"), ) .set_series_opts( axisline_opts=opts.AxisLineOpts( linestyle_opts=opts.LineStyleOpts( color=[[0.3, "#67e0e3"], [0.7, "#37a2da"], [1, "#fd666d"]], width=30 ) ) ) .render("gauge_change_color.html") )
from pyecharts import options as opts from pyecharts.charts import Gauge c = ( Gauge() .add( "业务指标", [("完成率", 55.5)], split_number=5, axisline_opts=opts.AxisLineOpts( linestyle_opts=opts.LineStyleOpts( color=[(0.3, "#67e0e3"), (0.7, "#37a2da"), (1, "#fd666d")], width=30 ) ), detail_label_opts=opts.LabelOpts(formatter="{value}"), ) .set_global_opts( title_opts=opts.TitleOpts(title="Gauge-分割段数-Label"), legend_opts=opts.LegendOpts(is_show=False), ) .render("gauge_splitnum_label.html") )
from pyecharts import options as opts
from pyecharts.charts import Gauge
c = (
Gauge()
.add("", [("完成率", 66.6)], radius="50%")
.set_global_opts(title_opts=opts.TitleOpts(title="Gauge-修改 Radius 为 50%"))
.render("gauge_change_radius.html")
)
class Graph(
# 初始化配置项,参考 `global_options.InitOpts`
init_opts: opts.InitOpts = opts.InitOpts()
)
def add( # 系列名称,用于 tooltip 的显示,legend 的图例筛选。 series_name: str, # 关系图节点数据项列表,参考 `opts.GraphNode` nodes: Sequence[Union[opts.GraphNode, dict]], # 关系图节点间关系数据项列表,参考 `opts.GraphLink` links: Sequence[Union[opts.GraphLink, dict]], # 关系图节点分类的类目列表,参考 `opts.GraphCategory` categories: Union[Sequence[Union[opts.GraphCategory, dict]], None] = None, # 是否选中图例。 is_selected: bool = True, # 是否在鼠标移到节点上的时候突出显示节点以及节点的边和邻接节点。 is_focusnode: bool = True, # 是否开启鼠标缩放和平移漫游。 is_roam: bool = True, # 节点是否可拖拽,只在使用力引导布局的时候有用。 is_draggable: bool = False, # 是否旋转标签,默认不旋转。 is_rotate_label: bool = False, # 图的布局。可选: # 'none' 不采用任何布局,使用节点中提供的 x, y 作为节点的位置。 # 'circular' 采用环形布局。 # 'force' 采用力引导布局。 layout: str = "force", # 关系图节点标记的图形。 # ECharts 提供的标记类型包括 'circle', 'rect', 'roundRect', 'triangle', # 'diamond', 'pin', 'arrow', 'none' # 可以通过 'image://url' 设置为图片,其中 URL 为图片的链接,或者 dataURI。 symbol: Optional[str] = None, # 关系图节点标记的大小 # 可以设置成诸如 10 这样单一的数字 # 也可以用数组分开表示宽和高,例如 [20, 10] 表示标记宽为20,高为10。 symbol_size: types.Numeric = 10, # 边的两个节点之间的距离,这个距离也会受 repulsion。 # 支持设置成数组表达边长的范围,此时不同大小的值会线性映射到不同的长度。值越小则长度越长。 edge_length: Numeric = 50, # 节点受到的向中心的引力因子。该值越大节点越往中心点靠拢。 gravity: Numeric = 0.2, # 节点之间的斥力因子。 # 支持设置成数组表达斥力的范围,此时不同大小的值会线性映射到不同的斥力。值越大则斥力越大 repulsion: Numeric = 50, # Graph 图节点边的 Label 配置(即在边上显示数据或标注的配置) edge_label: types.Label = None, # 边两端的标记类型,可以是一个数组分别指定两端,也可以是单个统一指定。 # 默认不显示标记,常见的可以设置为箭头,如下:edgeSymbol: ['circle', 'arrow'] edge_symbol: Optional[str] = None, # 边两端的标记大小,可以是一个数组分别指定两端,也可以是单个统一指定。 edge_symbol_size: Numeric = 10, # 标签配置项,参考 `series_options.LabelOpts` label_opts: Union[opts.LabelOpts, dict] = opts.LabelOpts(), # 关系边的公用线条样式。 linestyle_opts: Union[opts.LineStyleOpts, dict] = opts.LineStyleOpts(), # 提示框组件配置项,参考 `series_options.TooltipOpts` tooltip_opts: Union[opts.TooltipOpts, dict, None] = None, # 图元样式配置项,参考 `series_options.ItemStyleOpts` itemstyle_opts: Union[opts.ItemStyleOpts, dict, None] = None, )
class GraphNode( # 数据项名称。 name: Optional[str] = None, # 节点的初始 x 值。在不指定的时候需要指明layout属性选择布局方式。 x: Optional[Numeric] = None, # 节点的初始 y 值。在不指定的时候需要指明layout属性选择布局方式。 y: Optional[Numeric] = None, # 节点在力引导布局中是否固定。 is_fixed: bool = False, # 数据项值。 value: Union[str, Sequence, None] = None, # 数据项所在类目的 index。 category: Optional[int] = None, # 该类目节点标记的图形。 # ECharts 提供的标记类型包括 'circle', 'rect', 'roundRect', 'triangle', # 'diamond', 'pin', 'arrow', 'none' # 可以通过 'image://url' 设置为图片,其中 URL 为图片的链接,或者 dataURI。 symbol: Optional[str] = None, # 该类目节点标记的大小,可以设置成诸如 10 这样单一的数字,也可以用数组分开表示宽和高, # 例如 [20, 10] 表示标记宽为 20,高为 10。 symbol_size: Union[Numeric, Sequence, None] = None, # 标签配置项,参考 `series_options.LabelOpts` label_opts: Optional[LabelOpts] = None, )
class GraphLink( # 边的源节点名称的字符串,也支持使用数字表示源节点的索引。 source: Union[str, int, None] = None, # 边的目标节点名称的字符串,也支持使用数字表示源节点的索引。 target: Union[str, int, None] = None, # 边的数值,可以在力引导布局中用于映射到边的长度。 value: Optional[Numeric] = None, # 边两端的标记类型,可以是一个数组分别指定两端,也可以是单个统一指定。 symbol: Union[str, Sequence, None] = None, # 边两端的标记大小,可以是一个数组分别指定两端,也可以是单个统一指定。 symbol_size: Union[Numeric, Sequence, None] = None, # 关系边的线条样式,参考 `series_options.LineStyleOpts` linestyle_opts: Optional[LineStyleOpts] = None, # 标签样式,参考 `series_options.LabelOpts` label_opts: Optional[LabelOpts] = None, )
class GraphCategory( # 类目名称,用于和 legend 对应以及格式化 tooltip 的内容。 name: Optional[str] = None, # 该类目节点标记的图形。 # ECharts 提供的标记类型包括 'circle', 'rect', 'roundRect', 'triangle', # 'diamond', 'pin', 'arrow', 'none' # 可以通过 'image://url' 设置为图片,其中 URL 为图片的链接,或者 dataURI。 symbol: Optional[str] = None, # 该类目节点标记的大小,可以设置成诸如 10 这样单一的数字,也可以用数组分开表示宽和高, # 例如 [20, 10] 表示标记宽为 20,高为 10。 symbol_size: Union[Numeric, Sequence, None] = None, # # 标签样式,参考 `series_options.LabelOpts` label_opts: Optional[LabelOpts] = None, )
from pyecharts import options as opts from pyecharts.charts import Graph 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="Graph-基本示例")) .render("graph_base.html") )
from pyecharts import options as opts from pyecharts.charts import Graph nodes_data = [ opts.GraphNode(name="结点1", symbol_size=10), opts.GraphNode(name="结点2", symbol_size=20), opts.GraphNode(name="结点3", symbol_size=30), opts.GraphNode(name="结点4", symbol_size=40), opts.GraphNode(name="结点5", symbol_size=50), opts.GraphNode(name="结点6", symbol_size=60), ] links_data = [ opts.GraphLink(source="结点1", target="结点2", value=2), opts.GraphLink(source="结点2", target="结点3", value=3), opts.GraphLink(source="结点3", target="结点4", value=4), opts.GraphLink(source="结点4", target="结点5", value=5), opts.GraphLink(source="结点5", target="结点6", value=6), opts.GraphLink(source="结点6", target="结点1", value=7), ] c = ( Graph() .add( "", nodes_data, links_data, repulsion=4000, edge_label=opts.LabelOpts( is_show=True, position="middle", formatter="{b} 的数据 {c}" ), ) .set_global_opts( title_opts=opts.TitleOpts(title="Graph-GraphNode-GraphLink-WithEdgeLabel") ) .render("graph_with_edge_options.html") )
from pyecharts import options as opts from pyecharts.charts import Graph nodes = [ opts.GraphNode(name="结点1", symbol_size=10), opts.GraphNode(name="结点2", symbol_size=20), opts.GraphNode(name="结点3", symbol_size=30), opts.GraphNode(name="结点4", symbol_size=40), opts.GraphNode(name="结点5", symbol_size=50), ] links = [ opts.GraphLink(source="结点1", target="结点2"), opts.GraphLink(source="结点2", target="结点3"), opts.GraphLink(source="结点3", target="结点4"), opts.GraphLink(source="结点4", target="结点5"), opts.GraphLink(source="结点5", target="结点1"), ] c = ( Graph() .add("", nodes, links, repulsion=4000) .set_global_opts(title_opts=opts.TitleOpts(title="Graph-GraphNode-GraphLink")) .render("graph_with_options.html") )
import json from pyecharts import options as opts from pyecharts.charts import Graph with open("weibo.json", "r", encoding="utf-8") as f: j = json.load(f) nodes, links, categories, cont, mid, userl = j c = ( Graph() .add( "", nodes, links, categories, repulsion=50, linestyle_opts=opts.LineStyleOpts(curve=0.2), label_opts=opts.LabelOpts(is_show=False), ) .set_global_opts( legend_opts=opts.LegendOpts(is_show=False), title_opts=opts.TitleOpts(title="Graph-微博转发关系图"), ) .render("graph_weibo.html") )
import asyncio from aiohttp import TCPConnector, ClientSession import pyecharts.options as opts from pyecharts.charts import Graph """ Gallery 使用 pyecharts 1.1.0 参考地址: https://echarts.apache.org/examples/editor.html?c=graph-npm 目前无法实现的功能: 1、暂无 """ async def get_json_data(url: str) -> dict: async with ClientSession(connector=TCPConnector(ssl=False)) as session: async with session.get(url=url) as response: return await response.json() # 获取官方的数据 data = asyncio.run( get_json_data( url="https://echarts.apache.org/examples/data/asset/data/npmdepgraph.min10.json" ) ) nodes = [ { "x": node["x"], "y": node["y"], "id": node["id"], "name": node["label"], "symbolSize": node["size"], "itemStyle": {"normal": {"color": node["color"]}}, } for node in data["nodes"] ] edges = [ {"source": edge["sourceID"], "target": edge["targetID"]} for edge in data["edges"] ] ( Graph(init_opts=opts.InitOpts(width="1600px", height="800px")) .add( series_name="", nodes=nodes, links=edges, layout="none", is_roam=True, is_focusnode=True, label_opts=opts.LabelOpts(is_show=False), linestyle_opts=opts.LineStyleOpts(width=0.5, curve=0.3, opacity=0.7), ) .set_global_opts(title_opts=opts.TitleOpts(title="NPM Dependencies")) .render("npm_dependencies.html") )
import json from pyecharts import options as opts from pyecharts.charts import Graph with 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="Graph-Les Miserables"), legend_opts=opts.LegendOpts(orient="vertical", pos_left="2%", pos_top="20%"), ) .render("graph_les_miserables.html") )
class Liquid(
# 初始化配置项,参考 `global_options.InitOpts`
init_opts: opts.InitOpts = opts.InitOpts()
)
def add( # 系列名称,用于 tooltip 的显示,legend 的图例筛选。 series_name: str, # 系列数据,格式为 [value1, value2, ....] data: Sequence, # 水球外形,有' circle', 'rect', 'roundRect', 'triangle', 'diamond', 'pin', 'arrow' 可选。 # 默认 'circle'。也可以为自定义的 SVG 路径。 shape: str = "circle", # 波浪颜色。 color: Optional[Sequence[str]] = None, # 背景颜色 background_color: types.Union[str, dict, None] = None, # 是否显示波浪动画。 is_animation: bool = True, # 是否显示边框。 is_outline_show: bool = True, # 外沿边框宽度 outline_border_distance: types.Numeric = 8, # 外沿样式 outline_itemstyle_opts: types.ItemStyle = None, # 标签配置项,参考 `series_options.LabelOpts` label_opts: Union[opts.LabelOpts, dict] = opts.LabelOpts(font_size=50, position="inside"), # 提示框组件配置项,参考 `series_options.TooltipOpts` tooltip_opts: Union[opts.TooltipOpts, dict, None] = None, )
from pyecharts import options as opts
from pyecharts.charts import Liquid
from pyecharts.globals import SymbolType
c = (
Liquid()
.add("lq", [0.3, 0.7], is_outline_show=False, shape=SymbolType.DIAMOND)
.set_global_opts(title_opts=opts.TitleOpts(title="Liquid-Shape-Diamond"))
.render("liquid_shape_diamond")
)
from pyecharts import options as opts from pyecharts.charts import Grid, Liquid from pyecharts.commons.utils import JsCode l1 = ( Liquid() .add("lq", [0.6, 0.7], center=["60%", "50%"]) .set_global_opts(title_opts=opts.TitleOpts(title="多个 Liquid 显示")) ) l2 = Liquid().add( "lq", [0.3254], center=["25%", "50%"], label_opts=opts.LabelOpts( font_size=50, formatter=JsCode( """function (param) { return (Math.floor(param.value * 10000) / 100) + '%'; }""" ), position="inside", ), ) grid = Grid().add(l1, grid_opts=opts.GridOpts()).add(l2, grid_opts=opts.GridOpts()) grid.render("multiple_liquid.html")
from pyecharts import options as opts
from pyecharts.charts import Liquid
from pyecharts.globals import SymbolType
c = (
Liquid()
.add("lq", [0.3, 0.7], is_outline_show=False, shape=SymbolType.RECT)
.set_global_opts(title_opts=opts.TitleOpts(title="Liquid-Shape-rect"))
.render("liquid_shape_rect.html")
)
from pyecharts import options as opts
from pyecharts.charts import Liquid
c = (
Liquid()
.add("lq", [0.6, 0.7])
.set_global_opts(title_opts=opts.TitleOpts(title="Liquid-基本示例"))
.render("liquid_base.html")
)
from pyecharts import options as opts from pyecharts.charts import Liquid from pyecharts.commons.utils import JsCode c = ( Liquid() .add( "lq", [0.3254], label_opts=opts.LabelOpts( font_size=50, formatter=JsCode( """function (param) { return (Math.floor(param.value * 10000) / 100) + '%'; }""" ), position="inside", ), ) .set_global_opts(title_opts=opts.TitleOpts(title="Liquid-数据精度")) .render("liquid_data_precision.html") )
from pyecharts import options as opts
from pyecharts.charts import Liquid
c = (
Liquid()
.add("lq", [0.6, 0.7, 0.8], is_outline_show=False)
.set_global_opts(title_opts=opts.TitleOpts(title="Liquid-无边框"))
.render("liquid_without_outline.html")
)
from pyecharts import options as opts
from pyecharts.charts import Liquid
from pyecharts.globals import SymbolType
c = (
Liquid()
.add("lq", [0.3, 0.7], is_outline_show=False, shape=SymbolType.ARROW)
.set_global_opts(title_opts=opts.TitleOpts(title="Liquid-Shape-arrow"))
.render("liquid_shape_arrow.html")
)
class Parallel(
# 初始化配置项,参考 `global_options.InitOpts`
init_opts: opts.InitOpts = opts.InitOpts()
)
def add_schema(
schema: Sequence[Union[opts.ParallelAxisOpts, dict]],
parallel_opts: Union[opts.ParallelOpts, dict, None] = None,
)
def add( # 系列名称,用于 tooltip 的显示,legend 的图例筛选。 series_name: str, # 系列数据 data: types.Sequence[types.Union[opts.ParallelItem, dict]], # 是否选中图例。 is_selected: bool = True, # 是否平滑曲线 is_smooth: bool = False, # 线条样式,参考 `series_options.LineStyleOpts` linestyle_opts: Union[opts.LineStyleOpts, dict] = opts.LineStyleOpts(), # 提示框组件配置项,参考 `series_options.TooltipOpts` tooltip_opts: Union[opts.TooltipOpts, dict, None] = None, # 图元样式配置项,参考 `series_options.ItemStyleOpts` itemstyle_opts: Union[opts.ItemStyleOpts, dict, None] = None, )
class ParallelOpts( # parallel 组件离容器左侧的距离。 # left 的值可以是像 20 这样的具体像素值,可以是像 '20%' 这样相对于容器高宽的百分比, # 也可以是 'left', 'center', 'right'。 # 如果 left 的值为'left', 'center', 'right',组件会根据相应的位置自动对齐。 pos_left: str = "5%", # parallel 组件离容器右侧的距离。 # right 的值可以是像 20 这样的具体像素值,可以是像 '20%' 这样相对于容器高宽的百分比。 pos_right: str = "13%", # parallel 组件离容器下侧的距离。 # bottom 的值可以是像 20 这样的具体像素值,可以是像 '20%' 这样相对于容器高宽的百分比。 pos_bottom: str = "10%", # parallel 组件离容器上侧的距离。 # top 的值可以是像 20 这样的具体像素值,可以是像 '20%' 这样相对于容器高宽的百分比, # 也可以是 'top', 'middle', 'bottom'。 # 如果 top 的值为'top', 'middle', 'bottom',组件会根据相应的位置自动对齐。 pos_top: str = "20%", # 布局方式,可选值为: # 'horizontal':水平排布各个坐标轴。 # 'vertical':竖直排布各个坐标轴。 layout: Optional[str] = None, )
class ParallelAxisOpts( # 坐标轴的维度序号。 dim: Numeric, # 坐标轴名称。 name: str, # 坐标轴数据项 data: Sequence = None, # 坐标轴类型。可选: # 'value': 数值轴,适用于连续数据。 # 'category': 类目轴,适用于离散的类目数据,为该类型时必须通过 data 设置类目数据。 # 'time': 时间轴,适用于连续的时序数据,与数值轴相比时间轴带有时间的格式化,在刻度计算上也有所不同 # 例如会根据跨度的范围来决定使用月,星期,日还是小时范围的刻度。 # 'log' 对数轴。适用于对数数据。 type_: Optional[str] = None, # 坐标轴刻度最小值。 # 可以设置成特殊值 'dataMin',此时取数据在该轴上的最小值作为最小刻度。 # 不设置时会自动计算最小值保证坐标轴刻度的均匀分布。 # 在类目轴中,也可以设置为类目的序数(如类目轴 data: ['类A', '类B', '类C'] 中,序数 2 表示 '类C' # 也可以设置为负数,如 -3)。 min_: Union[str, Numeric, None] = None, # 坐标轴刻度最大值。 # 可以设置成特殊值 'dataMax',此时取数据在该轴上的最大值作为最大刻度。 # 不设置时会自动计算最大值保证坐标轴刻度的均匀分布。 # 在类目轴中,也可以设置为类目的序数(如类目轴 data: ['类A', '类B', '类C'] 中,序数 2 表示 '类C' # 也可以设置为负数,如 -3)。 max_: Union[str, Numeric, None] = None, # 只在数值轴中(type: 'value')有效。 # 是否是脱离 0 值比例。设置成 true 后坐标刻度不会强制包含零刻度。在双数值轴的散点图中比较有用。 # 在设置 min 和 max 之后该配置项无效。 is_scale: bool = False, )
class ParallelItem( # 数据项名称。 name: Optional[str] = None, # 数据项值。 value: Optional[Sequence] = None, # 线条样式。 linestyle_opts: Union[LineStyleOpts, dict, None] = None, # 线的颜色。 color: Union[str, dict] = "#000", # 线宽。 width: Numeric = 2, # 线的类型。可选'solid','dashed','dotted' type_: str = "solid", # 图形透明度。支持从 0 到 1 的数字,为 0 时不绘制该图形。 opacity: Numeric = 0.45, )
import pyecharts.options as opts from pyecharts.charts import Parallel """ Gallery 使用 pyecharts 1.1.0 参考地址: https://echarts.apache.org/examples/editor.html?c=parallel-simple 目前无法实现的功能: 1、 """ parallel_axis = [ {"dim": 0, "name": "Price"}, {"dim": 1, "name": "Net Weight"}, {"dim": 2, "name": "Amount"}, { "dim": 3, "name": "Score", "type": "category", "data": ["Excellent", "Good", "OK", "Bad"], }, ] data = [[12.99, 100, 82, "Good"], [9.99, 80, 77, "OK"], [20, 120, 60, "Excellent"]] ( Parallel(init_opts=opts.InitOpts(width="1400px", height="800px")) .add_schema(schema=parallel_axis) .add( series_name="", data=data, linestyle_opts=opts.LineStyleOpts(width=4, opacity=0.5), ) .render("basic_parallel.html") )
from pyecharts import options as opts from pyecharts.charts import Parallel data = [ [1, 91, 45, 125, 0.82, 34, 23, "良"], [2, 65, 27, 78, 0.86, 45, 29, "良"], [3, 83, 60, 84, 1.09, 73, 27, "良"], [4, 109, 81, 121, 1.28, 68, 51, "轻度污染"], [5, 106, 77, 114, 1.07, 55, 51, "轻度污染"], [6, 109, 81, 121, 1.28, 68, 51, "轻度污染"], [7, 106, 77, 114, 1.07, 55, 51, "轻度污染"], [8, 89, 65, 78, 0.86, 51, 26, "良"], [9, 53, 33, 47, 0.64, 50, 17, "良"], [10, 80, 55, 80, 1.01, 75, 24, "良"], [11, 117, 81, 124, 1.03, 45, 24, "轻度污染"], [12, 99, 71, 142, 1.1, 62, 42, "良"], [13, 95, 69, 130, 1.28, 74, 50, "良"], [14, 116, 87, 131, 1.47, 84, 40, "轻度污染"], ] c = ( Parallel() .add_schema( [ opts.ParallelAxisOpts(dim=0, name="data"), opts.ParallelAxisOpts(dim=1, name="AQI"), opts.ParallelAxisOpts(dim=2, name="PM2.5"), opts.ParallelAxisOpts(dim=3, name="PM10"), opts.ParallelAxisOpts(dim=4, name="CO"), opts.ParallelAxisOpts(dim=5, name="NO2"), opts.ParallelAxisOpts(dim=6, name="CO2"), opts.ParallelAxisOpts( dim=7, name="等级", type_="category", data=["优", "良", "轻度污染", "中度污染", "重度污染", "严重污染"], ), ] ) .add("parallel", data) .set_global_opts(title_opts=opts.TitleOpts(title="Parallel-Category")) .render("parallel_category.html") )
class Pie(
# 初始化配置项,参考 `global_options.InitOpts`
init_opts: opts.InitOpts = opts.InitOpts()
)
def add( # 系列名称,用于 tooltip 的显示,legend 的图例筛选。 series_name: str, # 系列数据项,格式为 [(key1, value1), (key2, value2)] data_pair: types.Sequence[types.Union[types.Sequence, opts.PieItem, dict]], # 系列 label 颜色 color: Optional[str] = None, # 饼图的半径,数组的第一项是内半径,第二项是外半径 # 默认设置成百分比,相对于容器高宽中较小的一项的一半 radius: Optional[Sequence] = None, # 饼图的中心(圆心)坐标,数组的第一项是横坐标,第二项是纵坐标 # 默认设置成百分比,设置成百分比时第一项是相对于容器宽度,第二项是相对于容器高度 center: Optional[Sequence] = None, # 是否展示成南丁格尔图,通过半径区分数据大小,有'radius'和'area'两种模式。 # radius:扇区圆心角展现数据的百分比,半径展现数据的大小 # area:所有扇区圆心角相同,仅通过半径展现数据大小 rosetype: Optional[str] = None, # 饼图的扇区是否是顺时针排布。 is_clockwise: bool = True, # 标签配置项,参考 `series_options.LabelOpts` label_opts: Union[opts.LabelOpts, dict] = opts.LabelOpts(), # 提示框组件配置项,参考 `series_options.TooltipOpts` tooltip_opts: Union[opts.TooltipOpts, dict, None] = None, # 图元样式配置项,参考 `series_options.ItemStyleOpts` itemstyle_opts: Union[opts.ItemStyleOpts, dict, None] = None, # 可以定义 data 的哪个维度被编码成什么。 encode: types.Union[types.JSFunc, dict, None] = None, )
class PieItem( # 数据项名称。 name: Optional[str] = None, # 数据值。 value: Optional[Numeric] = None, # 该数据项是否被选中。 is_selected: bool = False, # 标签配置项,参考 `series_options.LabelOpts` label_opts: Union[LabelOpts, dict, None] = None, # 图元样式配置项,参考 `series_options.ItemStyleOpts` itemstyle_opts: Union[ItemStyleOpts, dict, None] = None, # 提示框组件配置项,参考 `series_options.TooltipOpts` tooltip_opts: Union[TooltipOpts, dict, None] = None, )
class PieLabelLineOpts( # 是否显示视觉引导线。 is_show: bool = True, # 视觉引导线第一段的长度。 length: Numeric = None, # 视觉引导项第二段的长度。 length_2: Numeric = None, # 是否平滑视觉引导线,默认不平滑,可以设置成 true 平滑显示。 # 也可以设置为 0 到 1 的值,表示平滑程度。 smooth: Union[bool, Numeric] = False, # 线条样式,参考 `LineStyleOpts` linestyle_opts: Union[LineStyleOpts, dict, None] = None, )
from pyecharts import options as opts
from pyecharts.charts import Pie
from pyecharts.faker import Faker
c = (
Pie()
.add("", [list(z) for z in zip(Faker.choose(), Faker.values())])
.set_colors(["blue", "green", "yellow", "red", "pink", "orange", "purple"])
.set_global_opts(title_opts=opts.TitleOpts(title="Pie-设置颜色"))
.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}"))
.render("pie_set_color.html")
)
import pyecharts.options as opts from pyecharts.charts import Pie """ Gallery 使用 pyecharts 1.1.0 参考地址: https://echarts.apache.org/examples/editor.html?c=pie-doughnut 目前无法实现的功能: 1、迷之颜色映射的问题 """ x_data = ["直接访问", "邮件营销", "联盟广告", "视频广告", "搜索引擎"] y_data = [335, 310, 274, 235, 400] data_pair = [list(z) for z in zip(x_data, y_data)] data_pair.sort(key=lambda x: x[1]) ( Pie(init_opts=opts.InitOpts(width="1600px", height="800px", bg_color="#2c343c")) .add( series_name="访问来源", data_pair=data_pair, rosetype="radius", radius="55%", center=["50%", "50%"], label_opts=opts.LabelOpts(is_show=False, position="center"), ) .set_global_opts( title_opts=opts.TitleOpts( title="Customized Pie", pos_left="center", pos_top="20", title_textstyle_opts=opts.TextStyleOpts(color="#fff"), ), legend_opts=opts.LegendOpts(is_show=False), ) .set_series_opts( tooltip_opts=opts.TooltipOpts( trigger="item", formatter="{a} <br/>{b}: {c} ({d}%)" ), label_opts=opts.LabelOpts(color="rgba(255, 255, 255, 0.3)"), ) .render("customized_pie.html") )
from pyecharts import options as opts from pyecharts.charts import Pie from pyecharts.faker import Faker c = ( Pie() .add( "", [list(z) for z in zip(Faker.choose(), Faker.values())], radius=["40%", "55%"], label_opts=opts.LabelOpts( position="outside", formatter="{a|{a}}{abg|}\n{hr|}\n {b|{b}: }{c} {per|{d}%} ", background_color="#eee", border_color="#aaa", border_width=1, border_radius=4, rich={ "a": {"color": "#999", "lineHeight": 22, "align": "center"}, "abg": { "backgroundColor": "#e3e3e3", "width": "100%", "align": "right", "height": 22, "borderRadius": [4, 4, 0, 0], }, "hr": { "borderColor": "#aaa", "width": "100%", "borderWidth": 0.5, "height": 0, }, "b": {"fontSize": 16, "lineHeight": 33}, "per": { "color": "#eee", "backgroundColor": "#334455", "padding": [2, 4], "borderRadius": 2, }, }, ), ) .set_global_opts(title_opts=opts.TitleOpts(title="Pie-富文本示例")) .render("pie_rich_label.html") )
from pyecharts import options as opts from pyecharts.charts import Pie from pyecharts.faker import Faker c = ( Pie() .add( "", [list(z) for z in zip(Faker.choose(), Faker.values())], center=["35%", "50%"], ) .set_global_opts( title_opts=opts.TitleOpts(title="Pie-调整位置"), legend_opts=opts.LegendOpts(pos_left="15%"), ) .set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}")) .render("pie_position.html") )
from pyecharts import options as opts
from pyecharts.charts import Pie
from pyecharts.faker import Faker
c = (
Pie()
.add("", [list(z) for z in zip(Faker.choose(), Faker.values())])
.set_global_opts(title_opts=opts.TitleOpts(title="Pie-基本示例"))
.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}"))
.render("pie_base.html")
)
from pyecharts import options as opts from pyecharts.charts import Pie from pyecharts.faker import Faker c = ( Pie() .add( "", [ list(z) for z in zip( Faker.choose() + Faker.choose() + Faker.choose(), Faker.values() + Faker.values() + Faker.values(), ) ], center=["40%", "50%"], ) .set_global_opts( title_opts=opts.TitleOpts(title="Pie-Legend 滚动"), legend_opts=opts.LegendOpts(type_="scroll", pos_left="80%", orient="vertical"), ) .set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}")) .render("pie_scroll_legend.html") )
import pyecharts.options as opts from pyecharts.charts import Pie """ Gallery 使用 pyecharts 1.1.0 参考地址: https://echarts.apache.org/examples/editor.html?c=pie-doughnut 目前无法实现的功能: 1、饼状图中间的图例名称暂时无法显示 """ x_data = ["直接访问", "邮件营销", "联盟广告", "视频广告", "搜索引擎"] y_data = [335, 310, 234, 135, 1548] ( Pie(init_opts=opts.InitOpts(width="1600px", height="1000px")) .add( series_name="访问来源", data_pair=[list(z) for z in zip(x_data, y_data)], radius=["50%", "70%"], label_opts=opts.LabelOpts(is_show=False, position="center"), ) .set_global_opts(legend_opts=opts.LegendOpts(pos_left="legft", orient="vertical")) .set_series_opts( tooltip_opts=opts.TooltipOpts( trigger="item", formatter="{a} <br/>{b}: {c} ({d}%)" ), # label_opts=opts.LabelOpts(formatter="{b}: {c}") ) .render("doughnut_chart.html") )
import pyecharts.options as opts from pyecharts.charts import Pie """ Gallery 使用 pyecharts 1.1.0 参考地址: https://echarts.apache.org/examples/editor.html?c=pie-nest 目前无法实现的功能: 1、暂无 """ inner_x_data = ["直达", "营销广告", "搜索引擎"] inner_y_data = [335, 679, 1548] inner_data_pair = [list(z) for z in zip(inner_x_data, inner_y_data)] outer_x_data = ["直达", "营销广告", "搜索引擎", "邮件营销", "联盟广告", "视频广告", "百度", "谷歌", "必应", "其他"] outer_y_data = [335, 310, 234, 135, 1048, 251, 147, 102] outer_data_pair = [list(z) for z in zip(outer_x_data, outer_y_data)] ( Pie(init_opts=opts.InitOpts(width="1600px", height="800px")) .add( series_name="访问来源", data_pair=inner_data_pair, radius=[0, "30%"], label_opts=opts.LabelOpts(position="inner"), ) .add( series_name="访问来源", radius=["40%", "55%"], data_pair=outer_data_pair, label_opts=opts.LabelOpts( position="outside", formatter="{a|{a}}{abg|}\n{hr|}\n {b|{b}: }{c} {per|{d}%} ", background_color="#eee", border_color="#aaa", border_width=1, border_radius=4, rich={ "a": {"color": "#999", "lineHeight": 22, "align": "center"}, "abg": { "backgroundColor": "#e3e3e3", "width": "100%", "align": "right", "height": 22, "borderRadius": [4, 4, 0, 0], }, "hr": { "borderColor": "#aaa", "width": "100%", "borderWidth": 0.5, "height": 0, }, "b": {"fontSize": 16, "lineHeight": 33}, "per": { "color": "#eee", "backgroundColor": "#334455", "padding": [2, 4], "borderRadius": 2, }, }, ), ) .set_global_opts(legend_opts=opts.LegendOpts(pos_left="left", orient="vertical")) .set_series_opts( tooltip_opts=opts.TooltipOpts( trigger="item", formatter="{a} <br/>{b}: {c} ({d}%)" ) ) .render("nested_pies.html") )
from pyecharts import options as opts from pyecharts.charts import Pie from pyecharts.commons.utils import JsCode fn = """ function(params) { if(params.name == '其他') return '\\n\\n\\n' + params.name + ' : ' + params.value + '%'; return params.name + ' : ' + params.value + '%'; } """ def new_label_opts(): return opts.LabelOpts(formatter=JsCode(fn), position="center") c = ( Pie() .add( "", [list(z) for z in zip(["剧情", "其他"], [25, 75])], center=["20%", "30%"], radius=[60, 80], label_opts=new_label_opts(), ) .add( "", [list(z) for z in zip(["奇幻", "其他"], [24, 76])], center=["55%", "30%"], radius=[60, 80], label_opts=new_label_opts(), ) .add( "", [list(z) for z in zip(["爱情", "其他"], [14, 86])], center=["20%", "70%"], radius=[60, 80], label_opts=new_label_opts(), ) .add( "", [list(z) for z in zip(["惊悚", "其他"], [11, 89])], center=["55%", "70%"], radius=[60, 80], label_opts=new_label_opts(), ) .set_global_opts( title_opts=opts.TitleOpts(title="Pie-多饼图基本示例"), legend_opts=opts.LegendOpts( type_="scroll", pos_top="20%", pos_left="80%", orient="vertical" ), ) .render("mutiple_pie.html") )
from pyecharts import options as opts from pyecharts.charts import Pie from pyecharts.faker import Faker v = Faker.choose() c = ( Pie() .add( "", [list(z) for z in zip(v, Faker.values())], radius=["30%", "75%"], center=["25%", "50%"], rosetype="radius", label_opts=opts.LabelOpts(is_show=False), ) .add( "", [list(z) for z in zip(v, Faker.values())], radius=["30%", "75%"], center=["75%", "50%"], rosetype="area", ) .set_global_opts(title_opts=opts.TitleOpts(title="Pie-玫瑰图示例")) .render("pie_rosetype.html") )
from pyecharts import options as opts from pyecharts.charts import Pie from pyecharts.faker import Faker c = ( Pie() .add( "", [list(z) for z in zip(Faker.choose(), Faker.values())], radius=["40%", "75%"], ) .set_global_opts( title_opts=opts.TitleOpts(title="Pie-Radius"), legend_opts=opts.LegendOpts(orient="vertical", pos_top="15%", pos_left="2%"), ) .set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}")) .render("pie_radius.html") )
class Polar(
# 初始化配置项,参考 `global_options.InitOpts`
init_opts: opts.InitOpts = opts.InitOpts()
)
def add_schema(
radiusaxis_opts: Union[opts.RadiusAxisOpts, dict] = opts.RadiusAxisOpts(),
angleaxis_opts: Union[opts.AngleAxisOpts, dict] = opts.AngleAxisOpts(),
)
def add( # 系列名称,用于 tooltip 的显示,legend 的图例筛选。 series_name: str, # 系列数据项 data: Sequence, # 是否选中图例 is_selected: bool = True, # 图表类型,支持 # ChartType.SCATTER, ChartType.LINE, ChartType.BAR,ChartType.EFFECT_SCATTER type_: str = "line", # ECharts 提供的标记类型包括 'circle', 'rect', 'roundRect', 'triangle', # 'diamond', 'pin', 'arrow', 'none' # 可以通过 'image://url' 设置为图片,其中 URL 为图片的链接,或者 dataURI。 symbol: Optional[str] = None, # 标记的大小,可以设置成诸如 10 这样单一的数字,也可以用数组分开表示宽和高, # 例如 [20, 10] 表示标记宽为 20,高为 10。 symbol_size: Numeric = 4, # 数据堆叠,同个类目轴上系列配置相同的 stack 值可以堆叠放置。 stack: Optional[str] = None, # 标签配置项,参考 `series_options.LabelOpts` label_opts: Union[opts.LabelOpts, dict] = opts.LabelOpts(), # 区域填充样式配置项,参考 `series_options.AreaStyleOpts` areastyle_opts: Union[opts.AreaStyleOpts, dict] = opts.AreaStyleOpts(), # 坐标轴刻度配置项,参考 `global_options.AxisTickOpts` axistick_opts: Union[AxisTickOpts, dict, None] = None, # 涟漪特效配置项,参考 `series_options.EffectOpts` effect_opts: Union[opts.EffectOpts, dict] = opts.EffectOpts(), # 提示框组件配置项,参考 `series_options.TooltipOpts` tooltip_opts: Union[opts.TooltipOpts, dict, None] = None, )
class RadiusAxisItem(
value: Optional[str] = None,
textstyle_opts: Optional[TextStyleOpts] = None,
)
class RadiusAxisOpts( # 径向轴所在的极坐标系的索引,默认使用第一个极坐标系。 polar_index: Optional[int] = None, # 数据项,参考 `global_options.RadiusAxisItem` data: Optional[Sequence[Union[RadiusAxisItem, dict, str]]] = None, # 坐标轴两边留白策略,类目轴和非类目轴的设置和表现不一样。 # 类目轴中 boundaryGap 可以配置为 true 和 false。默认为 true,这时候刻度只是作为分隔线, # 标签和数据点都会在两个刻度之间的带(band)中间。 # 非类目轴,包括时间,数值,对数轴,boundaryGap是一个两个值的数组,分别表示数据最小值和最大值的延伸范围 # 可以直接设置数值或者相对的百分比,在设置 min 和 max 后无效。 示例:boundaryGap: ['20%', '20%'] boundary_gap: Union[bool, Sequence] = None, # 坐标轴类型。可选: # 'value': 数值轴,适用于连续数据。 # 'category': 类目轴,适用于离散的类目数据,为该类型时必须通过 data 设置类目数据。 # 'time': 时间轴,适用于连续的时序数据,与数值轴相比时间轴带有时间的格式化,在刻度计算上也有所不同 # 例如会根据跨度的范围来决定使用月,星期,日还是小时范围的刻度。 # 'log' 对数轴。适用于对数数据。 type_: Optional[str] = None, # 坐标轴名称。 name: Optional[str] = None, # 坐标轴名称显示位置。可选: # 'start', 'middle' 或者 'center','end name_location: Optional[str] = None, # 坐标轴刻度最小值。 # 可以设置成特殊值 'dataMin',此时取数据在该轴上的最小值作为最小刻度。 # 不设置时会自动计算最小值保证坐标轴刻度的均匀分布。 # 在类目轴中,也可以设置为类目的序数(如类目轴 data: ['类A', '类B', '类C'] 中,序数 2 表示 '类C' # 也可以设置为负数,如 -3)。 min_: Union[str, Numeric, None] = None, # 坐标轴刻度最大值。 # 可以设置成特殊值 'dataMax',此时取数据在该轴上的最大值作为最大刻度。 # 不设置时会自动计算最大值保证坐标轴刻度的均匀分布。 # 在类目轴中,也可以设置为类目的序数(如类目轴 data: ['类A', '类B', '类C'] 中,序数 2 表示 '类C' # 也可以设置为负数,如 -3)。 max_: Union[str, Numeric, None] = None, # 只在数值轴中(type: 'value')有效。 # 是否是脱离 0 值比例。设置成 true 后坐标刻度不会强制包含零刻度。在双数值轴的散点图中比较有用。 # 在设置 min 和 max 之后该配置项无效。 is_scale: bool = False, # 强制设置坐标轴分割间隔。 interval: Optional[Numeric] = None, # 分割线配置项,参考 `series_options.SplitLineOpts` splitline_opts: Union[SplitLineOpts, dict, None] = None, # 坐标轴在 grid 区域中的分隔区域,默认不显示。参考 `series_options.SplitAreaOpts` splitarea_opts: Union[SplitAreaOpts, dict, None] = None, # 坐标轴线风格配置项,参考 `series_options.AxisLineOpts` axisline_opts: Union[AxisLineOpts, dict, None] = None, # 坐标轴线标签配置项,参考 `series_options.LabelOpts` axislabel_opts: Union[LabelOpts, dict, None] = None, # 半径轴组件的所有图形的 z 值。控制图形的前后顺序。z 值 小的图形会被 z 值大的图形覆盖 z: Optional[int] = None, )
class AngleAxisItem(
value: Optional[str] = None,
textstyle_opts: Optional[TextStyleOpts] = None,
)
class AngleAxisOpts( # 径向轴所在的极坐标系的索引,默认使用第一个极坐标系。 polar_index: Optional[int] = None, data: Optional[Sequence[Union[AngleAxisItem, dict, str]]] = None, start_angle: Optional[Numeric] = None, is_clockwise: bool = False, # 坐标轴两边留白策略,类目轴和非类目轴的设置和表现不一样。 # 类目轴中 boundaryGap 可以配置为 true 和 false。默认为 true,这时候刻度只是作为分隔线, # 标签和数据点都会在两个刻度之间的带(band)中间。 # 非类目轴,包括时间,数值,对数轴,boundaryGap是一个两个值的数组,分别表示数据最小值和最大值的延伸范围 # 可以直接设置数值或者相对的百分比,在设置 min 和 max 后无效。 示例:boundaryGap: ['20%', '20%'] boundary_gap: Union[bool, Sequence] = None, # 坐标轴类型。可选: # 'value': 数值轴,适用于连续数据。 # 'category': 类目轴,适用于离散的类目数据,为该类型时必须通过 data 设置类目数据。 # 'time': 时间轴,适用于连续的时序数据,与数值轴相比时间轴带有时间的格式化,在刻度计算上也有所不同 # 例如会根据跨度的范围来决定使用月,星期,日还是小时范围的刻度。 # 'log' 对数轴。适用于对数数据。 type_: Optional[str] = None, # 坐标轴刻度最小值。 # 可以设置成特殊值 'dataMin',此时取数据在该轴上的最小值作为最小刻度。 # 不设置时会自动计算最小值保证坐标轴刻度的均匀分布。 # 在类目轴中,也可以设置为类目的序数(如类目轴 data: ['类A', '类B', '类C'] 中,序数 2 表示 '类C' # 也可以设置为负数,如 -3)。 min_: Union[str, Numeric, None] = None, # 坐标轴刻度最大值。 # 可以设置成特殊值 'dataMax',此时取数据在该轴上的最大值作为最大刻度。 # 不设置时会自动计算最大值保证坐标轴刻度的均匀分布。 # 在类目轴中,也可以设置为类目的序数(如类目轴 data: ['类A', '类B', '类C'] 中,序数 2 表示 '类C' # 也可以设置为负数,如 -3)。 max_: Union[str, Numeric, None] = None, # 只在数值轴中(type: 'value')有效。 # 是否是脱离 0 值比例。设置成 true 后坐标刻度不会强制包含零刻度。在双数值轴的散点图中比较有用。 # 在设置 min 和 max 之后该配置项无效。 is_scale: bool = False, # 坐标轴的分割段数,需要注意的是这个分割段数只是个预估值,最后实际显示的段数会在这个基础上根据分割后坐标轴刻度显示的易读程度作调整。 # 在类目轴中无效。 split_number: Numeric = 5, # 强制设置坐标轴分割间隔。 interval: Optional[Numeric] = None, # 分割线风格配置项,参考 `series_options.SplitLineOpts` splitline_opts: Union[SplitLineOpts, dict, None] = None, # 坐标轴线风格配置项,参考 `series_options.AxisLineOpts` axisline_opts: Union[AxisLineOpts, dict, None] = None, # 坐标轴标签风格配置项,参考 `series_options.LabelOpts` axislabel_opts: Union[LabelOpts, dict, None] = None, # 半径轴组件的所有图形的 z 值。控制图形的前后顺序。z 值 小的图形会被 z 值大的图形覆盖 z: Optional[int] = None, )
import random
from pyecharts import options as opts
from pyecharts.charts import Polar
data = [(i, random.randint(1, 100)) for i in range(101)]
c = (
Polar()
.add("", data, type_="scatter", label_opts=opts.LabelOpts(is_show=False))
.set_global_opts(title_opts=opts.TitleOpts(title="Polar-Scatter0"))
.render("polar_scatter_0.html")
)
import math from pyecharts import options as opts from pyecharts.charts import Polar data = [] for i in range(101): theta = i / 100 * 360 r = 5 * (1 + math.sin(theta / 180 * math.pi)) data.append([r, theta]) hour = [i for i in range(1, 25)] c = ( Polar() .add_schema( angleaxis_opts=opts.AngleAxisOpts( data=hour, type_="value", boundary_gap=False, start_angle=0 ) ) .add("love", data, label_opts=opts.LabelOpts(is_show=False)) .set_global_opts(title_opts=opts.TitleOpts(title="Polar-Love")) .render("polar_love.html") )
from pyecharts import options as opts from pyecharts.charts import Polar from pyecharts.faker import Faker c = ( Polar() .add_schema( radiusaxis_opts=opts.RadiusAxisOpts(data=Faker.week, type_="category"), angleaxis_opts=opts.AngleAxisOpts(is_clockwise=True, max_=10), ) .add("A", [1, 2, 3, 4, 3, 5, 1], type_="bar") .set_global_opts(title_opts=opts.TitleOpts(title="Polar-RadiusAxis")) .set_series_opts(label_opts=opts.LabelOpts(is_show=True)) .render("polar_radius.html") )
import math import pyecharts.options as opts from pyecharts.charts import Polar """ Gallery 使用 pyecharts 1.1.0 参考地址: https://www.echartsjs.com/examples/editor.html?c=line-polar 目前无法实现的功能: 1、赞无 """ data = [] for i in range(0, 101): theta = i / 100 * 360 r = 5 * (1 + math.sin(theta / 180 * math.pi)) data.append([r, theta]) ( Polar(init_opts=opts.InitOpts(width="1600px", height="800px")) .add(series_name="line", data=data, label_opts=opts.LabelOpts(is_show=False)) .add_schema( angleaxis_opts=opts.AngleAxisOpts( start_angle=0, type_="value", is_clockwise=True ) ) .set_global_opts( tooltip_opts=opts.TooltipOpts(trigger="axis", axis_pointer_type="cross"), title_opts=opts.TitleOpts(title="极坐标双数值轴"), ) .render("two_value_axes_in_polar.html") )
import math import pyecharts.options as opts from pyecharts.charts import Polar """ Gallery 使用 pyecharts 1.1.0 参考地址: https://www.echartsjs.com/examples/editor.html?c=line-polar2 目前无法实现的功能: 1、赞无 """ data = [] for i in range(0, 360 + 1): t = i / 180 * math.pi r = math.sin(2 * t) * math.cos(2 * t) data.append([r, i]) ( Polar(init_opts=opts.InitOpts(width="1600px", height="800px")) .add( series_name="line", data=data, label_opts=opts.LabelOpts(is_show=False), symbol_size=0, ) .add_schema( angleaxis_opts=opts.AngleAxisOpts( start_angle=0, type_="value", is_clockwise=True ), radiusaxis_opts=opts.RadiusAxisOpts(min_=0), ) .set_global_opts( tooltip_opts=opts.TooltipOpts(trigger="axis", axis_pointer_type="cross"), title_opts=opts.TitleOpts(title="极坐标双数值轴"), ) .render("two_value_axes_in_polar_2.html") )
import random
from pyecharts import options as opts
from pyecharts.charts import Polar
c = (
Polar()
.add("", [(10, random.randint(1, 100)) for i in range(300)], type_="scatter")
.add("", [(11, random.randint(1, 100)) for i in range(300)], type_="scatter")
.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
.set_global_opts(title_opts=opts.TitleOpts(title="Polar-Scatter1"))
.render("polar_scatter_1.html")
)
from pyecharts import options as opts
from pyecharts.charts import Polar
from pyecharts.faker import Faker
c = (
Polar()
.add_schema(angleaxis_opts=opts.AngleAxisOpts(data=Faker.week, type_="category"))
.add("A", [1, 2, 3, 4, 3, 5, 1], type_="bar", stack="stack0")
.add("B", [2, 4, 6, 1, 2, 3, 1], type_="bar", stack="stack0")
.add("C", [1, 2, 3, 4, 1, 2, 5], type_="bar", stack="stack0")
.set_global_opts(title_opts=opts.TitleOpts(title="Polar-AngleAxis"))
.render("polar_angleaxis.html")
)
import math from pyecharts import options as opts from pyecharts.charts import Polar data = [] for i in range(361): t = i / 180 * math.pi r = math.sin(2 * t) * math.cos(2 * t) data.append([r, i]) c = ( Polar() .add_schema(angleaxis_opts=opts.AngleAxisOpts(start_angle=0, min_=0)) .add("flower", data, label_opts=opts.LabelOpts(is_show=False)) .set_global_opts(title_opts=opts.TitleOpts(title="Polar-Flower")) .render("polar_flower.html") )
import random from pyecharts import options as opts from pyecharts.charts import Polar data = [(i, random.randint(1, 100)) for i in range(10)] c = ( Polar() .add( "", data, type_="effectScatter", effect_opts=opts.EffectOpts(scale=10, period=5), label_opts=opts.LabelOpts(is_show=False), ) .set_global_opts(title_opts=opts.TitleOpts(title="Polar-EffectScatter")) .render("polar_effectscatter.html") )
class Radar(
# 初始化配置项,参考 `global_options.InitOpts`
init_opts: opts.InitOpts = opts.InitOpts()
)
def add_schema( # 雷达指示器配置项列表,参考 `RadarIndicatorItem` schema: Sequence[Union[opts.RadarIndicatorItem, dict]], # 雷达图绘制类型,可选 'polygon' 和 'circle' shape: Optional[str] = None, # 雷达的中心(圆心)坐标,数组的第一项是横坐标,第二项是纵坐标。 # 支持设置成百分比,设置成百分比时第一项是相对于容器宽度,第二项是相对于容器高度。 center: Optional[types.Sequence] = None, # 文字样式配置项,参考 `series_options.TextStyleOpts` textstyle_opts: Union[opts.TextStyleOpts, dict] = opts.TextStyleOpts(), # 分割线配置项,参考 `series_options.SplitLineOpts` splitline_opt: Union[opts.SplitLineOpts, dict] = opts.SplitLineOpts(is_show=True), # 分隔区域配置项,参考 `series_options.SplitAreaOpts` splitarea_opt: Union[opts.SplitAreaOpts, dict] = opts.SplitAreaOpts(), # 坐标轴轴线配置项,参考 `global_options.AxisLineOpts` axisline_opt: Union[opts.AxisLineOpts, dict] = opts.AxisLineOpts(), # 极坐标系的径向轴。参考 `basic_charts.RadiusAxisOpts` radiusaxis_opts: types.RadiusAxis = None, # 极坐标系的角度轴。参考 `basic_charts.AngleAxisOpts` angleaxis_opts: types.AngleAxis = None, # 极坐标系配置,参考 `global_options.PolorOpts` polar_opts: types.Polar = None, )
def add( # 系列名称,用于 tooltip 的显示,legend 的图例筛选。 series_name: str, # 系列数据项 data: types.Sequence[types.Union[opts.RadarItem, dict]], # 是否选中图例 is_selected: bool = True, # ECharts 提供的标记类型包括 'circle', 'rect', 'roundRect', 'triangle', # 'diamond', 'pin', 'arrow', 'none' # 可以通过 'image://url' 设置为图片,其中 URL 为图片的链接,或者 dataURI。 symbol: Optional[str] = None, # 系列 label 颜色 color: Optional[str] = None, # 标签配置项,参考 `series_options.LabelOpts` label_opts: opts.LabelOpts = opts.LabelOpts(), # 线样式配置项,参考 `series_options.LineStyleOpts` linestyle_opts: opts.LineStyleOpts = opts.LineStyleOpts(), # 区域填充样式配置项,参考 `series_options.AreaStyleOpts` areastyle_opts: opts.AreaStyleOpts = opts.AreaStyleOpts(), # 提示框组件配置项,参考 `series_options.TooltipOpts` tooltip_opts: Union[opts.TooltipOpts, dict, None] = None, )
class RadarIndicatorItem(
# 指示器名称。
name: Optional[str] = None,
# 指示器的最大值,可选,建议设置
min_: Optional[Numeric] = None,
# 指示器的最小值,可选,默认为 0。
max_: Optional[Numeric] = None,
# 标签特定的颜色。
color: Optional[str] = None,
)
class RadarItem( # 数据项名称 name: Optional[str] = None, # 单个数据项的数值。 value: Optional[Numeric] = None, # 单个数据标记的图形。 symbol: Optional[str] = None, # 单个数据标记的大小 symbol_size: Union[Sequence[Numeric], Numeric] = None, # 单个数据标记的旋转角度(而非弧度)。 symbol_rotate: Optional[Numeric] = None, # 如果 symbol 是 path:// 的形式,是否在缩放时保持该图形的长宽比。 symbol_keep_aspect: bool = False, # 单个数据标记相对于原本位置的偏移。 symbol_offset: Optional[Sequence] = None, # 标签配置项,参考 `series_options.LabelOpts` label_opts: Union[LabelOpts, dict, None] = None, # 图元样式配置项,参考 `series_options.ItemStyleOpts` itemstyle_opts: Union[ItemStyleOpts, dict, None] = None, # 提示框组件配置项,参考 `series_options.TooltipOpts` tooltip_opts: Union[TooltipOpts, dict, None] = None, # 线样式配置项,参考 `series_options.LineStyleOpts` linestyle_opts: Union[LineStyleOpts, dict, None] = None, # 区域填充样式配置项,参考 `series_options.AreaStyleOpts` areastyle_opts: Union[AreaStyleOpts, dict, None] = None, )
import pyecharts.options as opts from pyecharts.charts import Radar """ Gallery 使用 pyecharts 1.1.0 参考地址: https://echarts.apache.org/examples/editor.html?c=radar 目前无法实现的功能: 1、雷达图周围的图例的 textStyle 暂时无法设置背景颜色 """ v1 = [[4300, 10000, 28000, 35000, 50000, 19000]] v2 = [[5000, 14000, 28000, 31000, 42000, 21000]] ( Radar(init_opts=opts.InitOpts(width="1280px", height="720px", bg_color="#CCCCCC")) .add_schema( schema=[ opts.RadarIndicatorItem(name="销售(sales)", max_=6500), opts.RadarIndicatorItem(name="管理(Administration)", max_=16000), opts.RadarIndicatorItem(name="信息技术(Information Technology)", max_=30000), opts.RadarIndicatorItem(name="客服(Customer Support)", max_=38000), opts.RadarIndicatorItem(name="研发(Development)", max_=52000), opts.RadarIndicatorItem(name="市场(Marketing)", max_=25000), ], splitarea_opt=opts.SplitAreaOpts( is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1) ), textstyle_opts=opts.TextStyleOpts(color="#fff"), ) .add( series_name="预算分配(Allocated Budget)", data=v1, linestyle_opts=opts.LineStyleOpts(color="#CD0000"), ) .add( series_name="实际开销(Actual Spending)", data=v2, linestyle_opts=opts.LineStyleOpts(color="#5CACEE"), ) .set_series_opts(label_opts=opts.LabelOpts(is_show=False)) .set_global_opts( title_opts=opts.TitleOpts(title="基础雷达图"), legend_opts=opts.LegendOpts() ) .render("basic_radar_chart.html") )
from pyecharts import options as opts from pyecharts.charts import Radar v1 = [[4300, 10000, 28000, 35000, 50000, 19000]] v2 = [[5000, 14000, 28000, 31000, 42000, 21000]] c = ( Radar() .add_schema( schema=[ opts.RadarIndicatorItem(name="销售", max_=6500), opts.RadarIndicatorItem(name="管理", max_=16000), opts.RadarIndicatorItem(name="信息技术", max_=30000), opts.RadarIndicatorItem(name="客服", max_=38000), opts.RadarIndicatorItem(name="研发", max_=52000), opts.RadarIndicatorItem(name="市场", max_=25000), ] ) .add("预算分配", v1) .add("实际开销", v2) .set_series_opts(label_opts=opts.LabelOpts(is_show=False)) .set_global_opts( legend_opts=opts.LegendOpts(selected_mode="single"), title_opts=opts.TitleOpts(title="Radar-单例模式"), ) .render("radar_selected_mode.html") )
from pyecharts import options as opts from pyecharts.charts import Radar value_bj = [ [55, 9, 56, 0.46, 18, 6, 1], [25, 11, 21, 0.65, 34, 9, 2], [56, 7, 63, 0.3, 14, 5, 3], [33, 7, 29, 0.33, 16, 6, 4], [42, 24, 44, 0.76, 40, 16, 5], [82, 58, 90, 1.77, 68, 33, 6], [74, 49, 77, 1.46, 48, 27, 7], [78, 55, 80, 1.29, 59, 29, 8], [267, 216, 280, 4.8, 108, 64, 9], [185, 127, 216, 2.52, 61, 27, 10], [39, 19, 38, 0.57, 31, 15, 11], [41, 11, 40, 0.43, 21, 7, 12], ] value_sh = [ [91, 45, 125, 0.82, 34, 23, 1], [65, 27, 78, 0.86, 45, 29, 2], [83, 60, 84, 1.09, 73, 27, 3], [109, 81, 121, 1.28, 68, 51, 4], [106, 77, 114, 1.07, 55, 51, 5], [109, 81, 121, 1.28, 68, 51, 6], [106, 77, 114, 1.07, 55, 51, 7], [89, 65, 78, 0.86, 51, 26, 8], [53, 33, 47, 0.64, 50, 17, 9], [80, 55, 80, 1.01, 75, 24, 10], [117, 81, 124, 1.03, 45, 24, 11], [99, 71, 142, 1.1, 62, 42, 12], ] c_schema = [ {"name": "AQI", "max": 300, "min": 5}, {"name": "PM2.5", "max": 250, "min": 20}, {"name": "PM10", "max": 300, "min": 5}, {"name": "CO", "max": 5}, {"name": "NO2", "max": 200}, {"name": "SO2", "max": 100}, ] c = ( Radar() .add_schema(schema=c_schema, shape="circle") .add("北京", value_bj, color="#f9713c") .add("上海", value_sh, color="#b3e4a1") .set_series_opts(label_opts=opts.LabelOpts(is_show=False)) .set_global_opts(title_opts=opts.TitleOpts(title="Radar-空气质量")) .render("radar_air_quality.html") )
from pyecharts import options as opts from pyecharts.charts import Radar data = [{"value": [4, -4, 2, 3, 0, 1], "name": "预算分配"}] c_schema = [ {"name": "销售", "max": 4, "min": -4}, {"name": "管理", "max": 4, "min": -4}, {"name": "技术", "max": 4, "min": -4}, {"name": "客服", "max": 4, "min": -4}, {"name": "研发", "max": 4, "min": -4}, {"name": "市场", "max": 4, "min": -4}, ] c = ( Radar() .set_colors(["#4587E7"]) .add_schema( schema=c_schema, shape="circle", center=["50%", "50%"], radius="80%", angleaxis_opts=opts.AngleAxisOpts( min_=0, max_=360, is_clockwise=False, interval=5, axistick_opts=opts.AxisTickOpts(is_show=False), axislabel_opts=opts.LabelOpts(is_show=False), axisline_opts=opts.AxisLineOpts(is_show=False), splitline_opts=opts.SplitLineOpts(is_show=False), ), radiusaxis_opts=opts.RadiusAxisOpts( min_=-4, max_=4, interval=2, splitarea_opts=opts.SplitAreaOpts( is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1) ), ), polar_opts=opts.PolarOpts(), splitarea_opt=opts.SplitAreaOpts(is_show=False), splitline_opt=opts.SplitLineOpts(is_show=False), ) .add( series_name="预算", data=data, areastyle_opts=opts.AreaStyleOpts(opacity=0.1), linestyle_opts=opts.LineStyleOpts(width=1), ) .render("radar_angle_radius_axis.html") )
class Sankey(
# 初始化配置项,参考 `global_options.InitOpts`
init_opts: opts.InitOpts = opts.InitOpts()
)
class SankeyLevelsOpts(
# 指定设置的是桑基图哪一层,取值从 0 开始。
depth: Numeric = None,
# 桑基图指定层节点的样式。参考 `global_opts.ItemStyleOpts`
itemstyle_opts: Union[ItemStyleOpts, dict, None] = None,
# 桑基图指定层出边的样式。
# 其中 lineStyle.color 支持设置为'source'或者'target'特殊值,此时出边会自动取源节点或目标节点的颜色作为自己的颜色。
# 参考 `global_opts.LineStyleOpts`
linestyle_opts: Union[LineStyleOpts, dict, None] = None,
)
def add( # 系列名称,用于 tooltip 的显示,legend 的图例筛选。 series_name: str, nodes: Sequence, links: Sequence, # 是否选中图例 is_selected: bool = True, # Sankey 组件离容器左侧的距离。 pos_left: types.Union[str, types.Numeric] = "5%", # Sankey 组件离容器上侧的距离。 pos_top: types.Union[str, types.Numeric] = "5%", # Sankey 组件离容器右侧的距离。 pos_right: types.Union[str, types.Numeric] = "20%", # Sankey 组件离容器下侧的距离。 pos_bottom: types.Union[str, types.Numeric] = "5%", # 桑基图中每个矩形节点的宽度。 node_width: Numeric = 20, # 桑基图中每一列任意两个矩形节点之间的间隔。 node_gap: Numeric = 8, # 桑基图中节点的对齐方式,默认是双端对齐,可以设置为左对齐或右对齐,对应的值分别是: # justify: 节点双端对齐。 # left: 节点左对齐。 # right: 节点右对齐。 node_align: str = "justify", # 布局的迭代次数,用来不断优化图中节点的位置,以减少节点和边之间的相互遮盖。 # 默认布局迭代次数:32。 # 注: 布局迭代次数不要低于默认值。 layout_iterations: types.Numeric = 32, # 桑基图中节点的布局方向,可以是水平的从左往右,也可以是垂直的从上往下。 # 对应的参数值分别是 horizontal, vertical。 orient: str = "horizontal", # 控制节点拖拽的交互,默认开启。开启后,用户可以将图中任意节点拖拽到任意位置。若想关闭此交互,只需将值设为 false 就行了。 is_draggable: bool = True, # 鼠标 hover 到节点或边上,相邻接的节点和边高亮的交互,默认关闭,可手动开启。 # false:hover 到节点或边时,只有被 hover 的节点或边高亮。 # true:同 'allEdges'。 # 'allEdges':hover 到节点时,与节点邻接的所有边以及边对应的节点全部高亮。hover 到边时,边和相邻节点高亮。 # 'outEdges':hover 的节点、节点的出边、出边邻接的另一节点 会被高亮。hover 到边时,边和相邻节点高亮。 # 'inEdges':hover 的节点、节点的入边、入边邻接的另一节点 会被高亮。hover 到边时,边和相邻节点高亮。 focus_node_adjacency: types.Union[bool, str] = False, # 桑基图每一层的设置。可以逐层设置 levels: types.SankeyLevel = None, # 标签配置项,参考 `series_options.LabelOpts` label_opts: Union[opts.LabelOpts, dict] = opts.LabelOpts(), # 线条样式配置项,参考 `series_options.LineStyleOpts` linestyle_opt: Union[opts.LineStyleOpts, dict] = opts.LineStyleOpts(), # 提示框组件配置项,参考 `series_options.TooltipOpts` tooltip_opts: Union[opts.TooltipOpts, dict, None] = None, )
from pyecharts import options as opts from pyecharts.charts import Sankey nodes = [ {"name": "category1"}, {"name": "category2"}, {"name": "category3"}, {"name": "category4"}, {"name": "category5"}, {"name": "category6"}, ] links = [ {"source": "category1", "target": "category2", "value": 10}, {"source": "category2", "target": "category3", "value": 15}, {"source": "category3", "target": "category4", "value": 20}, {"source": "category5", "target": "category6", "value": 25}, ] c = ( Sankey() .add( "sankey", nodes, links, linestyle_opt=opts.LineStyleOpts(opacity=0.2, curve=0.5, color="source"), label_opts=opts.LabelOpts(position="right"), ) .set_global_opts(title_opts=opts.TitleOpts(title="Sankey-基本示例")) .render("sankey_base.html") )
import asyncio from aiohttp import TCPConnector, ClientSession import pyecharts.options as opts from pyecharts.charts import Sankey """ Gallery 使用 pyecharts 1.1.0 参考地址: https://echarts.apache.org/examples/editor.html?c=sankey-energy 目前无法实现的功能: 1、label 和图的层次有点问题 """ async def get_json_data(url: str) -> dict: async with ClientSession(connector=TCPConnector(ssl=False)) as session: async with session.get(url=url) as response: return await response.json() # 获取官方的数据 data = asyncio.run( get_json_data(url="https://echarts.apache.org/examples/data/asset/data/energy.json") ) ( Sankey(init_opts=opts.InitOpts(width="1600px", height="800px")) .add( series_name="", nodes=data["nodes"], links=data["links"], itemstyle_opts=opts.ItemStyleOpts(border_width=1, border_color="#aaa"), linestyle_opt=opts.LineStyleOpts(color="source", curve=0.5, opacity=0.5), tooltip_opts=opts.TooltipOpts(trigger_on="mousemove"), ) .set_global_opts(title_opts=opts.TitleOpts(title="Sankey Diagram")) .render("sankey_diagram.html") )
from pyecharts import options as opts from pyecharts.charts import Sankey colors = [ "#67001f", "#b2182b", "#d6604d", "#f4a582", "#fddbc7", "#d1e5f0", "#92c5de", "#4393c3", "#2166ac", "#053061", ] nodes = [ {"name": "a"}, {"name": "b"}, {"name": "a1"}, {"name": "b1"}, {"name": "c"}, {"name": "e"}, ] links = [ {"source": "a", "target": "a1", "value": 5}, {"source": "e", "target": "b", "value": 3}, {"source": "a", "target": "b1", "value": 3}, {"source": "b1", "target": "a1", "value": 1}, {"source": "b1", "target": "c", "value": 2}, {"source": "b", "target": "c", "value": 1}, ] c = ( Sankey() .set_colors(colors) .add( "sankey", nodes=nodes, links=links, pos_bottom="10%", focus_node_adjacency="allEdges", orient="vertical", linestyle_opt=opts.LineStyleOpts(opacity=0.2, curve=0.5, color="source"), label_opts=opts.LabelOpts(position="top"), ) .set_global_opts( title_opts=opts.TitleOpts(title="Sankey-Vertical"), tooltip_opts=opts.TooltipOpts(trigger="item", trigger_on="mousemove"), ) .render("sankey_vertical.html") )
class Sunburst(
# 初始化配置项,参考 `global_options.InitOpts`
init_opts: opts.InitOpts = opts.InitOpts()
)
def add( # 系列名称,用于 tooltip 的显示,legend 的图例筛选。 series_name: str, # 数据项。 data_pair: Sequence, # 旭日图的中心(圆心)坐标,数组的第一项是横坐标,第二项是纵坐标。 # 支持设置成百分比,设置成百分比时第一项是相对于容器宽度,第二项是相对于容器高度。 center: Optional[Sequence] = None, # 旭日图的半径。可以为如下类型: # Sequence.<int|str>:数组的第一项是内半径,第二项是外半径。 radius: Optional[Sequence] = None, # 当鼠标移动到一个扇形块时,可以高亮相关的扇形块。 # 'descendant':高亮该扇形块和后代元素,其他元素将被淡化; # 'ancestor':高亮该扇形块和祖先元素; # 'self':只高亮自身; # 'none':不会淡化其他元素。 highlight_policy: str = "descendant", # 点击节点后的行为。可取值为:false:节点点击无反应。 # 'rootToNode':点击节点后以该节点为根结点。 # 'link':如果节点数据中有 link 点击节点后会进行超链接跳转。 node_click: str = "rootToNode", # 扇形块根据数据 value 的排序方式,如果未指定 value,则其值为子元素 value 之和。 # 'desc':降序排序; # 'asc':升序排序; # 'null':表示不排序,使用原始数据的顺序; # 使用 javascript 回调函数进行排列: sort_: Optional[JSFunc] = "desc", # 旭日图多层级配置 # 目前配置方式可以参考: https://www.echartsjs.com/option.html#series-sunburst.levels levels: Optional[Sequence] = None, # 标签配置项,参考 `series_options.LabelOpts` label_opts: Union[opts.LabelOpts, dict] = opts.LabelOpts(), # 数据项的配置,参考 `series_options.ItemStyleOpts` itemstyle_opts: Union[opts.ItemStyleOpts, dict, None] = None, )
class SunburstItem( # 数据值,如果包含 children,则可以不写 value 值。 # 这时,将使用子元素的 value 之和作为父元素的 value。 # 如果 value 大于子元素之和,可以用来表示还有其他子元素未显示。 value: Optional[Numeric] = None, # 显示在扇形块中的描述文字。 name: Optional[str] = None, # 点击此节点可跳转的超链接。须 Sunburst.add.node_click 值为 'link' 时才生效 link: Optional[str] = None, # 意义同 HTML <a> 标签中的 target,跳转方式的不同 # blank 是在新窗口或者新的标签页中打开 # self 则在当前页面或者当前标签页打开 target: Optional[str] = "blank", # 标签配置项,参考 `series_options.LabelOpts` label_opts: Union[LabelOpts, dict, None] = None, # 数据项配置项,参考 `series_options.ItemStyleOpts` itemstyle_opts: Union[ItemStyleOpts, dict, None] = None, # 子节点数据项配置配置(和 SunburstItem 一致, 递归下去) children: Optional[Sequence] = None, )
from pyecharts.charts import Sunburst from pyecharts import options as opts """ Gallery 使用 pyecharts 1.2.1 参考地址: https://www.echartsjs.com/examples/editor.html?c=sunburst-simple 目前无法实现的功能: 1、暂无 """ data = [ { "name": "Flora", "itemStyle": {"color": "#da0d68"}, "children": [ {"name": "Black Tea", "value": 1, "itemStyle": {"color": "#975e6d"}}, { "name": "Floral", "itemStyle": {"color": "#e0719c"}, "children": [ { "name": "Chamomile", "value": 1, "itemStyle": {"color": "#f99e1c"}, }, {"name": "Rose", "value": 1, "itemStyle": {"color": "#ef5a78"}}, {"name": "Jasmine", "value": 1, "itemStyle": {"color": "#f7f1bd"}}, ], }, ], }, { "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": "Sour/\nFermented", "itemStyle": {"color": "#ebb40f"}, "children": [ { "name": "Sour", "itemStyle": {"color": "#e1c315"}, "children": [ { "name": "Sour Aromatics", "value": 1, "itemStyle": {"color": "#9ea718"}, }, { "name": "Acetic Acid", "value": 1, "itemStyle": {"color": "#94a76f"}, }, { "name": "Butyric Acid", "value": 1, "itemStyle": {"color": "#d0b24f"}, }, { "name": "Isovaleric Acid", "value": 1, "itemStyle": {"color": "#8eb646"}, }, { "name": "Citric Acid", "value": 1, "itemStyle": {"color": "#faef07"}, }, { "name": "Malic Acid", "value": 1, "itemStyle": {"color": "#c1ba07"}, }, ], }, { "name": "Alcohol/\nFremented", "itemStyle": {"color": "#b09733"}, "children": [ {"name": "Winey", "value": 1, "itemStyle": {"color": "#8f1c53"}}, {"name": "Whiskey", "value": 1, "itemStyle": {"color": "#b34039"}}, { "name": "Fremented", "value": 1, "itemStyle": {"color": "#ba9232"}, }, {"name": "Overripe", "value": 1, "itemStyle": {"color": "#8b6439"}}, ], }, ], }, { "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"}}, ], }, { "name": "Other", "itemStyle": {"color": "#0aa3b5"}, "children": [ { "name": "Papery/Musty", "itemStyle": {"color": "#9db2b7"}, "children": [ {"name": "Stale", "value": 1, "itemStyle": {"color": "#8b8c90"}}, { "name": "Cardboard", "value": 1, "itemStyle": {"color": "#beb276"}, }, {"name": "Papery", "value": 1, "itemStyle": {"color": "#fefef4"}}, {"name": "Woody", "value": 1, "itemStyle": {"color": "#744e03"}}, { "name": "Moldy/Damp", "value": 1, "itemStyle": {"color": "#a3a36f"}, }, { "name": "Musty/Dusty", "value": 1, "itemStyle": {"color": "#c9b583"}, }, { "name": "Musty/Earthy", "value": 1, "itemStyle": {"color": "#978847"}, }, {"name": "Animalic", "value": 1, "itemStyle": {"color": "#9d977f"}}, { "name": "Meaty Brothy", "value": 1, "itemStyle": {"color": "#cc7b6a"}, }, {"name": "Phenolic", "value": 1, "itemStyle": {"color": "#db646a"}}, ], }, { "name": "Chemical", "itemStyle": {"color": "#76c0cb"}, "children": [ {"name": "Bitter", "value": 1, "itemStyle": {"color": "#80a89d"}}, {"name": "Salty", "value": 1, "itemStyle": {"color": "#def2fd"}}, { "name": "Medicinal", "value": 1, "itemStyle": {"color": "#7a9bae"}, }, { "name": "Petroleum", "value": 1, "itemStyle": {"color": "#039fb8"}, }, {"name": "Skunky", "value": 1, "itemStyle": {"color": "#5e777b"}}, {"name": "Rubber", "value": 1, "itemStyle": {"color": "#120c0c"}}, ], }, ], }, { "name": "Roasted", "itemStyle": {"color": "#c94930"}, "children": [ {"name": "Pipe Tobacco", "value": 1, "itemStyle": {"color": "#caa465"}}, {"name": "Tobacco", "value": 1, "itemStyle": {"color": "#dfbd7e"}}, { "name": "Burnt", "itemStyle": {"color": "#be8663"}, "children": [ {"name": "Acrid", "value": 1, "itemStyle": {"color": "#b9a449"}}, {"name": "Ashy", "value": 1, "itemStyle": {"color": "#899893"}}, {"name": "Smoky", "value": 1, "itemStyle": {"color": "#a1743b"}}, { "name": "Brown, Roast", "value": 1, "itemStyle": {"color": "#894810"}, }, ], }, { "name": "Cereal", "itemStyle": {"color": "#ddaf61"}, "children": [ {"name": "Grain", "value": 1, "itemStyle": {"color": "#b7906f"}}, {"name": "Malt", "value": 1, "itemStyle": {"color": "#eb9d5f"}}, ], }, ], }, { "name": "Spices", "itemStyle": {"color": "#ad213e"}, "children": [ {"name": "Pungent", "value": 1, "itemStyle": {"color": "#794752"}}, {"name": "Pepper", "value": 1, "itemStyle": {"color": "#cc3d41"}}, { "name": "Brown Spice", "itemStyle": {"color": "#b14d57"}, "children": [ {"name": "Anise", "value": 1, "itemStyle": {"color": "#c78936"}}, {"name": "Nutmeg", "value": 1, "itemStyle": {"color": "#8c292c"}}, {"name": "Cinnamon", "value": 1, "itemStyle": {"color": "#e5762e"}}, {"name": "Clove", "value": 1, "itemStyle": {"color": "#a16c5a"}}, ], }, ], }, { "name": "Nutty/\nCocoa", "itemStyle": {"color": "#a87b64"}, "children": [ { "name": "Nutty", "itemStyle": {"color": "#c78869"}, "children": [ {"name": "Peanuts", "value": 1, "itemStyle": {"color": "#d4ad12"}}, {"name": "Hazelnut", "value": 1, "itemStyle": {"color": "#9d5433"}}, {"name": "Almond", "value": 1, "itemStyle": {"color": "#c89f83"}}, ], }, { "name": "Cocoa", "itemStyle": {"color": "#bb764c"}, "children": [ { "name": "Chocolate", "value": 1, "itemStyle": {"color": "#692a19"}, }, { "name": "Dark Chocolate", "value": 1, "itemStyle": {"color": "#470604"}, }, ], }, ], }, { "name": "Sweet", "itemStyle": {"color": "#e65832"}, "children": [ { "name": "Brown Sugar", "itemStyle": {"color": "#d45a59"}, "children": [ {"name": "Molasses", "value": 1, "itemStyle": {"color": "#310d0f"}}, { "name": "Maple Syrup", "value": 1, "itemStyle": {"color": "#ae341f"}, }, { "name": "Caramelized", "value": 1, "itemStyle": {"color": "#d78823"}, }, {"name": "Honey", "value": 1, "itemStyle": {"color": "#da5c1f"}}, ], }, {"name": "Vanilla", "value": 1, "itemStyle": {"color": "#f89a80"}}, {"name": "Vanillin", "value": 1, "itemStyle": {"color": "#f37674"}}, {"name": "Overall Sweet", "value": 1, "itemStyle": {"color": "#e75b68"}}, {"name": "Sweet Aromatics", "value": 1, "itemStyle": {"color": "#d0545f"}}, ], }, ] 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}")) .render("drink_flavors.html") )
from pyecharts.charts import Sunburst from pyecharts import options as opts """ Gallery 使用 pyecharts 1.1.0 参考地址: https://www.echartsjs.com/examples/editor.html?c=sunburst-simple 目前无法实现的功能: 1、 """ data = [ opts.SunburstItem( name="Grandpa", children=[ opts.SunburstItem( name="Uncle Leo", value=15, children=[ opts.SunburstItem(name="Cousin Jack", value=2), opts.SunburstItem( name="Cousin Mary", value=5, children=[opts.SunburstItem(name="Jackson", value=2)], ), opts.SunburstItem(name="Cousin Ben", value=4), ], ), opts.SunburstItem( name="Father", value=10, children=[ opts.SunburstItem(name="Me", value=5), opts.SunburstItem(name="Brother Peter", value=1), ], ), ], ), opts.SunburstItem( name="Nancy", children=[ opts.SunburstItem( name="Uncle Nike", children=[ opts.SunburstItem(name="Cousin Betty", value=1), opts.SunburstItem(name="Cousin Jenny", value=2), ], ) ], ), ] sunburst = ( Sunburst(init_opts=opts.InitOpts(width="1000px", height="600px")) .add(series_name="", data_pair=data, radius=[0, "90%"]) .set_global_opts(title_opts=opts.TitleOpts(title="Sunburst-基本示例")) .set_series_opts(label_opts=opts.LabelOpts(formatter="{b}")) .render("basic_sunburst.html") )
class ThemeRiver(
# 初始化配置项,参考 `global_options.InitOpts`
init_opts: opts.InitOpts = opts.InitOpts()
)
def add( # 系列名称,用于 tooltip 的显示,legend 的图例筛选。 series_name: Sequence, # 系列数据项 data: types.Sequence[types.Union[opts.ThemeRiverItem, dict]], # 是否选中图例 is_selected: bool = True, # 标签配置项,参考 `series_options.LabelOpts` label_opts: Union[opts.LabelOpts, dict] = opts.LabelOpts(), # 提示框组件配置项,参考 `series_options.TooltipOpts` tooltip_opts: Union[opts.TooltipOpts, dict, None] = None, # 单轴组件配置项,参考 `global_options.SingleAxisOpts` singleaxis_opts: Union[opts.SingleAxisOpts, dict] = opts.SingleAxisOpts(), )
class ThemeRiverItem(
# 时间或主题的时间属性。
date: Optional[str] = None,
# 事件或主题在某个时间点的值。
value: Optional[Numeric] = None,
# 事件或主题的名称。
name: Optional[str] = None,
)
import pyecharts.options as opts from pyecharts.charts import ThemeRiver """ Gallery 使用 pyecharts 1.1.0 参考地址: https://echarts.apache.org/examples/editor.html?c=themeRiver-basic 目前无法实现的功能: 1、暂时无法设置阴影样式 """ x_data = ["DQ", "TY", "SS", "QG", "SY", "DD"] y_data = [ ["2015/11/08", 10, "DQ"], ["2015/11/09", 15, "DQ"], ["2015/11/10", 35, "DQ"], ["2015/11/11", 38, "DQ"], ["2015/11/12", 22, "DQ"], ["2015/11/13", 16, "DQ"], ["2015/11/14", 7, "DQ"], ["2015/11/15", 2, "DQ"], ["2015/11/16", 17, "DQ"], ["2015/11/17", 33, "DQ"], ["2015/11/18", 40, "DQ"], ["2015/11/19", 32, "DQ"], ["2015/11/20", 26, "DQ"], ["2015/11/21", 35, "DQ"], ["2015/11/22", 40, "DQ"], ["2015/11/23", 32, "DQ"], ["2015/11/24", 26, "DQ"], ["2015/11/25", 22, "DQ"], ["2015/11/26", 16, "DQ"], ["2015/11/27", 22, "DQ"], ["2015/11/28", 10, "DQ"], ["2015/11/08", 35, "TY"], ["2015/11/09", 36, "TY"], ["2015/11/10", 37, "TY"], ["2015/11/11", 22, "TY"], ["2015/11/12", 24, "TY"], ["2015/11/13", 26, "TY"], ["2015/11/14", 34, "TY"], ["2015/11/15", 21, "TY"], ["2015/11/16", 18, "TY"], ["2015/11/17", 45, "TY"], ["2015/11/18", 32, "TY"], ["2015/11/19", 35, "TY"], ["2015/11/20", 30, "TY"], ["2015/11/21", 28, "TY"], ["2015/11/22", 27, "TY"], ["2015/11/23", 26, "TY"], ["2015/11/24", 15, "TY"], ["2015/11/25", 30, "TY"], ["2015/11/26", 35, "TY"], ["2015/11/27", 42, "TY"], ["2015/11/28", 42, "TY"], ["2015/11/08", 21, "SS"], ["2015/11/09", 25, "SS"], ["2015/11/10", 27, "SS"], ["2015/11/11", 23, "SS"], ["2015/11/12", 24, "SS"], ["2015/11/13", 21, "SS"], ["2015/11/14", 35, "SS"], ["2015/11/15", 39, "SS"], ["2015/11/16", 40, "SS"], ["2015/11/17", 36, "SS"], ["2015/11/18", 33, "SS"], ["2015/11/19", 43, "SS"], ["2015/11/20", 40, "SS"], ["2015/11/21", 34, "SS"], ["2015/11/22", 28, "SS"], ["2015/11/23", 26, "SS"], ["2015/11/24", 37, "SS"], ["2015/11/25", 41, "SS"], ["2015/11/26", 46, "SS"], ["2015/11/27", 47, "SS"], ["2015/11/28", 41, "SS"], ["2015/11/08", 10, "QG"], ["2015/11/09", 15, "QG"], ["2015/11/10", 35, "QG"], ["2015/11/11", 38, "QG"], ["2015/11/12", 22, "QG"], ["2015/11/13", 16, "QG"], ["2015/11/14", 7, "QG"], ["2015/11/15", 2, "QG"], ["2015/11/16", 17, "QG"], ["2015/11/17", 33, "QG"], ["2015/11/18", 40, "QG"], ["2015/11/19", 32, "QG"], ["2015/11/20", 26, "QG"], ["2015/11/21", 35, "QG"], ["2015/11/22", 40, "QG"], ["2015/11/23", 32, "QG"], ["2015/11/24", 26, "QG"], ["2015/11/25", 22, "QG"], ["2015/11/26", 16, "QG"], ["2015/11/27", 22, "QG"], ["2015/11/28", 10, "QG"], ["2015/11/08", 10, "SY"], ["2015/11/09", 15, "SY"], ["2015/11/10", 35, "SY"], ["2015/11/11", 38, "SY"], ["2015/11/12", 22, "SY"], ["2015/11/13", 16, "SY"], ["2015/11/14", 7, "SY"], ["2015/11/15", 2, "SY"], ["2015/11/16", 17, "SY"], ["2015/11/17", 33, "SY"], ["2015/11/18", 40, "SY"], ["2015/11/19", 32, "SY"], ["2015/11/20", 26, "SY"], ["2015/11/21", 35, "SY"], ["2015/11/22", 4, "SY"], ["2015/11/23", 32, "SY"], ["2015/11/24", 26, "SY"], ["2015/11/25", 22, "SY"], ["2015/11/26", 16, "SY"], ["2015/11/27", 22, "SY"], ["2015/11/28", 10, "SY"], ["2015/11/08", 10, "DD"], ["2015/11/09", 15, "DD"], ["2015/11/10", 35, "DD"], ["2015/11/11", 38, "DD"], ["2015/11/12", 22, "DD"], ["2015/11/13", 16, "DD"], ["2015/11/14", 7, "DD"], ["2015/11/15", 2, "DD"], ["2015/11/16", 17, "DD"], ["2015/11/17", 33, "DD"], ["2015/11/18", 4, "DD"], ["2015/11/19", 32, "DD"], ["2015/11/20", 26, "DD"], ["2015/11/21", 35, "DD"], ["2015/11/22", 40, "DD"], ["2015/11/23", 32, "DD"], ["2015/11/24", 26, "DD"], ["2015/11/25", 22, "DD"], ["2015/11/26", 16, "DD"], ["2015/11/27", 22, "DD"], ["2015/11/28", 10, "DD"], ] ( ThemeRiver(init_opts=opts.InitOpts(width="1600px", height="800px")) .add( series_name=x_data, data=y_data, singleaxis_opts=opts.SingleAxisOpts( pos_top="50", pos_bottom="50", type_="time" ), ) .set_global_opts( tooltip_opts=opts.TooltipOpts(trigger="axis", axis_pointer_type="line") ) .render("theme_river.html") )
class WordCloud(
# 初始化配置项,参考 `global_options.InitOpts`
init_opts: opts.InitOpts = opts.InitOpts()
)
def add( # 系列名称,用于 tooltip 的显示,legend 的图例筛选。 series_name: str, # 系列数据项,[(word1, count1), (word2, count2)] data_pair: Sequence, # 词云图轮廓,有 'circle', 'cardioid', 'diamond', 'triangle-forward', 'triangle', 'pentagon', 'star' 可选 shape: str = "circle", # 自定义的图片(目前支持 jpg, jpeg, png, ico 的格式,其他的图片格式待测试) # 该参数支持: # 1、 base64 (需要补充 data 头); # 2、本地文件路径(相对或者绝对路径都可以) # 注:如果使用了 mask_image 之后第一次渲染会出现空白的情况,再刷新一次就可以了(Echarts 的问题) # Echarts Issue: https://github.com/ecomfe/echarts-wordcloud/issues/74 mask_image: types.Optional[str] = None, # 单词间隔 word_gap: Numeric = 20, # 单词字体大小范围 word_size_range=None, # 旋转单词角度 rotate_step: Numeric = 45, # 距离左侧的距离 pos_left: types.Optional[str] = None, # 距离顶部的距离 pos_top: types.Optional[str] = None, # 距离右侧的距离 pos_right: types.Optional[str] = None, # 距离底部的距离 pos_bottom: types.Optional[str] = None, # 词云图的宽度 width: types.Optional[str] = None, # 词云图的高度 height: types.Optional[str] = None, # 允许词云图的数据展示在画布范围之外 is_draw_out_of_bound: bool = False, # 提示框组件配置项,参考 `series_options.TooltipOpts` tooltip_opts: Union[opts.TooltipOpts, dict, None] = None, # 词云图文字的配置 textstyle_opts: types.TextStyle = None, # 词云图文字阴影的范围 emphasis_shadow_blur: types.Optional[types.Numeric] = None, # 词云图文字阴影的颜色 emphasis_shadow_color: types.Optional[str] = None, )
import pyecharts.options as opts from pyecharts.charts import WordCloud """ Gallery 使用 pyecharts 1.1.0 参考地址: https://gallery.echartsjs.com/editor.html?c=xS1jMxuOVm 目前无法实现的功能: 1、暂无 """ data = [ ("生活资源", "999"), ("供热管理", "888"), ("供气质量", "777"), ("生活用水管理", "688"), ("一次供水问题", "588"), ("交通运输", "516"), ("城市交通", "515"), ("环境保护", "483"), ("房地产管理", "462"), ("城乡建设", "449"), ("社会保障与福利", "429"), ("社会保障", "407"), ("文体与教育管理", "406"), ("公共安全", "406"), ("公交运输管理", "386"), ("出租车运营管理", "385"), ("供热管理", "375"), ("市容环卫", "355"), ("自然资源管理", "355"), ("粉尘污染", "335"), ("噪声污染", "324"), ("土地资源管理", "304"), ("物业服务与管理", "304"), ("医疗卫生", "284"), ("粉煤灰污染", "284"), ("占道", "284"), ("供热发展", "254"), ("农村土地规划管理", "254"), ("生活噪音", "253"), ("供热单位影响", "253"), ("城市供电", "223"), ("房屋质量与安全", "223"), ("大气污染", "223"), ("房屋安全", "223"), ("文化活动", "223"), ("拆迁管理", "223"), ("公共设施", "223"), ("供气质量", "223"), ("供电管理", "223"), ("燃气管理", "152"), ("教育管理", "152"), ("医疗纠纷", "152"), ("执法监督", "152"), ("设备安全", "152"), ("政务建设", "152"), ("县区、开发区", "152"), ("宏观经济", "152"), ("教育管理", "112"), ("社会保障", "112"), ("生活用水管理", "112"), ("物业服务与管理", "112"), ("分类列表", "112"), ("农业生产", "112"), ("二次供水问题", "112"), ("城市公共设施", "92"), ("拆迁政策咨询", "92"), ("物业服务", "92"), ("物业管理", "92"), ("社会保障保险管理", "92"), ("低保管理", "92"), ("文娱市场管理", "72"), ("城市交通秩序管理", "72"), ("执法争议", "72"), ("商业烟尘污染", "72"), ("占道堆放", "71"), ("地上设施", "71"), ("水质", "71"), ("无水", "71"), ("供热单位影响", "71"), ("人行道管理", "71"), ("主网原因", "71"), ("集中供热", "71"), ("客运管理", "71"), ("国有公交(大巴)管理", "71"), ("工业粉尘污染", "71"), ("治安案件", "71"), ("压力容器安全", "71"), ("身份证管理", "71"), ("群众健身", "41"), ("工业排放污染", "41"), ("破坏森林资源", "41"), ("市场收费", "41"), ("生产资金", "41"), ("生产噪声", "41"), ("农村低保", "41"), ("劳动争议", "41"), ("劳动合同争议", "41"), ("劳动报酬与福利", "41"), ("医疗事故", "21"), ("停供", "21"), ("基础教育", "21"), ("职业教育", "21"), ("物业资质管理", "21"), ("拆迁补偿", "21"), ("设施维护", "21"), ("市场外溢", "11"), ("占道经营", "11"), ("树木管理", "11"), ("农村基础设施", "11"), ("无水", "11"), ("供气质量", "11"), ("停气", "11"), ("市政府工作部门(含部门管理机构、直属单位)", "11"), ("燃气管理", "11"), ("市容环卫", "11"), ("新闻传媒", "11"), ("人才招聘", "11"), ("市场环境", "11"), ("行政事业收费", "11"), ("食品安全与卫生", "11"), ("城市交通", "11"), ("房地产开发", "11"), ("房屋配套问题", "11"), ("物业服务", "11"), ("物业管理", "11"), ("占道", "11"), ("园林绿化", "11"), ("户籍管理及身份证", "11"), ("公交运输管理", "11"), ("公路(水路)交通", "11"), ("房屋与图纸不符", "11"), ("有线电视", "11"), ("社会治安", "11"), ("林业资源", "11"), ("其他行政事业收费", "11"), ("经营性收费", "11"), ("食品安全与卫生", "11"), ("体育活动", "11"), ("有线电视安装及调试维护", "11"), ("低保管理", "11"), ("劳动争议", "11"), ("社会福利及事务", "11"), ("一次供水问题", "11"), ] ( WordCloud() .add(series_name="热点分析", data_pair=data, word_size_range=[6, 66]) .set_global_opts( title_opts=opts.TitleOpts( title="热点分析", title_textstyle_opts=opts.TextStyleOpts(font_size=23) ), tooltip_opts=opts.TooltipOpts(is_show=True), ) .render("basic_wordcloud.html") )
from pyecharts import options as opts from pyecharts.charts import WordCloud from pyecharts.globals import SymbolType words = [ ("Sam S Club", 10000), ("Macys", 6181), ("Amy Schumer", 4386), ("Jurassic World", 4055), ("Charter Communications", 2467), ("Chick Fil A", 2244), ("Planet Fitness", 1868), ("Pitch Perfect", 1484), ("Express", 1112), ("Home", 865), ("Johnny Depp", 847), ("Lena Dunham", 582), ("Lewis Hamilton", 555), ("KXAN", 550), ("Mary Ellen Mark", 462), ("Farrah Abraham", 366), ("Rita Ora", 360), ("Serena Williams", 282), ("NCAA baseball tournament", 273), ("Point Break", 265), ] c = ( WordCloud() .add("", words, word_size_range=[20, 100], shape=SymbolType.DIAMOND) .set_global_opts(title_opts=opts.TitleOpts(title="WordCloud-shape-diamond")) .render("wordcloud_diamond.html") )
from pyecharts import options as opts from pyecharts.charts import WordCloud words = [ ("花鸟市场", 1446), ("汽车", 928), ("视频", 906), ("电视", 825), ("Lover Boy 88", 514), ("动漫", 486), ("音乐", 53), ("直播", 163), ("广播电台", 86), ("戏曲曲艺", 17), ("演出票务", 6), ("给陌生的你听", 1), ("资讯", 1437), ("商业财经", 422), ("娱乐八卦", 353), ("军事", 331), ("科技资讯", 313), ("社会时政", 307), ("时尚", 43), ("网络奇闻", 15), ("旅游出行", 438), ("景点类型", 957), ("国内游", 927), ("远途出行方式", 908), ("酒店", 693), ("关注景点", 611), ("旅游网站偏好", 512), ("出国游", 382), ("交通票务", 312), ("旅游方式", 187), ("旅游主题", 163), ("港澳台", 104), ("本地周边游", 3), ("小卖家", 1331), ("全日制学校", 941), ("基础教育科目", 585), ("考试培训", 473), ("语言学习", 358), ("留学", 246), ("K12课程培训", 207), ("艺术培训", 194), ("技能培训", 104), ("IT培训", 87), ("高等教育专业", 63), ("家教", 48), ("体育培训", 23), ("职场培训", 5), ("金融财经", 1328), ("银行", 765), ("股票", 452), ("保险", 415), ("贷款", 253), ("基金", 211), ("信用卡", 180), ("外汇", 138), ("P2P", 116), ("贵金属", 98), ("债券", 93), ("网络理财", 92), ("信托", 90), ("征信", 76), ("期货", 76), ("公积金", 40), ("银行理财", 36), ("银行业务", 30), ("典当", 7), ("海外置业", 1), ("汽车", 1309), ("汽车档次", 965), ("汽车品牌", 900), ("汽车车型", 727), ("购车阶段", 461), ("二手车", 309), ("汽车美容", 260), ("新能源汽车", 173), ("汽车维修", 155), ("租车服务", 136), ("车展", 121), ("违章查询", 76), ("汽车改装", 62), ("汽车用品", 37), ("路况查询", 32), ("汽车保险", 28), ("陪驾代驾", 4), ("网络购物", 1275), ("做我的猫", 1088), ("只想要你知道", 907), ("团购", 837), ("比价", 201), ("海淘", 195), ("移动APP购物", 179), ("支付方式", 119), ("代购", 43), ("体育健身", 1234), ("体育赛事项目", 802), ("运动项目", 405), ("体育类赛事", 337), ("健身项目", 199), ("健身房健身", 78), ("运动健身", 77), ("家庭健身", 36), ("健身器械", 29), ("办公室健身", 3), ("商务服务", 1201), ("法律咨询", 508), ("化工材料", 147), ("广告服务", 125), ("会计审计", 115), ("人员招聘", 101), ("印刷打印", 66), ("知识产权", 32), ("翻译", 22), ("安全安保", 9), ("公关服务", 8), ("商旅服务", 2), ("展会服务", 2), ("特许经营", 1), ("休闲爱好", 1169), ("收藏", 412), ("摄影", 393), ("温泉", 230), ("博彩彩票", 211), ("美术", 207), ("书法", 139), ("DIY手工", 75), ("舞蹈", 23), ("钓鱼", 21), ("棋牌桌游", 17), ("KTV", 6), ("密室", 5), ("采摘", 4), ("电玩", 1), ("真人CS", 1), ("轰趴", 1), ("家电数码", 1111), ("手机", 885), ("电脑", 543), ("大家电", 321), ("家电关注品牌", 253), ("网络设备", 162), ("摄影器材", 149), ("影音设备", 133), ("办公数码设备", 113), ("生活电器", 67), ("厨房电器", 54), ("智能设备", 45), ("个人护理电器", 22), ("服饰鞋包", 1047), ("服装", 566), ("饰品", 289), ("鞋", 184), ("箱包", 168), ("奢侈品", 137), ("母婴亲子", 1041), ("孕婴保健", 505), ("母婴社区", 299), ("早教", 103), ("奶粉辅食", 66), ("童车童床", 41), ("关注品牌", 271), ("宝宝玩乐", 30), ("母婴护理服务", 25), ("纸尿裤湿巾", 16), ("妈妈用品", 15), ("宝宝起名", 12), ("童装童鞋", 9), ("胎教", 8), ("宝宝安全", 1), ("宝宝洗护用品", 1), ("软件应用", 1018), ("系统工具", 896), ("理财购物", 440), ("生活实用", 365), ("影音图像", 256), ("社交通讯", 214), ("手机美化", 39), ("办公学习", 28), ("应用市场", 23), ("母婴育儿", 14), ("游戏", 946), ("手机游戏", 565), ("PC游戏", 353), ("网页游戏", 254), ("游戏机", 188), ("模拟辅助", 166), ("个护美容", 942), ("护肤品", 177), ("彩妆", 133), ("美发", 80), ("香水", 50), ("个人护理", 46), ("美甲", 26), ("SPA美体", 21), ("花鸟萌宠", 914), ("绿植花卉", 311), ("狗", 257), ("其他宠物", 131), ("水族", 125), ("猫", 122), ("动物", 81), ("鸟", 67), ("宠物用品", 41), ("宠物服务", 26), ("书籍阅读", 913), ("网络小说", 483), ("关注书籍", 128), ("文学", 105), ("报刊杂志", 77), ("人文社科", 22), ("建材家居", 907), ("装修建材", 644), ("家具", 273), ("家居风格", 187), ("家居家装关注品牌", 140), ("家纺", 107), ("厨具", 47), ("灯具", 43), ("家居饰品", 29), ("家居日常用品", 10), ("生活服务", 883), ("物流配送", 536), ("家政服务", 108), ("摄影服务", 49), ("搬家服务", 38), ("物业维修", 37), ("婚庆服务", 24), ("二手回收", 24), ("鲜花配送", 3), ("维修服务", 3), ("殡葬服务", 1), ("求职创业", 874), ("创业", 363), ("目标职位", 162), ("目标行业", 50), ("兼职", 21), ("期望年薪", 20), ("实习", 16), ("雇主类型", 10), ("星座运势", 789), ("星座", 316), ("算命", 303), ("解梦", 196), ("风水", 93), ("面相分析", 47), ("手相", 32), ("公益", 90), ] c = ( WordCloud() .add( "", words, word_size_range=[20, 100], textstyle_opts=opts.TextStyleOpts(font_family="cursive"), ) .set_global_opts(title_opts=opts.TitleOpts(title="WordCloud-自定义文字样式")) .render("wordcloud_custom_font_style.html") )
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。