pyecharts绘制条形图、饼图、散点图、词云图、地图等常用图形(一)

简介: pyecharts绘制条形图、饼图、散点图、词云图、地图等常用图形

PyEcharts 简介

Echarts 是一个由百度开源的数据可视化,凭借着良好的交互性,精巧的图表设计,得到了众 多开发者的认可。而 Python 是一门富有表达力的语言,很适合用于数据处理。当数据分析遇 上数据可视化时,pyecharts 诞生了。

特性


• 简洁的 API 设计,使用如丝滑般流畅,支持链式调用


• 囊括了 30+ 种常见图表,应有尽有


• 支持主流 Notebook 环境,Jupyter Notebook 和 JupyterLab


• 可轻松集成至 Flask,Django 等主流 Web 框架


• 高度灵活的配置项,可轻松搭配出精美的图表


• 详细的文档和示例,帮助开发者更快的上手项目


• 多达 400+ 地图文件以及原生的百度地图,为地理数据可视化提供强有力的支持

Bar图

from pyecharts.charts import Bar
from pyecharts.faker import Faker
from pyecharts import options as  opts 
bar = Bar()
bar.add_xaxis(Faker.choose())
bar.add_yaxis('销售团队A',Faker.values())
bar.add_yaxis('销售团队B',Faker.values())
bar.set_series_opts(markline_opts=opts.MarkLineOpts(
    data=[opts.MarkLineItem(type_='max',name='最大值')]
))
bar.render_notebook()

image.png

from pyecharts.charts import Bar
from pyecharts.faker import Faker
from pyecharts import options as  opts 
bar = Bar()
bar.add_xaxis(Faker.choose())
bar.add_yaxis('销售团队A',Faker.values())
bar.add_yaxis('销售团队B',Faker.values())
bar.reversal_axis()
bar.set_series_opts(label_opts=opts.LabelOpts(position="right"))
bar.set_global_opts(title_opts=opts.TitleOpts(title="XY翻转"))
bar.render_notebook()

image.png

from pyecharts.charts import Bar
from pyecharts.faker import Faker
from pyecharts import options as  opts 
bar = Bar()
bar.add_xaxis(Faker.choose())
bar.add_yaxis('销售团队A',Faker.values(),stack='stack')
bar.add_yaxis('销售团队B',Faker.values(),stack='stack')
bar.set_global_opts(title_opts=opts.TitleOpts(title="堆叠图"))
bar.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
bar.render_notebook()

image.png

Line图

from pyecharts.charts import Line
from pyecharts import options as opts
from pyecharts.faker import Faker
line = Line()
line.add_xaxis(xaxis_data=Faker.choose())
line.add_yaxis('商家A',y_axis=Faker.values())
line.add_yaxis('商家B',y_axis=Faker.values())
line.set_global_opts(xaxis_opts=opts.AxisOpts(splitline_opts = opts.SplitLineOpts(is_show=True)))
line.render_notebook()

image.png

from pyecharts.charts import Line
from pyecharts import options as opts
from pyecharts.faker import Faker
line = Line()
line.add_xaxis(xaxis_data=Faker.choose())
line.add_yaxis('商家A',y_axis=Faker.values(),is_smooth = True)
line.add_yaxis('商家B',y_axis=Faker.values(),is_smooth = True)
line.set_global_opts(xaxis_opts=opts.AxisOpts(splitline_opts = opts.SplitLineOpts(is_show=True)))
line.render_notebook()

image.png

from pyecharts.charts import Line
from pyecharts import options as opts
from pyecharts.faker import Faker
line = Line()
x_values = Faker.choose()
line.add_xaxis(x_values)
line.add_yaxis(
    series_name=x_values[0],
    y_axis=Faker.values(),
    stack="总量",
    label_opts= opts.LabelOpts(is_show=False),
    areastyle_opts = opts.AreaStyleOpts(opacity=0.5)
    )
line.add_yaxis(
    series_name=x_values[1],
    y_axis=Faker.values(),
    stack="总量",
    label_opts= opts.LabelOpts(is_show=False),
    areastyle_opts = opts.AreaStyleOpts(opacity=0.5))
line.add_yaxis(
    series_name=x_values[2],
    y_axis=Faker.values(),
    stack="总量",
    label_opts= opts.LabelOpts(is_show=False),
    areastyle_opts = opts.AreaStyleOpts(opacity=0.5))
line.add_yaxis(
series_name=x_values[3],
y_axis=Faker.values(),
stack="总量",
    label_opts= opts.LabelOpts(is_show=False),
    areastyle_opts = opts.AreaStyleOpts(opacity=0.5))
line.add_yaxis(
    series_name=x_values[4],
    y_axis=Faker.values(),
    stack="总量",
    label_opts= opts.LabelOpts(is_show=False),
    areastyle_opts = opts.AreaStyleOpts(opacity=0.5))
line.set_global_opts(xaxis_opts=opts.AxisOpts(boundary_gap=False))
line.render_notebook()

image.png

Pie

from pyecharts.charts import Pie
from pyecharts import options as opts
from pyecharts.faker import Faker
pie = Pie()
pie.add('',[list(z) for z in zip(Faker.choose(),Faker.values())])
pie.set_global_opts(title_opts=opts.TitleOpts(title="Pie的基本图表"))
pie.render_notebook()

