Pyecharts

画图的(doge)

文章目录

  • Pyecharts
    • 一、 柱状图
      • 单列柱状图
      • 多列柱状图
      • 水平柱状图
    • 二、 饼状图
      • 一般饼状图
      • 玫瑰图
    • 三、折线图
    • 四、 漏斗图
    • 五、散点图
      • 一般散点图
      • 涟漪散点图
    • 六、K线图
    • 七、仪表盘
    • 八、词云图
    • 九、 Page-顺序多图
    • 十、Grid-并行多图

一、 柱状图

使用Bar函数可以绘制柱状图。

单列柱状图

from pyecharts.charts import Bar
from pyecharts import options as optsbar = Bar()
bar.add_xaxis(['1号选手', '2号选手', '3号选手', '4号选手', '5号选手'])
bar.add_yaxis("第一轮", [87, 91, 86, 85, 93])
bar.set_global_opts(title_opts=opts.TitleOpts(title="各选手得分情况"))bar.render_notebook()

运行结果为:

多列柱状图

在原代码基础上再加一行add_yaxis即可。

from pyecharts.charts import Bar
from pyecharts import options as optsbar = Bar()
bar.add_xaxis(['1号选手', '2号选手', '3号选手', '4号选手', '5号选手'])
bar.add_yaxis("第一轮", [87, 91, 86, 85, 93])
bar.add_yaxis("第二轮", [90, 90, 87, 86, 89])
bar.set_global_opts(title_opts=opts.TitleOpts(title="各选手得分情况"))bar.render_notebook()

运行结果为:

水平柱状图

使用**bar.reversal_axis()**可以绘制水平柱状图。

from pyecharts.charts import Bar
from pyecharts import options as optsbar = Bar()
bar.add_xaxis(['1号选手', '2号选手', '3号选手', '4号选手', '5号选手'])
bar.add_yaxis("第一轮", [87, 91, 86, 85, 93])
bar.add_yaxis("第二轮", [90, 90, 87, 86, 89])
bar.set_global_opts(title_opts=opts.TitleOpts(title="各选手得分情况"))bar.reversal_axis()bar.render_notebook()

运行结果为:

二、 饼状图

饼状图通常用来表现不同类别的占比情况。

Pie可以绘制饼状图。

一般饼状图

from pyecharts.charts import Pie
from pyecharts import options as optslist1 = ['优秀', '良好', '及格', '不及格']
num = [11, 35, 7, 2]c = Pie()
#这一步,是要将list1里面的元素和num里面的元素用zip函数对应打包成一个元组,然后形成一个列表。
c.add("", [list(z) for z in zip(list1, num)])
c.set_global_opts(title_opts=opts.TitleOpts(title='Pie-2班成绩占比'))
#这一步没怎么懂,应该是设置标签的形式
c.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}"))c.render_notebook()

运行结果为:

关于上面代码中的:c.set_series_opts(label_opts=opts.LabelOpts(formatter=“{b}: {c}”))

我试了一下把{b}去掉,运行后饼状图的标签就只剩数字了;相反,去掉{c}运行之后就只剩文字了;全部去掉运行也是文字。

玫瑰图

add()中:

参数radius用于设置饼状图半径,默认为[0, 75],前面为内半径后面为外半径

参数center用于设置饼状图中心坐标,默认为[50, 50];

参数rosetype用于设置玫瑰图,有两种表现形式,分别为radiusarea

from pyecharts.charts import Pie
from pyecharts import options as optslist1 = ['优秀', '良好', '及格', '不及格']
num = [11, 35, 7, 2]c = Pie()
c.add("", [list(z) for z in zip(list1, num)], radius=["40%", "55%"], center=[240, 210], rosetype='radius')
c.add("", [list(z) for z in zip(list1, num)], radius=["40%", "55%"], center=[640, 210], rosetype='area')
c.set_global_opts(title_opts=opts.TitleOpts(title='2班成绩占比-玫瑰图'))
c.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}:{c}"))c.render_notebook()

运行结果为:(左图为radius形式,右图为area形式)

三、折线图

通过Line绘制折线图。

from pyecharts.charts import Line
from pyecharts import options as optsl = Line()
l.add_xaxis(['1号选手', '2号选手', '3号选手', '4号选手', '5号选手'])
l.add_yaxis("第一轮", [87, 91, 86, 85, 93])
l.set_global_opts(title_opts=opts.TitleOpts(title="各选手得分情况"))l.render_notebook()

运行结果为:

四、 漏斗图

通过Funnel绘制漏斗图。

