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

 

‍♂️ 个人主页:@艾派森的个人主页

✍作者简介:Python学习者
希望大家多多支持,我们一起进步!
如果文章对你有帮助的话,
欢迎评论 点赞 收藏 加关注+


目录

PyEcharts 简介

Bar图

Line图

Pie图

Scatter图 

 Boxplot图

 heatmap图

 Kline图

funne图

WordCloud图

 Radar图

Map图

 组合图

Timeline图


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()

pyecharts绘制条形图、饼图、散点图、词云图、地图等常用图形_第1张图片


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()

 pyecharts绘制条形图、饼图、散点图、词云图、地图等常用图形_第2张图片

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()

pyecharts绘制条形图、饼图、散点图、词云图、地图等常用图形_第3张图片

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()

 pyecharts绘制条形图、饼图、散点图、词云图、地图等常用图形_第4张图片

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()

pyecharts绘制条形图、饼图、散点图、词云图、地图等常用图形_第5张图片

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()

 pyecharts绘制条形图、饼图、散点图、词云图、地图等常用图形_第6张图片

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()

 pyecharts绘制条形图、饼图、散点图、词云图、地图等常用图形_第7张图片

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()

 pyecharts绘制条形图、饼图、散点图、词云图、地图等常用图形_第8张图片

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()

pyecharts绘制条形图、饼图、散点图、词云图、地图等常用图形_第9张图片

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()

pyecharts绘制条形图、饼图、散点图、词云图、地图等常用图形_第10张图片

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()

pyecharts绘制条形图、饼图、散点图、词云图、地图等常用图形_第11张图片

 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()

pyecharts绘制条形图、饼图、散点图、词云图、地图等常用图形_第12张图片

 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()

pyecharts绘制条形图、饼图、散点图、词云图、地图等常用图形_第13张图片

 Kline图

from pyecharts import options as opts
from pyecharts.charts import Kline

data = [
    [2320.26, 2320.26, 2287.3, 2362.94],
    [2300, 2291.3, 2288.26, 2308.38],
    [2295.35, 2346.5, 2295.35, 2345.92],
    [2347.22, 2358.98, 2337.35, 2363.8],
    [2360.75, 2382.48, 2347.89, 2383.76],
    [2383.43, 2385.42, 2371.23, 2391.82],
    [2377.41, 2419.02, 2369.57, 2421.15],
    [2425.92, 2428.15, 2417.58, 2440.38],
    [2411, 2433.13, 2403.3, 2437.42],
    [2432.68, 2334.48, 2427.7, 2441.73],
    [2430.69, 2418.53, 2394.22, 2433.89],
    [2416.62, 2432.4, 2414.4, 2443.03],
    [2441.91, 2421.56, 2418.43, 2444.8],
    [2420.26, 2382.91, 2373.53, 2427.07],
    [2383.49, 2397.18, 2370.61, 2397.94],
    [2378.82, 2325.95, 2309.17, 2378.82],
    [2322.94, 2314.16, 2308.76, 2330.88],
    [2320.62, 2325.82, 2315.01, 2338.78],
    [2313.74, 2293.34, 2289.89, 2340.71],
    [2297.77, 2313.22, 2292.03, 2324.63],
    [2322.32, 2365.59, 2308.92, 2366.16],
    [2364.54, 2359.51, 2330.86, 2369.65],
    [2332.08, 2273.4, 2259.25, 2333.54],
    [2274.81, 2326.31, 2270.1, 2328.14],
    [2333.61, 2347.18, 2321.6, 2351.44],
    [2340.44, 2324.29, 2304.27, 2352.02],
    [2326.42, 2318.61, 2314.59, 2333.67],
    [2314.68, 2310.59, 2296.58, 2320.96],
    [2309.16, 2286.6, 2264.83, 2333.29],
    [2282.17, 2263.97, 2253.25, 2286.33],
    [2255.77, 2270.28, 2253.31, 2276.22],
]

kline = Kline()
kline.add_xaxis([f'2030/10/{i+1}' for i in range(len(data))])
kline.add_yaxis('',data,
itemstyle_opts=opts.ItemStyleOpts(color='red',color0='green')
)
kline.set_global_opts(title_opts=opts.TitleOpts(title='Kline的基本图'))
kline.render_notebook()

pyecharts绘制条形图、饼图、散点图、词云图、地图等常用图形_第14张图片

funne图

from pyecharts.charts import Funnel
from pyecharts.faker import Faker
from pyecharts import options as opts

funnel = Funnel()
funnel.add('',[list(z) for z in zip(Faker.choose(),Faker.values())])
funnel.set_global_opts(title_opts=opts.TitleOpts(title='漏斗图'))
funnel.render_notebook()

 pyecharts绘制条形图、饼图、散点图、词云图、地图等常用图形_第15张图片

WordCloud图

from pyecharts.charts import WordCloud
from pyecharts import options as opts

