pyecharts 画图归纳

将本地文件导入到Pyecharts:

test = open(filename, 'r')

data = test.readlines()

test.close()

如果遇到无法导入包的情况:

sudo pip install pyecharts == 0.1.9.4

再不行:

sudo apt - get install python3 - tk

pip3 install pyecharts

mysql文件导入Pycharm的代码

import pymysql

一页多图

from pyecharts import Page

导入柱状图Bar

from pyecharts import Bar

导入饼图Pie

from pyecharts import Pie

导入折线图Line

from pyecharts import Line

导入雷达图Radar

from pyecharts import Radar

导入散点图Scatter

from pyecharts import Scatter

导入词云图WordCloud

from pyecharts import WordCloud

将mysql的数据导入pycharm

db = pymysql.connect("要连接的主机地址localhost", "用于登录的数据库用户root", "密码strongs", "要连接的数据库名")

cursor = db.cursor()

sql = "select * from 表名"

try:

cursor.execute(sql)

data = cursor.fetchall()

except:

print("Error!")

db.close()

print(data)
x = [x[0] for x in data]
y = [x[1] for x in data]

page = Page()

柱状图-Bar

设置行名

columns = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]

设置数据

data1 = [2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3]

data2 = [2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3]

设置柱状图的主标题与副标题

bar = Bar("柱状图", "一年的降水量与蒸发量", title_color='red', width=1000)

添加柱状图的数据及配置项

bar.add("图标", 列名, 列高(数据), mark_line=["average"], mark_point=["max", "min"])

bar.add("降水量", columns, data1, mark_line=['max'], mark_point=["max", "min"], is_convert=False, area_color='yellow')

bar.add("蒸发量", columns, data2, mark_line=["average"], mark_point=["max", "min"], is_convert=False)

打印输出图表的所有配置项

bar.show_config()

生成本地文件(默认为.html文件)

bar.render('./bar.html')

page.add(bar)

饼图-Pie

设置主标题与副标题,标题设置居中,设置宽度为900

pie = Pie("饼状图", "一年的降水量与蒸发量", title_pos='center', width=900)

加入数据,设置坐标位置为【25,50】,上方的colums选项取消显示

pie.add("降水量", columns, data1, center=[25, 50], is_legend_show=True)

加入数据,设置坐标位置为【75,50】,上方的colums选项取消显示,显示label标签

pie.add("蒸发量", columns, data2, center=[75, 50], is_legend_show=False, is_label_show=True)

pie.show_config()

保存图表

pie.render('./pie.html')

page.add(pie)

折线图-Line

line = Line("折线图", "一年的降水量与蒸发量")

is_label_show是设置上方数据是否显示

line.add("降水量", columns, data1, is_label_show=True)

line.add("蒸发量", columns, data2, is_label_show=True)

line.render('./line.html')

page.add(line)

雷达图-Radar

radar = Radar("雷达图", "一年的降水量与蒸发量")

由于雷达图传入的数据得为多维数据,所以这里需要做一下处理

radar_data1 = [[2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3]]

radar_data2 = [[2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3]]

设置column的最大值,为了雷达图更为直观,这里的月份最大值设置有所不同

schema = [

("Jan", 5), ("Feb", 10), ("Mar", 10),

("Apr", 50), ("May", 50), ("Jun", 200),

("Jul", 200), ("Aug", 200), ("Sep", 50),

("Oct", 50), ("Nov", 10), ("Dec", 5)

]

传入坐标

radar.config(schema)

radar.add("降水量", radar_data1)

一般默认为同一种颜色,这里为了便于区分,需要设置item的颜色

radar.add("蒸发量", radar_data2, item_color="#1C86EE")

radar.render('./radar.html')

page.add(radar)

散点图-scatter

scatter = Scatter("散点图", "一年的降水量与蒸发量")

xais_name是设置横坐标名称,这里由于显示问题,还需要将y轴名称与y轴的距离进行设置

scatter.add("降水量与蒸发量的散点分布", data1, data2, xaxis_name="降水量", yaxis_name="蒸发量",

yaxis_name_gap=40)

scatter.render('./scatter.html')

page.add(scatter)

词云图-word_cloud

word_cloud = WordCloud(width=1300, height=620)

name = ['Sam S Club', 'Macys', 'Amy Schumer', 'Jurassic World', 'Charter Communications', 'Chick Fil A',

'Planet Fitness', 'Pitch Perfect', 'Express', 'Home', 'Johnny Depp', 'Lena Dunham', 'Lewis Hamilton', 'KXAN',

'Mary Ellen Mark', 'Farrah Abraham', 'Rita Ora', 'Serena Williams', 'NCAA baseball tournament', 'Point Break']

value = [10000, 6181, 4386, 4055, 2467, 2244, 1898, 1484, 1112, 965, 847, 582, 555, 550, 462, 366, 360, 282, 273, 265]

word_cloud.add("", name, value, word_size_range=[30, 100], shape='diamond')

