pyecharts 画廊网站 : https://gallery.pyecharts.org/#/
pyecharts 模块 有很多 配置选项 , 常用的配置项有如下几种 :
Pyecharts 提供了一些全局配置和系列配置选项 , 用于控制图表的外观和行为 ;
下图是一个 pyecharts 图表的常见全局配置 :
常见的 Pyecharts 模块全局配置选项:
InitOpts(初始化配置项)
TitleOpts(标题配置项)
TooltipOpts(提示框配置项)
AxisOpts(坐标轴配置项)
VisualMapOpts(视觉映射配置设置)
在 set_global_opts 函数中 , 点击 Ctrl + P 可以看到可配置的全局配置项 ;
在具体的配置项中 , 在配置项构造函数中 , 点击 Ctrl + P 可以查看具体可以配置哪些属性 ;
pyecharts 模块全局配置项文档 : https://pyecharts.org/#/zh-cn/global_options
在上述页面中 , 可以找到全局配置项文档 ;
代码示例 :
"""
pyecharts 模块
"""
# 导入 pyecharts 模块中的 折线图 Line 对象
from pyecharts.charts import Line
# 全局配置中的标题配置, 图例配置, 工具箱配置, 视觉映射配置
from pyecharts.options import TitleOpts, LegendOpts, ToolboxOpts, VisualMapOpts
# 创建 折线图 对象
line = Line()
# 设置 x 轴数据
line.add_xaxis(["西城", "东城", "海淀", "朝阳", "昌平"])
# 设置 y 轴数据
line.add_yaxis("清北录取人数", [105, 28, 215, 16, 1])
# 设置全局配置项
# 配置标题
# 调用 set_global_opts 方法, 传入的参数使用关键字传参
line.set_global_opts(
# pos_left="center" 表示标题水平方向居中对齐
# pos_bottom="1%" 表示距离底部 1%
title_opts=TitleOpts(title="清北录取人数", pos_left="center", pos_bottom="1%"),
# 图例配置
legend_opts=LegendOpts(is_show=True),
# 工具箱配置
toolbox_opts=ToolboxOpts(is_show=True),
# 视觉映射配置
visualmap_opts=VisualMapOpts(is_show=True)
)
# 生成图表
line.render()
运行结果 : 运行上述代码 , 生成 render.html 网页 ;
render.html 网页内容 :
DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Awesome-pyechartstitle>
<script type="text/javascript" src="https://assets.pyecharts.org/assets/v5/echarts.min.js">script>
head>
<body >
<div id="b74fc495f77544f5a15f5a3814366245" class="chart-container" style="width:900px; height:500px; ">div>
<script>
var chart_b74fc495f77544f5a15f5a3814366245 = echarts.init(
document.getElementById('b74fc495f77544f5a15f5a3814366245'), 'white', {renderer: 'canvas'});
var option_b74fc495f77544f5a15f5a3814366245 = {
"animation": true,
"animationThreshold": 2000,
"animationDuration": 1000,
"animationEasing": "cubicOut",
"animationDelay": 0,
"animationDurationUpdate": 300,
"animationEasingUpdate": "cubicOut",
"animationDelayUpdate": 0,
"aria": {
"enabled": false
},
"color": [
"#5470c6",
"#91cc75",
"#fac858",
"#ee6666",
"#73c0de",
"#3ba272",
"#fc8452",
"#9a60b4",
"#ea7ccc"
],
"series": [
{
"type": "line",
"name": "\u6e05\u5317\u5f55\u53d6\u4eba\u6570",
"connectNulls": false,
"xAxisIndex": 0,
"symbolSize": 4,
"showSymbol": true,
"smooth": false,
"clip": true,
"step": false,
"data": [
[
"\u897f\u57ce",
105
],
[
"\u4e1c\u57ce",
28
],
[
"\u6d77\u6dc0",
215
],
[
"\u671d\u9633",
16
],
[
"\u660c\u5e73",
1
]
],
"hoverAnimation": true,
"label": {
"show": true,
"margin": 8
},
"logBase": 10,
"seriesLayoutBy": "column",
"lineStyle": {
"show": true,
"width": 1,
"opacity": 1,
"curveness": 0,
"type": "solid"
},
"areaStyle": {
"opacity": 0
},
"zlevel": 0,
"z": 0
}
],
"legend": [
{
"data": [
"\u6e05\u5317\u5f55\u53d6\u4eba\u6570"
],
"selected": {},
"show": true,
"padding": 5,
"itemGap": 10,
"itemWidth": 25,
"itemHeight": 14,
"backgroundColor": "transparent",
"borderColor": "#ccc",
"borderWidth": 1,
"borderRadius": 0,
"pageButtonItemGap": 5,
"pageButtonPosition": "end",
"pageFormatter": "{current}/{total}",
"pageIconColor": "#2f4554",
"pageIconInactiveColor": "#aaa",
"pageIconSize": 15,
"animationDurationUpdate": 800,
"selector": false,
"selectorPosition": "auto",
"selectorItemGap": 7,
"selectorButtonGap": 10
}
],
"tooltip": {
"show": true,
"trigger": "item",
"triggerOn": "mousemove|click",
"axisPointer": {
"type": "line"
},
"showContent": true,
"alwaysShowContent": false,
"showDelay": 0,
"hideDelay": 100,
"enterable": false,
"confine": false,
"appendToBody": false,
"transitionDuration": 0.4,
"textStyle": {
"fontSize": 14
},
"borderWidth": 0,
"padding": 5,
"order": "seriesAsc"
},
"xAxis": [
{
"show": true,
"scale": false,
"nameLocation": "end",
"nameGap": 15,
"gridIndex": 0,
"inverse": false,
"offset": 0,
"splitNumber": 5,
"minInterval": 0,
"splitLine": {
"show": true,
"lineStyle": {
"show": true,
"width": 1,
"opacity": 1,
"curveness": 0,
"type": "solid"
}
},
"data": [
"\u897f\u57ce",
"\u4e1c\u57ce",
"\u6d77\u6dc0",
"\u671d\u9633",
"\u660c\u5e73"
]
}
],
"yAxis": [
{
"show": true,
"scale": false,
"nameLocation": "end",
"nameGap": 15,
"gridIndex": 0,
"inverse": false,
"offset": 0,
"splitNumber": 5,
"minInterval": 0,
"splitLine": {
"show": true,
"lineStyle": {
"show": true,
"width": 1,
"opacity": 1,
"curveness": 0,
"type": "solid"
}
}
}
],
"title": [
{
"show": true,
"text": "\u6e05\u5317\u5f55\u53d6\u4eba\u6570",
"target": "blank",
"subtarget": "blank",
"left": "center",
"bottom": "1%",
"padding": 5,
"itemGap": 10,
"textAlign": "auto",
"textVerticalAlign": "auto",
"triggerEvent": false
}
],
"toolbox": {
"show": true,
"orient": "horizontal",
"itemSize": 15,
"itemGap": 10,
"left": "80%",
"feature": {
"saveAsImage": {
"type": "png",
"backgroundColor": "auto",
"connectedBackgroundColor": "#fff",
"show": true,
"title": "\u4fdd\u5b58\u4e3a\u56fe\u7247",
"pixelRatio": 1
},
"restore": {
"show": true,
"title": "\u8fd8\u539f"
},
"dataView": {
"show": true,
"title": "\u6570\u636e\u89c6\u56fe",
"readOnly": false,
"lang": [
"\u6570\u636e\u89c6\u56fe",
"\u5173\u95ed",
"\u5237\u65b0"
],
"backgroundColor": "#fff",
"textareaColor": "#fff",
"textareaBorderColor": "#333",
"textColor": "#000",
"buttonColor": "#c23531",
"buttonTextColor": "#fff"
},
"dataZoom": {
"show": true,
"title": {
"zoom": "\u533a\u57df\u7f29\u653e",
"back": "\u533a\u57df\u7f29\u653e\u8fd8\u539f"
},
"icon": {},
"filterMode": "filter"
},
"magicType": {
"show": true,
"type": [
"line",
"bar",
"stack",
"tiled"
],
"title": {
"line": "\u5207\u6362\u4e3a\u6298\u7ebf\u56fe",
"bar": "\u5207\u6362\u4e3a\u67f1\u72b6\u56fe",
"stack": "\u5207\u6362\u4e3a\u5806\u53e0",
"tiled": "\u5207\u6362\u4e3a\u5e73\u94fa"
},
"icon": {}
}
}
},
"visualMap": {
"show": true,
"type": "continuous",
"min": 0,
"max": 100,
"inRange": {
"color": [
"#50a3ba",
"#eac763",
"#d94e5d"
]
},
"calculable": true,
"inverse": false,
"splitNumber": 5,
"hoverLink": true,
"orient": "vertical",
"padding": 5,
"showLabel": true,
"itemWidth": 20,
"itemHeight": 140,
"borderWidth": 0
}
};
chart_b74fc495f77544f5a15f5a3814366245.setOption(option_b74fc495f77544f5a15f5a3814366245);
script>
body>
html>
使用 Chrome 浏览器打开网页 , 效果如下 :