pyecharts 标准线_pyecharts
整理自官网from pyecharts.globals import CurrentConfig, OnlineHostType
CurrentConfig.ONLINE_HOST = OnlineHostType.NOTEBOOK_HOST
散点图-多图from pyecharts.charts import Scatter,EffectScatter
import numpy as np
y = np.random.randint(1,30,50).tolist() s = EffectScatter()
s.add_xaxis(xaxis_data=range(50))
s.add_yaxis('A', y_axis=y, symbol='pin',symbol_size=16,label_opts=opts.LabelOpts(is_show=False))
s.set_global_opts(
title_opts=opts.TitleOpts(title='散点图-涟漪特效散点'),
xaxis_opts=opts.AxisOpts(name='秒'),
yaxis_opts=opts.AxisOpts(name='流量'),
legend_opts=opts.LegendOpts(pos_right=50),
# series_index指定映射的系列索引
visualmap_opts=[
opts.VisualMapOpts(type_='color', min_=0,max_=50,series_index=0, pos_top='20px'),
opts.VisualMapOpts(type_='size', min_=0,max_=50,series_index=1, pos_top='60%')
]
)
s2 = Scatter()
s2.add_xaxis(xaxis_data=range(50))
s2.add_yaxis('B', y_axis=y,
xaxis_index=1, yaxis_index=1,
label_opts=opts.LabelOpts(is_show=False))
s2.set_global_opts(
xaxis_opts=opts.AxisOpts(name='秒', grid_index=1),
yaxis_opts=opts.AxisOpts(name='流量'),
legend_opts=opts.LegendOpts(pos_right=10),
)
g = Grid(init_opts=opts.InitOpts(height='450px', width='850px'))
g.add(s,grid_opts=opts.GridOpts(height="35%")) # 高度变为35%
g.add(s2,grid_opts=opts.GridOpts(pos_top='60%',height="35%")) # 距离容器顶部的距离
g.render_notebook()
平行坐标系from pyecharts.charts import Parallel
平行坐标系-基本设置r = np.random.rand(12)
data = [[i, round(j,2), round(m,2), n] for i,j,m,n in zip(range(12),r,np.random.randint(1,3,12)+r, np.random.choice(['A','B'],12))]
data[:3]
[[0, 0.04, 1.04, ‘A’], [1, 0.9, 1.9, ‘A’], [2, 0.11, 2.11, ‘B’]]# 坐标轴设置,类别轴设置data所有的类别
schema = [
{'dim':0,'name':'月份'},{'dim':1,'name':'指标1'},
{'dim':2,'name':'指标2'},{'dim':3,'name':'类别','type':'category', 'data':['A','B']},
]
p =Parallel(init_opts=opts.InitOpts(height='350px', width='850px'))
p.add_schema(schema=schema)
p.add('2015', data, linestyle_opts=opts.LineStyleOpts(color='#CD0000')) # 没有color参数
r = np.random.rand(12)
data = [[i, round(j,2), round(m,2), n] for i,j,m,n in zip(range(12),r,np.random.randint(1,3,12)+r, np.random.choice(['A','B'],12))]
p.add('2016', data, linestyle_opts=opts.LineStyleOpts(color='#5CACEE'))
p.render_notebook()
平行坐标系-单独设置每个轴p =Parallel(init_opts=opts.InitOpts(height='350px', width='850px'))
# 单独设置每个轴,刻度范围
p.add_schema(
schema=[
opts.ParallelAxisOpts(dim=0, name='月份'),
opts.ParallelAxisOpts(dim=1, name='指标1',min_=0,max_=1),
opts.ParallelAxisOpts(dim=2, name='指标2',min_=1,max_=3),
opts.ParallelAxisOpts(dim=3, name='类别',type_='category', data=['A','B']),
]
)
p.add('2015', data, is_smooth=True)
r = np.random.rand(12)
data = [[i, round(j,2), round(m,2), n] for i,j,m,n in zip(range(12),r,np.random.randint(1,3,12)+r, np.random.choice(['A','B'],12))]
p.add('2016', data, is_smooth=True)
p.render_notebook()
桑基图from pyecharts.charts import Sankey
from pyecharts import options as opts
import numpy as np
nodes1 = [{'name':'a%s'%i} for i in range(3)]
nodes2 = [{'name':'b%s'%i} for i in range(3)]
nodes3 = [{'name':'c%s'%i} for i in range(3)]
nodes = nodes1+nodes2+nodes3
nodes
[{‘name’: ‘a0’},
{‘name’: ‘a1’},
{‘name’: ‘a2’},
{‘name’: ‘b0’},
{‘name’: ‘b1’},
{‘name’: ‘b2’},
{‘name’: ‘c0’},
{‘name’: ‘c1’},
{‘name’: ‘c2’}]links1 = [{'source':i['name'],'target':j['name'],'value':int(np.random.randint(1,10))} for i in nodes1 for j in nodes2]
links2 = [{'source':i['name'],'target':j['name'],'value':int(np.random.randint(1,10))} for i in nodes2 for j in nodes3]
links = links1+links2
links[:5]
[{‘source’: ‘a0’, ‘target’: ‘b0’, ‘value’: 8},
{‘source’: ‘a0’, ‘target’: ‘b1’, ‘value’: 9},
{‘source’: ‘a0’, ‘target’: ‘b2’, ‘value’: 3},
{‘source’: ‘a1’, ‘target’: ‘b0’, ‘value’: 2},
{‘source’: ‘a1’, ‘target’: ‘b1’, ‘value’: 6}]s = Sankey(init_opts=opts.InitOpts(height='350px', width='650px'))
s.add(
"sankey", nodes=nodes, links=links,
linestyle_opt=opts.LineStyleOpts(opacity=0.2, curve=0.5, color="source"),
label_opts=opts.LabelOpts(position="right"),
# 选择方向,默认
orient='horizontal',
# 设置每一层的颜色,线型
levels=[opts.SankeyLevelsOpts(
depth=0,
itemstyle_opts=opts.ItemStyleOpts(color='#006699'),
linestyle_opts=opts.LineStyleOpts(color="source", opacity=0.6),
),opts.SankeyLevelsOpts(
depth=1,
itemstyle_opts=opts.ItemStyleOpts(color='#009966'),
linestyle_opts=opts.LineStyleOpts(color="source", opacity=0.6),
),
opts.SankeyLevelsOpts(
depth=2,
itemstyle_opts=opts.ItemStyleOpts(color='#FF9933'),
linestyle_opts=opts.LineStyleOpts(color="source", opacity=0.6),
),
],
)
s .set_global_opts(title_opts=opts.TitleOpts(title="Sankey-基本示例"))
s.render_notebook()
关系图from pyecharts.charts import Graph
cate = [{'name':i} for i in ['A','B','C']]
values=np.random.randint(10,20,20).tolist()
nodes_data = [
{"name": "结点%s"%i, "symbolSize":value*2,'value': value,'category':np.random.randint(0,3)}
for i,value in zip(range(1,21),values)
]
links_data = [
{"source": i.get("name"), "target": j.get("name"), 'value':np.random.randint(1,10)}
for i in nodes_data[0:20:2] for j in nodes_data[1:20:2]
]
# 也可以这样设置:
# nodes_data = [
# opts.GraphNode(name="结点1", symbol_size=10,value=20), # 节点项:节点名称,节点大小,节点的值
# opts.GraphNode(name="结点2", symbol_size=20,value=15),
# ]
# links_data = [
# opts.GraphLink(source="结点1", target="结点2", value=2), # 关系项:主节点,对应的节点,值
# opts.GraphLink(source="结点1", target="结点4", value=20),
# opts.GraphLink(source="结点2", target="结点3", value=3),
# ] nodes_data[:5]
[{‘category’: 1, ‘name’: ‘结点1’, ‘symbolSize’: 34, ‘value’: 17},
{‘category’: 2, ‘name’: ‘结点2’, ‘symbolSize’: 38, ‘value’: 19},
{‘category’: 2, ‘name’: ‘结点3’, ‘symbolSize’: 30, ‘value’: 15},
{‘category’: 2, ‘name’: ‘结点4’, ‘symbolSize’: 28, ‘value’: 14},
{‘category’: 2, ‘name’: ‘结点5’, ‘symbolSize’: 28, ‘value’: 14}]links_data[:5]
[{‘source’: ‘结点1’, ‘target’: ‘结点2’, ‘value’: 7},
{‘source’: ‘结点1’, ‘target’: ‘结点4’, ‘value’: 2},
{‘source’: ‘结点1’, ‘target’: ‘结点6’, ‘value’: 8},
{‘source’: ‘结点1’, ‘target’: ‘结点8’, ‘value’: 7},
{‘source’: ‘结点1’, ‘target’: ‘结点10’, ‘value’: 8}]g = Graph(init_opts=opts.InitOpts(height='450px', width='650px'))
g.add(series_name="", # 项目名称
nodes=nodes_data, # 节点数据
links=links_data, # 节点关系数据
categories=cate,
is_rotate_label=True, # 标签旋转
repulsion=4000, # 斥力值,值越大斥力越大,节点之间越远(最后的图也就越大)
# gravity=0.8,# 引力因子,和上面相反
layout='circular', # 图的布局。可选:'none' 不采用任何布局,使用节点中提供的 x, y 作为节点的位置。 'circular' 环形布局。'force' 力引导布局。
# layout:采用关系力引导布局方式,节点之间的值越大,节点之间也就越近
edge_length=[1,50], # 线的长度,值范围越大,关系亲疏越明显(近的更近)
edge_label=opts.LabelOpts(is_show=False, position="middle"), # 节点之间的边(线)的标签设置
itemstyle_opts=opts.ItemStyleOpts(border_color='black', opacity='0.9'), # 节点样式
# label_opts=opts.LabelOpts(is_show=True, position='outside', color='black') # 节点上的标签的设置
)
g.set_global_opts(title_opts=opts.TitleOpts(title="关系图示例"),
legend_opts=opts.LegendOpts(pos_right='40px')
# visualmap_opts=opts.VisualMapOpts(max_=20) # 颜色映射根据节点的值,即nodes中的value
)
g.render_notebook()
主题旭日图from pyecharts.charts import Sunburst
colors = ["#CD0000",'#009966','#FF9900'] #第1层颜色:
colors2 = [['#FF6699','#FF9999','#CC3366'],['#00CC33','#66CC00','#339900'],['#FFCC66','#FF9933']]# 第2层颜色
names = [['c1','c2','c3'],['c4','c5','c6'],['c7','c8']] # 第二层节点名称
values = [[10,15,29],[34,17,26],[20,16]] # 二层节点数值,一层节点可以没有数值,此时为和
level2 = [
[{'name':name[i], 'itemStyle':{'color':color[j]},'value':value[n]}
for i,j,n in zip(range(len(name)),range(len(color)),range(len(value)))]
for name,color,value in zip(names, colors2,values)
]
data = [{'name':i, 'itemStyle':{'color':j}, 'children': m} for i,j,m in zip(['Fruits','Vegetables','Others'],colors,level2)]
data
[{‘children’: [{‘itemStyle’: {‘color’: ‘#FF6699’}, ‘name’: ‘c1’, ‘value’: 10},
{‘itemStyle’: {‘color’: ‘#FF9999’}, ‘name’: ‘c2’, ‘value’: 15},
{‘itemStyle’: {‘color’: ‘#CC3366’}, ‘name’: ‘c3’, ‘value’: 29}],
‘itemStyle’: {‘color’: ‘#CD0000’},
‘name’: ‘Fruits’},
{‘children’: [{‘itemStyle’: {‘color’: ‘#00CC33’}, ‘name’: ‘c4’, ‘value’: 34},
{‘itemStyle’: {‘color’: ‘#66CC00’}, ‘name’: ‘c5’, ‘value’: 17},
{‘itemStyle’: {‘color’: ‘#339900’}, ‘name’: ‘c6’, ‘value’: 26}],
‘itemStyle’: {‘color’: ‘#009966’},
‘name’: ‘Vegetables’},
{‘children’: [{‘itemStyle’: {‘color’: ‘#FFCC66’}, ‘name’: ‘c7’, ‘value’: 20},
{‘itemStyle’: {‘color’: ‘#FF9933’}, ‘name’: ‘c8’, ‘value’: 16}],
‘itemStyle’: {‘color’: ‘#FF9900’},
‘name’: ‘Others’}]sun = Sunburst(init_opts=opts.InitOpts(width="850px", height="350px"))
sun.add('',data_pair=data,
radius=['20%','90%'],
highlight_policy='descendant', # 指向后高亮其子节点
sort_='desc', # 排序方式
# 层级配置:可选
levels=[
{}, # 里面的空白
{'label':{'rotate':'tangential'}}, # 第一层:标签旋转
{'label':{'position':'outside','padding':3},
"itemStyle": {"borderWidth": 3}
} # 第二层
]
)
sun.set_global_opts(title_opts=opts.TitleOpts(title="Sunburst"))
sun.render_notebook()
矩形树图from pyecharts.charts import TreeMap
values = [[10,15,29],[34,17,26],[20,16]] # 二层节点数值
names = [['c1','c2','c3'],['c4','c5','c6'],['c7','c8']] # 第二层节点名称
childs = [
[{'name':name[i], 'value':value[j]} for i,j in zip(range(len(name)),range(len(value)))]
for name,value in zip(names, values)
]
data = [{'name':i, 'value':j, 'children': m} for i,j,m in zip(['Fruits','Vegetables','Others'],[54,77,36],childs)]
data
# [{'value':10,'name':'节点1',
# 'children':[{'value':3,'name':'节点1.子节点1'},
# {'value':7,'name':'节点1.子节点2'}
# ]
# },
# { },
# ]
[{‘children’: [{‘name’: ‘c1’, ‘value’: 10},
{‘name’: ‘c2’, ‘value’: 15},
{‘name’: ‘c3’, ‘value’: 29}],
‘name’: ‘Fruits’,
‘value’: 54},
{‘children’: [{‘name’: ‘c4’, ‘value’: 34},
{‘name’: ‘c5’, ‘value’: 17},
{‘name’: ‘c6’, ‘value’: 26}],
‘name’: ‘Vegetables’,
‘value’: 77},
{‘children’: [{‘name’: ‘c7’, ‘value’: 20}, {‘name’: ‘c8’, ‘value’: 16}],
‘name’: ‘Others’,
‘value’: 36}]treemap = TreeMap(init_opts=opts.InitOpts(height='450px',width='850px'))
treemap.add(series_name='示例',data=data,leaf_depth=2,
# 设置每一层的
# levels=[
# opts.TreeMapLevelsOpts(color_mapping_by='value'),
# opts.TreeMapLevelsOpts(color_mapping_by='value'),
# ]
)
treemap.set_global_opts(title_opts=opts.TitleOpts(title='矩形树图'))
treemap.render_notebook()
pyecharts 标准线_pyecharts相关推荐
- python pyecharts用法_pyecharts的简单使用
由于需要在项目中展示数据,查了查资料发现,pyecharts模块在网页数据展示方面有很大优势,所以就学了点pyechas 参考博客:Python:数据可视化pyecharts的使用 - JYRoy - ...
- python中pyecharts安装_Pyecharts安装及使用
前言 本文旨在记录pyecharts的安装过程以及安装过程中遇到的bug,当然最主要的原因是要习惯写博客啦:): 关于Pyecharts Echarts是百度开源的一个数据可视化JS库,可视化效果很棒 ...
- pyecharts 大小_pyecharts 常用API 图形初始化
导入 import pyecharts from pyecharts.engine import create_default_environment 图表初始化参数 -- 通用 # TODO 图表初 ...
- pyecharts 标准线_数据可视化之pyecharts
ECharts ECharts是什么?下面是来自官方的介绍: ECharts,缩写来自Enterprise Charts,商业级数据图表,一个纯Javascript的图表库,可以流畅的运行在PC和移动 ...
- pyecharts 间距_pyecharts详细手册(一)
不要去追一匹马 用追马的时间 去种花 待到来年春暖花开之时 会有一批骏马奔赴于此 最近我在对pyecharts深造时,我竟然没有在广大的互联网上找到一个适合小白学习的手册,于是我觉得我要去做一个大事, ...
- python中pyecharts安装_Pyecharts安装使用和绘图案例
一次偶然的机会,接触了pyecharts,发现做图交互效果非常棒,便深究.摸索.入坑.这篇文章主要讲述自己在安装和使用中遇到的问题,解决方法,最后还会有pyecharts中自己比较喜欢的绘图功能. p ...
- pyecharts怎么绘制散点图_PyeCharts绘制各种图形
简介 PyeCharts 是一个用于生成 Echarts 图表的类库, 用其生成的图可视化效果非常棒,而且使用起来非常简单. 下面是一些常用图的pyecharts实现方法 柱状图 bar = pye. ...
- pyecharts怎么绘制散点图_pyecharts可视化和wx的结合
前言 最近在研究 pyecharts 的用法,它是 python 的一个可视化工具,然后就想着结合微信来一起玩 不多说,直接看效果: 条形图.gif 环境配置 pip install pyechart ...
- pyecharts查看版本_pyecharts v1 版本 学习笔记 折线图,面积图
折线图 折线图 基本demo import pyecharts.options as opts from pyecharts.charts import Line c = ( Line() .add_ ...
最新文章
- 机器学习算法专题(附组队学习)
- LeetCode 176. Second Highest Salary--Database--数据库题目
- 网站优化的“内忧外患”需兼顾
- 数据库常用面试题(SQL Server) (转载)
- es6 ...展开运算符
- Java OAuth开发包资料
- 成功跳槽百度工资从15K涨到28K,威力加强版
- Bitmap尺度变换
- hdu 1087 Super Jumping! Jumping! Jumping! 解题报告
- python查看数据库存在表_python sqlite3查看数据库所有表(table)
- vs中的opt文件包含了整个宇宙
- 电脑一直显示服务器不兼容,原神PC版提示版本不兼容怎么办 PC版常见问题介绍...
- 2021教资高中信息技术笔记知识点48页pdf
- 计算机模拟仿真技术的功能,浅谈虚拟仿真技术
- Python面向对象加强2.Python 中类的内置属性和内置方法(魔法函数)
- 深入浅出理解输入输出阻抗-音频电路输入输出阻抗
- MD5的使用(计算指定目录下文件的md5值)
- 基于Esp8266的远程开机棒设计和实现
- <script>alert(1)</script>怎么在页面显示且不出现功能
- java 1f8b0800,常用ASCII/ISO-8859-1/GB2312/GBK/UTF-8等字符编码梳理