pyecharts模块 【图形模块/数据可视化】(3)
快速开始
#coding=utf-8 from __future__ import unicode_literals from pyecharts import Bar bar = Bar("主题","副标题") bar.add("服装",["衬衫","羊毛衫","雪融衣"],[5,20,30],is_more_utils=True)#主要方法,用于添加图表的数据和设置各种配置项 bar.use_theme('dark') #更换主题色彩 #bar.print_echarts_options() #该行只为了打印配置项,方便调试使用 bar.render() #生成本地HTML文件
#柱状堆叠图 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_v2, is_stack=True) .render())
from pyecharts import Bar, Line from pyecharts.engine import create_default_environment #主题 bar = Bar("我的第一个图表", "这里是副标题") #数据 bar.add("服装", ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"], [5, 20, 36, 10, 75, 90]) #主题 line = Line("我的第一个图表", "这里是副标题") line.add("服装", ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"], [5, 20, 36, 10, 75, 90]) env = create_default_environment("html") # 为渲染创建一个默认配置环境 # create_default_environment(filet_ype) # file_type: 'html', 'svg', 'png', 'jpeg', 'gif' or 'pdf' env.render_chart_to_file(bar, path='bar.html') env.render_chart_to_file(line, path='line.html')
Pandas&Numpy 简单示例
import pandas as pd import numpy as np from pyecharts import Bar title = "bar chart" index = pd.date_range("3/8/2017",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
一个二次元的生物

浙公网安备 33010602011771号