image.png

from pyecharts.charts import Pie
from pyecharts import options as opts
from pyecharts.faker import Faker
pie = Pie()
pie.add('',[list(z) for z in zip(Faker.choose(),Faker.values())],radius=['50%','70%'])
pie.set_global_opts(title_opts=opts.TitleOpts(title="Pie的基本图表"))
pie.render_notebook()

image.png

pie = Pie()
pie.add('',[list(z) for z in zip(Faker.choose(),Faker.values())],rosetype='radius')
pie.set_global_opts(title_opts=opts.TitleOpts(title="Pie的基本图表"))
pie.render_notebook()

image.png

Scatter图

from pyecharts.charts import Scatter
from pyecharts import options as opts
from random import random,randint
x = [randint(0,100) for i in range(100)]
y = [randint(0,100) for i in range(100)]
sca = Scatter()
sca.add_xaxis(xaxis_data=x)
sca.add_yaxis('',y_axis=y,label_opts=opts.LabelOpts(is_show=False),symbol_size=10,symbol='rect')
sca.set_global_opts(xaxis_opts=opts.AxisOpts(type_='value'))
sca.render_notebook()

image.png

from pyecharts.charts import Scatter
from pyecharts import options as opts
from random import random,randint
x = [randint(0,100) for i in range(10)]
y = [randint(0,100) for i in range(10)]
sca = Scatter()
sca.add_xaxis(xaxis_data=x)
sca.add_yaxis('',y_axis=y,label_opts=opts.LabelOpts(is_show=True))
sca.set_global_opts(xaxis_opts=opts.AxisOpts(type_='value')
,visualmap_opts=opts.VisualMapOpts(type_='size'))
sca.render_notebook()

image.png

Boxplot

from pyecharts.charts import Boxplot
from pyecharts import options as opts
from random import randint
box = Boxplot()
box.add_xaxis([f'{i}月' for i in range(1,5)])
box.add_yaxis('A',box.prepare_data([
    [randint(50,80) for i in range(50)],
    [randint(70,100) for i in range(50)],
    [randint(50,90) for i in range(50)],
    [randint(50,120) for i in range(50)],
    ]))
box.set_global_opts(title_opts=opts.TitleOpts(title='箱图的基本案例'))
box.render_notebook()

image.png

heatmap图

from pyecharts.charts import HeatMap
from pyecharts import options as opts
from pyecharts.faker import Faker
from random import randint
from pyecharts.types import VisualMap
value = [[i,j, randint(0,40)] for i in range(24) for j in range(7)]
hm = HeatMap()
hm.add_xaxis(Faker.clock)
hm.add_yaxis('',Faker.week,value,label_opts=opts.LabelOpts(is_show=True,position='inside'))
hm.set_global_opts(title_opts=opts.TitleOpts(title='热力图'),
visualmap_opts= opts.VisualMapOpts()
)
hm.render_notebook()

image.png

目录
相关文章
|
5月前
|
Python
Python学习笔记之Matplotlib模块入门(直线图、折线图、曲线图、散点图、柱状图、饼状图、直方图、等高线图和三维图的绘制)-2
Python学习笔记之Matplotlib模块入门(直线图、折线图、曲线图、散点图、柱状图、饼状图、直方图、等高线图和三维图的绘制)
|
5月前
|
数据可视化 开发者 Python
Python学习笔记之Matplotlib模块入门(直线图、折线图、曲线图、散点图、柱状图、饼状图、直方图、等高线图和三维图的绘制)-1
Python学习笔记之Matplotlib模块入门(直线图、折线图、曲线图、散点图、柱状图、饼状图、直方图、等高线图和三维图的绘制)
|
6月前
|
NoSQL 数据库 Python
PyQt学习(二)-----图形的建立(柱状图,折线图,堆叠柱状图,饼图)
PyQt学习(二)-----图形的建立(柱状图,折线图,堆叠柱状图,饼图)
80 1
|
6月前
【SPSS】基础图形的绘制(条形图、折线图、饼图、箱图)详细操作过程(上)
【SPSS】基础图形的绘制(条形图、折线图、饼图、箱图)详细操作过程
466 0
|
6月前
【SPSS】基础图形的绘制(条形图、折线图、饼图、箱图)详细操作过程(下)
【SPSS】基础图形的绘制(条形图、折线图、饼图、箱图)详细操作过程
388 0
|
6月前
|
存储 数据可视化
使用 plotly 绘制旭日图
使用 plotly 绘制旭日图
286 0
|
编解码 前端开发 JavaScript
Matplotlib使用和绘制二维图表
Matplotlib使用和绘制二维图表
99 0
|
数据可视化 数据处理
R绘图案例|基于分面的折线图绘制
R绘图案例|基于分面的折线图绘制
281 0
|
开发者
pyecharts基础之柱状图的绘制
pyecharts分为v0.5.X和v1两个大版本,0.5.x 版本将不再进行维护推荐使用v1版本
108 0
|
定位技术
pyecharts绘制条形图、饼图、散点图、词云图、地图等常用图形(二)
pyecharts绘制条形图、饼图、散点图、词云图、地图等常用图形
172 0
pyecharts绘制条形图、饼图、散点图、词云图、地图等常用图形(二)