wc = WordCloud()
data = [
    ['ThinkPad','15.7'],
    ['联想','14.5'],
    ['惠普','14.4'],
    ['华为','11.7'],
    ['华硕','8.2'],
    ['戴尔','8.1'],
    ['Acer宏碁','4.5'],
    ['苹果','3.5'],
    ['神舟','3.2'],
    ['ROG','3.1'],
    ['机械革命','2.4'],
    ['msi微星','1.8'],
    ['外星人','1.5'],
    ['微软','1.4'],
    ['荣耀','1.2'],
    ['雷神','1'],
    ['三星','0.7'],
    ['红米','0.6'],
    ['机械师','0.5'],
    ['小米','0.5'],
    ['炫龙','0.4'],
    ['雷蛇','0.2'],
    ['壹号本','0.1'],
    ['a豆','0.1'],
    ['未来人类','0.1'],
    ['技嘉','0.1'],
    ['中柏','0.1'],
    ['VAIO','0.1'],
    ['火影','0.1'],
    ['LG','0.1'],
    ['松下','0'],
    ['麦本本','0'],
    ['吾空','0'],
    ['长城','0'],
    ['GPD','0'],
    ['清华同方','0'],
    ['神基','0'],
    ['爱尔轩','0'],
    ['酷比魔方','0'],
    ['海尔','0'],
    ['谷歌','0'],
    ['台电','0'],
    ['iru','0'],
    ['攀升IPASON','0'],
    ['NEC','0'],
    ['夏普','0'],
    ['京东京造','0'],
    ['锡恩帝','0'],
    ['皓勤','0'],
    ['Intel','0'],
]
wc.add('',data)
wc.set_global_opts(title_opts=opts.TitleOpts('词云图'))
wc.render_notebook()

 pyecharts绘制条形图、饼图、散点图、词云图、地图等常用图形_第16张图片

 Radar图

from pyecharts.charts import Radar
from pyecharts import options as opts

radar = Radar()

data1 = [[8,7,8,8,9,7]]
data2 = [[9,5,7,8,6,7]]

radar.add_schema(
    schema=[
        opts.RadarIndicatorItem(name='拍照',max_=10),
        opts.RadarIndicatorItem(name='外观',max_=10),
        opts.RadarIndicatorItem(name='性能',max_=10),
        opts.RadarIndicatorItem(name='屏幕',max_=10),
        opts.RadarIndicatorItem(name='内存',max_=10),
        opts.RadarIndicatorItem(name='系统',max_=10)]
)
radar.add('OPPO',data1)
radar.add('华为',data2)
radar.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
radar.set_global_opts(title_opts=opts.TitleOpts('雷达图'))
radar.render_notebook()

pyecharts绘制条形图、饼图、散点图、词云图、地图等常用图形_第17张图片

Map图

from pyecharts.charts import Map
from pyecharts import options as opts

map = Map()
map.add('',[['河北',10],['四川',20]],is_map_symbol_show=False)
map.set_global_opts(
    title_opts=opts.TitleOpts('地图'),
    visualmap_opts=opts.VisualMapOpts()
)
map.render_notebook()

 pyecharts绘制条形图、饼图、散点图、词云图、地图等常用图形_第18张图片

from pyecharts.charts import Map
from pyecharts import options as opts

map = Map()
map.add('',
[['西安市',10],['安康市',20]],
maptype='陕西',
is_map_symbol_show=False,
label_opts=opts.LabelOpts(is_show=True))
map.set_global_opts(
    title_opts=opts.TitleOpts('陕西省'),
    visualmap_opts=opts.VisualMapOpts()
)
map.render_notebook()

pyecharts绘制条形图、饼图、散点图、词云图、地图等常用图形_第19张图片

 组合图


from pyecharts.charts import Bar,Line
from pyecharts import options as opts

x = ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
bar =Bar()
bar.add_xaxis(x)
bar.add_yaxis('蒸发量',
[2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3],
label_opts=opts.LabelOpts(is_show=False))
bar.add_yaxis('降水量',
[2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3],
label_opts=opts.LabelOpts(is_show=False))
bar.set_global_opts(
    title_opts=opts.TitleOpts('混合图'),
    tooltip_opts=opts.TooltipOpts(is_show=True,trigger='axis',axis_pointer_type='cross'),
    xaxis_opts= opts.AxisOpts(type_='category',axispointer_opts=opts.AxisPointerOpts(is_show=True,type_='shadow'))
    )

bar.extend_axis(yaxis=opts.AxisOpts(
    name='温度',min_=0,max_= 25,
    interval = 5,
    axislabel_opts = opts.LabelOpts(formatter='{value} °C')
))

line = Line()
line.add_xaxis(x)
line.add_yaxis('平均温度',
[2.0, 2.2, 3.3, 4.5, 6.3, 10.2, 20.3, 23.4, 23.0, 16.5, 12.0, 6.2],
yaxis_index=1,
label_opts=opts.LabelOpts(is_show=False)
)

bar.overlap(line) # 合并图
bar.render_notebook()


pyecharts绘制条形图、饼图、散点图、词云图、地图等常用图形_第20张图片

Timeline图

from pyecharts.charts import Bar,Timeline
from pyecharts import options as opts
from pyecharts.faker import Faker

x = Faker.choose()
tl = Timeline() 
for i in range(2000,2006):
    bar = Bar()
    bar.add_xaxis(x)
    bar.add_yaxis('A',Faker.values())
    bar.add_yaxis('B',Faker.values())
    bar.set_global_opts(title_opts=opts.TitleOpts(f'{i}年的数据表'))
    tl.add(bar,f'{i}年')
tl.render_notebook()

 pyecharts绘制条形图、饼图、散点图、词云图、地图等常用图形_第21张图片

你可能感兴趣的:(数据可视化,echarts,数据分析,前端)