word_cloud.show_config()

word_cloud.render()

page.add(word_cloud)

page.render('./all-plots.html')

图表布局

from pyecharts import Grid

设置折线图标题位置

line = Line("折线图", "一年的降水量与蒸发量", title_top="45%")

line.add("降水量", columns, data1, is_label_show=True)

line.add("蒸发量", columns, data2, is_label_show=True)

grid = Grid()

设置两个图表的相对位置

grid.add(bar, grid_bottom="60%")

grid.add(line, grid_top="60%")

grid.render()

结合不同类型图表叠加

from pyecharts import Overlap

overlap = Overlap()

bar = Bar("柱状图-折线图合并", "一年的降水量与蒸发量")

bar.add("降水量", columns, data1, mark_point=["max", "min"])

bar.add("蒸发量", columns, data2, mark_point=["max", "min"])

overlap.add(bar)

overlap.add(line)

overlap.render()

pyecharts画图总结的更多相关文章

  1. pyecharts的使用及总结

    包的下载及配置 这个包的相应的配置较多,版本也不兼容,总结一下 预览:pyecharts画图 pip pyecharts pip 各级别地图(6.7个左右) pip jupyter环境 [为了生成pn ...

  2. ubuntu上pyecharts V1版本环境搭建

    1 背景 今天想用pyecharts画图,在新的环境下使用pip安装之后发现,导入pyecharts模块一直失败,报错如下. 图 1 导入pyecharts错误图 请注意:我这里使用的python版本 ...

  3. 利用pyecharts做地图数据展示

    首先, pip install pyecharts 为了地图上的数据能显示完全,加载好需要的城市地理坐标数据. pip install echarts-countries-pypkg pip inst ...

  4. django使用pyecharts(6)----django加入echarts_增量更新_定长_坐标轴定长

    六.Django 前后端分离_定时增量更新图表(坐标轴定长) 1.安装 djangorestframework linux pip3 install djangorestframework windo ...

  5. django使用pyecharts(5)----django加入echarts_增量更新_定长

    五.Django 前后端分离_定时增量更新图表定长数据 1.安装 djangorestframework linux pip3 install djangorestframework windows ...

  6. django使用pyecharts(4)----django加入echarts_增量更新

    四.Django 前后端分离_定时增量更新图表 1.安装 djangorestframework linux pip3 install djangorestframework windows pip ...

  7. django使用pyecharts(3)----django加入echarts_定时全量更新

    三.Django 前后端分离_定时全量更新图表 1.安装 djangorestframework linux pip3 install djangorestframework windows pip ...

  8. django使用pyecharts(2)----django加入echarts_前后台分离

    二.Django 中使用 pyecharts. 前后端分离 1.安装 djangorestframework linux pip3 install djangorestframework window ...

  9. 数据可视化基础专题(十五):pyecharts 基础(二)flask 框架整合

    Flask 前后端分离 Step 1: 新建一个 Flask 项目 $ mkdir pyecharts-flask-demo $ cd pyecharts-flask-demo $ mkdir tem ...

随机推荐

  1. JavaScript的DOM对象和jQuery对象的对比

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. WeihanLi.Npoi 支持 ShadowProperty 了

    WeihanLi.Npoi 支持 ShadowProperty 了 Intro 在 EF 里有个 ShadowProperty (阴影属性/影子属性)的概念,你可以通过 FluentAPI 的方式来定 ...

  3. BZOJ1014 火星人的prefix

    火星人最近研究了一种操作:求一个字串两个后缀的公共前缀.比方说,有这样一个字符串:madamimadam,我们将这个字符串的各个字符予以标号:序号: 1 2 3 4 5 6 7 8 9 10 11 字 ...

  4. Balls in the Boxes

    Description Mr. Mindless has many balls and many boxes,he wants to put all the balls into some of th ...

  5. Spring Cloud第七篇 | 声明式服务调用Feign

    本文是Spring Cloud专栏的第七篇文章,了解前六篇文章内容有助于更好的理解本文: Spring Cloud第一篇 | Spring Cloud前言及其常用组件介绍概览 Spring Cloud ...

  6. springboot+k8s+抛弃springcloud.eureka

    springboot开发微服务框架一般使用springcloud全家桶,而整个项目都是容器化的,通过k8s进行编排,而k8s自己也有服务发现机制,所以我们也可以抛弃springcloud里的eurek ...

  7. Vue中使用iconfont

    学习博客:https://www.imooc.com/article/33597?block_id=tuijian_wz

  8. struct socket结构体详解

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://weiguozhihui.blog.51cto.com/3060615/15852 ...

  9. NTFS在openwrt下的挂载问题

    在openwrt上市可以挂载ntfs分区的,但是如果原来如果搞过win,或者异常关机,那么会遇到以下的错误: root@Openwrt:/etc/config# mount -t ntfs -o rw ...

  10. hdu 2586 How far away?(LCA模板题+离线tarjan算法)

    How far away ? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...