from pyecharts.charts import Funnel
from pyecharts import options as optslabels = ['跑步', '足球', '篮球', '羽毛球', '乒乓球']
data = [65, 20, 53, 45, 49]f = Funnel()
f.add('', [list(z) for z in zip(labels, data)], is_selected=True)
f.set_global_opts(title_opts=opts.TitleOpts(title="运动类型喜好"))f.render_notebook()

运行结果为:

五、散点图

通过Scatter绘制散点图。

一般散点图

from pyecharts.charts import Scatter
from pyecharts import options as optslabels = ['跑步', '足球', '篮球', '羽毛球', '乒乓球']
data = [65, 20, 53, 45, 49]s = Scatter()
s.add_xaxis(labels)
s.add_yaxis('大一', data)
s.set_global_opts(title_opts=opts.TitleOpts(title="喜好不同运动类型的人数"))s.render_notebook()

运行结果为:

涟漪散点图

from pyecharts.charts import EffectScatter
from pyecharts import options as optslabels = ['跑步', '足球', '篮球', '羽毛球', '乒乓球']
data = [65, 20, 53, 45, 49]es = EffectScatter()
es.add_xaxis(labels)
es.add_yaxis('大一', data)
es.set_global_opts(title_opts=opts.TitleOpts(title="喜好不同运动类型的人数"))es.render_notebook()

运行结果为:(动态的,但这里看不出来)

六、K线图

通过Kline绘制K线图。

from pyecharts.charts import Kline
from pyecharts import options as optslabels = ["2022年10月{}日".format(i) for i in range(1, 32)]
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],
]k = Kline()
k.add_xaxis(labels)
k.add_yaxis("2022年10月份K线图", data)
k.set_global_opts(title_opts=opts.TitleOpts(title="数据抄的,不知道是啥"))k.render_notebook()

运行结果为:

七、仪表盘

通过Gauge绘制仪表盘。

from pyecharts.charts import Gauge
from pyecharts import options as optsg = Gauge()
g.add(" ", [("tempo", 70)], detail_label_opts=opts.GaugeDetailOpts(offset_center=[0, 90]))
g.set_global_opts(title_opts=opts.TitleOpts(title="任务完成率"), legend_opts=opts.LegendOpts(is_show=True))g.render_notebook()

其中:detail_label_opts=opts.GaugeDetailOpts(offset_center=[0, 90]))是设置偏移量,这么做的话文字和数字就不会重合在一起,But!不知道为什么,将数字移走之后,就没有百分号了。

运行结果为:

八、词云图

通过WordCloud绘制词云图。

from pyecharts.charts import WordCloud
from pyecharts import options as optswords = [("where", 500),("there", 400),("is", 487),("a", 355),("will", 247),("there", 666),("is", 578),("a", 184),("way", 120),
]w = WordCloud()
w.add("", words)
w.set_global_opts(title_opts=opts.TitleOpts(title="一句名言"))w.render_notebook()

以元组的形式生成词云图,后面的数字表示相对大小?

运行结果为:

九、 Page-顺序多图

通过Page可以把多张图按顺序展现。

from pyecharts.charts import Line, Bar, Page
from pyecharts import options as optsl = Line()
l.add_xaxis(['1号选手', '2号选手', '3号选手', '4号选手', '5号选手'])
l.add_yaxis("第一轮", [87, 91, 86, 85, 93])
l.set_global_opts(title_opts=opts.TitleOpts(title="各选手得分情况"))bar = Bar()
bar.add_xaxis(['1号选手', '2号选手', '3号选手', '4号选手', '5号选手'])
bar.add_yaxis("第一轮", [87, 91, 86, 85, 93])
bar.set_global_opts(title_opts=opts.TitleOpts(title="各选手得分情况"))p = Page()
p.add(l,bar)p.render_notebook()

运行结果为:

十、Grid-并行多图

通过Grid来实现多图并行

from pyecharts.charts import Line, Bar, Grid
from pyecharts import options as optsl = Line()
l.add_xaxis(['1号', '2号', '3号', '4号', '5号'])
l.add_yaxis("十月", [30, 25, 18, 19, 20])
l.set_global_opts(title_opts=opts.TitleOpts(title="气温"))bar = Bar()
bar.add_xaxis(['1号', '2号', '3号', '4号', '5号'])
bar.add_yaxis("十月", [30, 25, 18, 19, 20])g = Grid()
g.add(bar, grid_opts=opts.GridOpts(pos_left="70%", pos_bottom="70%"))
g.add(l, grid_opts=opts.GridOpts(pos_right="10%"))g.render_notebook()

其中:

pos_left="50%"是指在左侧留出50%的空间,其他同理。

运行结果为:

笔记:Pyecharts相关推荐

  1. 学习笔记 | pyecharts (V0.5版本) 画图

    使用如下代码来查看安装的pyecharts版本 import pyecharts print(pyecharts.__version__) 绘图逻辑 选择图表类型 添加数据 设置全局变量 显示及保存图 ...

  2. pyecharts查看版本_pyecharts v1 版本 学习笔记 折线图,面积图

    折线图 折线图 基本demo import pyecharts.options as opts from pyecharts.charts import Line c = ( Line() .add_ ...

  3. Pyecharts绘图笔记

    Pyecharts绘图笔记 柱状图 堆叠柱状图 翻转柱状图 直方图 折线图 显示 散点图 箱型图 面积图 仪表盘 饼状图 圆环图 玫瑰图 层叠图 水平组合图grid 水平组合图grid1 垂直组合图g ...

  4. Python数据可视化——pyecharts学习笔记

    导读:Python数据可视化的库有很多,常见的有matplotlib.pyplot.Seaborn.pyecharts等. pyecharts是一款将python与echarts相结合的数据可视化库, ...

  5. 【学习笔记】python - pyecharts

    pyecharts pyecharts是一款将python与echarts结合的强大的数据可视化工具.echarts是百度开源的一个数据可视化JS库,主要用于数据可视化,而pyecharts则是一个用 ...

  6. pyecharts x轴字体大小调整_pyecharts 柱状图基础篇#学习笔记#

    2020年初,很久没有用过pyecharts的我由于工作原因,安装了新版pyecharts之后,以前的pyecharts代码报错了.搜索之后才发现,我安装的是不兼容旧版本的新版. 空闲的时间,把新版e ...

  7. python在哪里画柱形图_Python笔记:用pyecharts绘制柱形图

    简介: pyecharts 是一个用于生成 Echarts 图表的类库. echarts 是百度开源的一个数据可视化 JS 库,主要用于数据可视化.pyecharts 是一个用于生成 Echarts ...

  8. [数据分析笔记] 网易云歌单分析系列02—pyecharts柱状图

    文章目录 0.前言 1.百分比堆叠柱状图 1.1 导入包,连接数据库 1.2 查看数据 1.3 数据预处理 1.4 生成图表 2.复合柱状图和折线图 2.1 数据预处理 2.2 生成图表 3.竖直缩放 ...

  9. [数据分析笔记] 网易云歌单分析系列03—pyecharts折线图

    0.导入数据 import numpy as np import pandas as pd import pymysql from pyecharts import options as opts f ...

  10. [pyecharts学习笔记]——Pie饼图

    基本示例 from pyecharts import options as opts from pyecharts.charts import Pie from pyecharts.faker imp ...

最新文章

  1. linux脚本或关系表达,Shell运算符:Shell算数运算符、关系运算符、布尔运算符、字符串运算符等...
  2. [Security]XSS一直是个棘手的问题
  3. Java线程池--ThreadPoolExecutor
  4. 原生JavaScript实现异步校验详解
  5. ant接口用什么天线_拆解测量真假钻石手台天线SRH805S
  6. 电脑录屏用什么软件?录屏软件哪个好用?
  7. viper4android还用酷狗,听HiFi专业的App,VIPER独占USB源码输出发烧友用过都上瘾
  8. linux调试符号表,strip去除目标文件中符号表、调试符号表信息
  9. matlab新手入门的简单操作
  10. 杭电多校(MINIEYE)第四场 补题
  11. chrome浏览器打开网页,总是跳转到2345主页的解决方法 2345.com 绑架主页
  12. 使用FastDFS实现图片服务器的功能【案例演示】
  13. LVDT接口测试工装研究
  14. BUU XXE COURSE
  15. win7系统问题:——桌面壁纸变黑解决方案
  16. c语言中定义一个十六进制的数,C语言如何定义一个16进制数
  17. 灰关联分析与语音/音乐信号识别
  18. 房价这么高,为什么租金却高不起来?
  19. 比尔盖茨与乔布斯,你们觉得,二人谁更伟大
  20. SpringBoot项目云端部署

热门文章

  1. 逻辑思维训练题:切西瓜之这个人是怎么切西瓜的?
  2. 清华姚班90后学霸、MIT博士吴佳俊即将加入斯坦福任助理教授
  3. CSS 3之图片对齐方式
  4. Android 11.0 recovery页面旋转180度问题的解决方案
  5. webrtc M66 RtpRtcp模块和Pacer模块的关系
  6. java中git使用教程_Git—使用方法
  7. 计算机应用技能知识竞赛,计算机应用技能大赛练习题1
  8. HTML-个人简历表格制作
  9. FreeMarker的逻辑判断功能简介
  10. Oracle的高级复制、流复制、备库的区别