Pycharts学习笔记

 这篇文章作为我的Pycharts学习笔记

参考网页http://pyecharts.org/#/zh-cn/prepare

 堆叠柱状图

from pyecharts import Bar

CLOTHES = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
clothes_v1 = [5, 20, 36, 10, 75, 90]
clothes_v2 = [10, 25, 8, 60, 20, 80]

(Bar("柱状图数据堆叠事例")
    .add("商家A",CLOTHES,clothes_v1,is_stack=True)
    .add("商家B",CLOTHES,clothes_v1,is_stack=True)
    .render(r"D:\chart2.html"))

 Json值传递

from __future__ import unicode_literals

import networkx as nx
from networkx.readwrite import json_graph
from pyecharts import Graph

g=nx.Graph()
categories=['网关','节点']
g.add_node('FF12C904', name='Gateway 1', symbolSize=40, category=0)
g.add_node('FF12CA02', name='Node 11', category=1)
g.add_node('FF12C326', name='Node 12', category=1)
g.add_node('FF45C023', name='Node 111', category=1)
g.add_node('FF230933', name='Node 1111', category=1)


g.add_edge('FF12C904', 'FF12CA02')
g.add_edge('FF12C904', 'FF12C326')
g.add_edge('FF12CA02', 'FF45C023')
g.add_edge('FF45C023', 'FF230933')


g_data=json_graph.node_link_data(g)
eg=Graph('设备最新拓扑图')
eg.add('Devices',nodes=g_data['nodes'],links=g_data['links'],categories=categories)
eg.show_config()
eg.render(r"D:\my_first_chart.html")

 损益表

import pandas as pd
import numpy as np
from pyecharts import Bar

title='bar chart'
index=pd.date_range('3/8/2018',periods=6,freq='M')
df1=pd.DataFrame(np.random.randn(6),index=index)
df2=pd.DataFrame(np.random.randn(6),index=index)

dtvalue1=[i[0] for i in df1.values]
dtvalue2=[i[0] for i in df2.values]
_index=[i for i in df1.index.format()]

bar=Bar(title,'Profit and loss situation')
bar.add('profit',_index,dtvalue1)
bar.add('loss',_index,dtvalue2)
bar.render(r"D:\chart3.html") 

 折线与柱状图

from pyecharts import Bar, Line
from pyecharts.engine import create_default_environment

bar=Bar("My Paragraph","Jennifer")
bar.add("clothes",["one","two","three","four","five","six"],[5,20,36,10,75,90])

line=Line("My Paragraph","Jennifer")
line.add("clothes",["one","two","three","four","five","six"],[5,20,36,10,75,90])

env = create_default_environment("html")
#为渲染创建一个默认配置环境

env.render_chart_to_file(bar,path='bar.html')
env.render_chart_to_file(line,path='line.html')

 

 添加最值、平均值

from pyecharts import Bar

attr=["{}month".format(i) for i in range(1,13)]
v1=[2.0,4.9,7.0,23.2,25.6,76.7,135.6,162.2,32.6,20.0,6.4,3.3]
v2=[2.6,5.9,9.0,26.4,28.7,70.7,175.6,182.2,48.7,18.8,6.0,2.3]
bar=Bar("Bar Example")
bar.add("Evaporation",attr,v1,mark_line=["average"],mark_point=["max","min"])
bar.add("Precipitation",attr,v2,mark_line=["average"],mark_point=["max","min"])

bar.render(r"D:\chart4.html")

 

 饼状图

from pyecharts import Pie

attr=["A","B","C","D","E","F"]
v1=[11,12,13,10,10,10]
v2=[19,21,32,20,20,33]
pie=Pie("Pie Chart",title_pos='center',width=900)
pie.add("Goods1",attr,v1,center=[25,50],is_random=True,radius=[30,75],rosetype='radius')
pie.add("Goods2",attr,v2,center=[75,50],is_random=True,radius=[30,75],rosetype='area',is_legend_show=False,is_label_show=True)

pie.render(r"D:\PieChart.html")

 重叠

from pyecharts import Bar,Line,Overlap

attr=['A','B','C','D','E','F']
v1=[10,20,30,40,50,60]
v2=[38,28,58,48,78,68]
bar=Bar("Line-Bar")
bar.add("bar",attr,v1)
line=Line()
line.add("line",attr,v2)

overlap=Overlap()
overlap.add(bar)
overlap.add(line)

overlap.render(r"D:\IntergrateChart.html")

 

 

滑块的使用

import random
from pyecharts import Bar

attr=["day{}".format(i) for i in range(30)]
v1=[random.randint(1,30) for _ in range(30)]
bar=Bar("Bar-datazoom-slider")
bar.add("",attr,v1,is_label_show=True,is_datazoom_show=True)
bar.render(r"D:\---.html")

 

还在学习中.....

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值