概述

  • 前言

  • bokeh

  • pyecharts

bokeh

这里展示一下常用的图表,详细的文档可查看(https://bokeh.pydata.org/en/latest/docs/user_guide/categorical.html)

条形图

条形图

from bokeh.io import show, output_file
from bokeh.models import ColumnDataSource
from bokeh.palettes import Spectral6
from bokeh.plotting import figure
output_file("colormapped_bars.html")#  配置输出文件名
fruits = ['Apples', '魅族', 'OPPO', 'VIVO', '小米', '华为'] # 数据
counts = [5, 3, 4, 2, 4, 6] # 数据
source = ColumnDataSource(data=dict(fruits=fruits, counts=counts, color=Spectral6))
p = figure(x_range=fruits, y_range=(0,9), plot_height=250, title="Fruit Counts",toolbar_location=None, tools="")# 条形图配置项
p.vbar(x='fruits', top='counts', width=0.9, color='color', legend="fruits", source=source)p.xgrid.grid_line_color = None # 配置网格线颜色
p.legend.orientation = "horizontal" # 图表方向为水平方向
p.legend.location = "top_center"show(p) # 展示图表

年度条形图

年度条形图

from bokeh.io import show, output_file
from bokeh.models import ColumnDataSource, FactorRange
from bokeh.plotting import figure
output_file("bars.html")
fruits = ['Apples', '魅族', 'OPPO', 'VIVO', '小米', '华为']
years = ['2015', '2016', '2017']
data = {'fruits': fruits,'2015': [2, 1, 4, 3, 2, 4],'2016': [5, 3, 3, 2, 4, 6],'2017': [3, 2, 4, 4, 5, 3]}
x = [(fruit, year) for fruit in fruits for year in years]
counts = sum(zip(data['2015'], data['2016'], data['2017']), ())
source = ColumnDataSource(data=dict(x=x, counts=counts))
p = figure(x_range=FactorRange(*x), plot_height=250, title="Fruit Counts by Year",toolbar_location=None, tools="")
p.vbar(x='x', top='counts', width=0.9, source=source)
p.y_range.start = 0
p.x_range.range_padding = 0.1
p.xaxis.major_label_orientation = 1
p.xgrid.grid_line_color = None
show(p)

饼图

饼图

from collections import Counter
from math import pi
import pandas as pd
from bokeh.io import output_file, show
from bokeh.palettes import Category20c
from bokeh.plotting import figure
from bokeh.transform import cumsum
output_file("pie.html")
x = Counter({ # 数据与权重'中国': 157,'美国': 93,'日本': 89,'巴西': 63,'德国': 44,'印度': 42,'意大利': 40,'澳大利亚': 35,'法国': 31,'西班牙': 29
})
data = pd.DataFrame.from_dict(dict(x), orient='index').reset_index().rename(index=str, columns={0:'value', 'index':'country'})
data['angle'] = data['value']/sum(x.values()) * 2*pi
data['color'] = Category20c[len(x)]
p = figure(plot_height=350, title="Pie Chart", toolbar_location=None,tools="hover", tooltips="@country: @value")
p.wedge(x=0, y=1, radius=0.4,start_angle=cumsum('angle', include_zero=True), end_angle=cumsum('angle'),line_color="white", fill_color='color', legend='country', source=data)
p.axis.axis_label=None
p.axis.visible=False
p.grid.grid_line_color = None # 网格线颜色
show(p)

条形图

年度水果进出口

from bokeh.io import output_file, show
from bokeh.models import ColumnDataSource
from bokeh.palettes import GnBu3, OrRd3
from bokeh.plotting import figure
output_file("stacked_split.html")
fruits = ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']
years = ["2015", "2016", "2017"]
exports = {'fruits': fruits,'2015': [2, 1, 4, 3, 2, 4],'2016': [5, 3, 4, 2, 4, 6],'2017': [3, 2, 4, 4, 5, 3]}
imports = {'fruits': fruits,'2015': [-1, 0, -1, -3, -2, -1],'2016': [-2, -1, -3, -1, -2, -2],'2017': [-1, -2, -1, 0, -2, -2]}
p = figure(y_range=fruits, plot_height=250, x_range=(-16, 16), title="Fruit import/export, by year",toolbar_location=None)
p.hbar_stack(years, y='fruits', height=0.9, color=GnBu3, source=ColumnDataSource(exports),legend=["%s exports" % x for x in years])
p.hbar_stack(years, y='fruits', height=0.9, color=OrRd3, source=ColumnDataSource(imports),legend=["%s imports" % x for x in years])
p.y_range.range_padding = 0.1
p.ygrid.grid_line_color = None
p.legend.location = "top_left"
p.axis.minor_tick_line_color = None
p.outline_line_color = None
show(p)

散点图

散点图

from bokeh.plotting import figure, output_file, show
output_file("line.html")
p = figure(plot_width=400, plot_height=400)
p.circle([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], size=20, color="navy", alpha=0.5)
show(p)

六边形图

六边形图

import numpy as np
from bokeh.io import output_file, show
from bokeh.plotting import figure
from bokeh.util.hex import axial_to_cartesian
output_file("hex_coords.html")
q = np.array([0, 0, 0, -1, -1, 1, 1])
r = np.array([0, -1, 1, 0, 1, -1, 0])
p = figure(plot_width=400, plot_height=400, toolbar_location=None) #
p.grid.visible = False # 配置网格是否可见
p.hex_tile(q, r, size=1, fill_color=["firebrick"] * 3 + ["navy"] * 4,line_color="white", alpha=0.5)
x, y = axial_to_cartesian(q, r, 1, "pointytop")
p.text(x, y, text=["(%d, %d)" % (q, r) for (q, r) in zip(q, r)],text_baseline="middle", text_align="center")
show(p)

元素周期表

元素周期表

pyecharts

pyecharts 也是一个比较常用的数据可视化库,用得也是比较多的了,是百度 echarts 库的 python 支持。这里也展示一下常用的图表。文档地址为(http://pyecharts.org/#/zh-cn/prepare?id=%E5%AE%89%E8%A3%85-pyecharts)

条形图

条形图

from pyecharts import Bar
bar = Bar("我的第一个图表", "这里是副标题")
bar.add("服装", ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"], [5, 20, 36, 10, 75, 90])
# bar.print_echarts_options() # 该行只为了打印配置项,方便调试时使用
bar.render()    # 生成本地 HTML 文件

散点图

散点图

from pyecharts import Polar
import random
data_1 = [(10, random.randint(1, 100)) for i in range(300)]
data_2 = [(11, random.randint(1, 100)) for i in range(300)]
polar = Polar("极坐标系-散点图示例", width=1200, height=600)
polar.add("", data_1, type='scatter')
polar.add("", data_2, type='scatter')
polar.render()

饼图

饼图

import random
from pyecharts import Pie
attr = ['A', 'B', 'C', 'D', 'E', 'F']
pie = Pie("饼图示例", width=1000, height=600)
pie.add("",attr,[random.randint(0, 100) for _ in range(6)],radius=[50, 55],center=[25, 50],is_random=True,
)
pie.add("",attr,[random.randint(20, 100) for _ in range(6)],radius=[0, 45],center=[25, 50],rosetype="area",
)
pie.add("",attr,[random.randint(0, 100) for _ in range(6)],radius=[50, 55],center=[65, 50],is_random=True,
)
pie.add("",attr,[random.randint(20, 100) for _ in range(6)],radius=[0, 45],center=[65, 50],rosetype="radius",
)
pie.render()

词云

词云

from pyecharts import WordCloud
name = ['Sam S Club'] # 词条
value = [10000] # 权重
wordcloud = WordCloud(width=1300, height=620)
wordcloud.add("", name, value, word_size_range=[20, 100])
wordcloud.render()

树图

树图


转载自公众号「zone7」

python 数据可视化利器(bokeh、pyecharts)相关推荐

  1. Python 数据可视化利器 plus(plotly )

    概述 前言 推荐 plotly bokeh pyecharts 后记 前言 更新:上一篇文章<python 数据可视化利器>中,我写了 bokeh.pyecharts 的用法,但是有一个挺 ...

  2. python利器-Python 数据可视化利器

    原标题:Python 数据可视化利器 (给Python开发者加星标,提升Python技能) 作者:zone7(本文来自作者投稿,简介见末尾) 概述 前言 推荐 plotly bokeh pyechar ...

  3. python数据可视化--pyecharts生成图表

    [python可视化系列]python数据可视化利器--pyecharts echarts官网 一.前言 echarts是什么?下面是来自官方的介绍: ECharts,缩写来自Enterprise C ...

  4. python中文显示不出来_Python数据可视化利器Matplotlib,无法显示中文,怎么办?...

    原标题:Python数据可视化利器Matplotlib,无法显示中文,怎么办? matplotlib无法显示中文主要是因为默认字体不是中文字体,所以我们只需设置一下字体行了. 文字字体设置主要有两种方 ...

  5. 干货 | 一文带你搞定Python 数据可视化

    2019独角兽企业重金招聘Python工程师标准>>> 01前言 在之前的一篇文章<Python 数据可视化利器>中,我写了 Bokeh.pyecharts 的用法,但是 ...

  6. Python数据可视化神奇利器,Pyecharts的使用(1.柱状图使用之分析LPL春季赛职业选手数据可视化)

    目录 简介 安装过程 关于版本问题 柱状图使用方法 (一)简单使用 (二)高阶使用 总结 简介 Echarts 是一个由百度开源的数据可视化,凭借着良好的交互性,精巧的图表设计,得到了众多开发者的认可 ...

  7. python数据可视化利用_利用pyecharts实现python数据可视化

    **python 利用pyecharts实现python数据可视化 **web pyecharts是一种交互式图表的表达方式. pyecharts是一款将python与echarts结合的强大的数据可 ...

  8. python 仪表盘-python数据可视化:pyecharts

    发现了一个做数据可视化非常好的库:pyecharts. 非常便捷好用,大力推荐!! 官方介绍:pyecharts 是一个用于生成 Echarts 图表的类库.Echarts 是百度开源的一个数据可视化 ...

  9. Python数据可视化-Pyecharts不同的主题风格

    本文介绍 PyEcharts主题风格配置 内容,通过内置提供了 10+ 种不同的风格,另外也提供了便捷的定制主题的方法. Echarts 是一个由百度开源的数据可视化,凭借着良好的交互性,精巧的图表设 ...

最新文章

  1. 来自MIT的论文答辩、PPT教程,教你轻松应对毕业季和学术会议
  2. mysql update 锁_Mysql心路历程:两个”log”引发的”血案”
  3. Js中的callback机制
  4. POJ 3368 Frequent values 【ST表RMQ 维护区间频率最大值】
  5. cesium 水位模拟_Water Simulation
  6. 关于 SAP 电商云 Spartacus UI 修改 div 层级结果是否算是 breaking change 的问题
  7. 水晶报表设置图片高度与宽度
  8. LNMP笔记:安装 Xcache 缓存扩展,降低服务器负载
  9. cs229吴恩达机器学习课件
  10. Android Kotlin关于新增本地数据库对象表字段问题
  11. error: The folder you are executing pip from can no longer be found.
  12. 支付宝官方支付接口申请配置教程(如何开通支付宝支付接口)
  13. 11-贴片陶瓷电容材质NPO、C0G、X7R、X5R、Y5V、Z5U区别
  14. 【解决方案】用微信打开链接提示“已停止访问该网页”
  15. 商业数据分析【一】概述及职业发展
  16. python:lzma --- 用 LZMA 算法压缩
  17. Mac电脑如何删除磁盘及双系统分区?
  18. 企业信息化不可缺少之方正OA
  19. 个人理解数据中台与大数据平台区别
  20. 郑州泓晟龙腾计算机有限公司,龙腾资料管理系统

热门文章

  1. 简单的LRU Cache设计与实现
  2. UIPikerView的属性
  3. ASP.NET 4.0 来了
  4. 转:Page.ClientScript.RegisterStartupScript(me.GetType(),script1,scriptalert('111');/script)...
  5. C语言-郝斌笔记-007是否为素数
  6. Ubuntu12.04中eclipse提示框黑色背景色修改
  7. HDOJ 2642 HDU 2642 Stars ACM 2642 IN HDU
  8. xml.dom.minidom 利用hbm.xml批量生成db2注释
  9. 如何在Linux系统上刷抖音
  10. 海龟交易法则07_如何衡量风险