pyecharts画图总结
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画图总结的更多相关文章
- pyecharts的使用及总结
包的下载及配置 这个包的相应的配置较多,版本也不兼容,总结一下 预览:pyecharts画图 pip pyecharts pip 各级别地图(6.7个左右) pip jupyter环境 [为了生成pn ...
- ubuntu上pyecharts V1版本环境搭建
1 背景 今天想用pyecharts画图,在新的环境下使用pip安装之后发现,导入pyecharts模块一直失败,报错如下. 图 1 导入pyecharts错误图 请注意:我这里使用的python版本 ...
- 利用pyecharts做地图数据展示
首先, pip install pyecharts 为了地图上的数据能显示完全,加载好需要的城市地理坐标数据. pip install echarts-countries-pypkg pip inst ...
- django使用pyecharts(6)----django加入echarts_增量更新_定长_坐标轴定长
六.Django 前后端分离_定时增量更新图表(坐标轴定长) 1.安装 djangorestframework linux pip3 install djangorestframework windo ...
- django使用pyecharts(5)----django加入echarts_增量更新_定长
五.Django 前后端分离_定时增量更新图表定长数据 1.安装 djangorestframework linux pip3 install djangorestframework windows ...
- django使用pyecharts(4)----django加入echarts_增量更新
四.Django 前后端分离_定时增量更新图表 1.安装 djangorestframework linux pip3 install djangorestframework windows pip ...
- django使用pyecharts(3)----django加入echarts_定时全量更新
三.Django 前后端分离_定时全量更新图表 1.安装 djangorestframework linux pip3 install djangorestframework windows pip ...
- django使用pyecharts(2)----django加入echarts_前后台分离
二.Django 中使用 pyecharts. 前后端分离 1.安装 djangorestframework linux pip3 install djangorestframework window ...
- 数据可视化基础专题(十五):pyecharts 基础(二)flask 框架整合
Flask 前后端分离 Step 1: 新建一个 Flask 项目 $ mkdir pyecharts-flask-demo $ cd pyecharts-flask-demo $ mkdir tem ...
随机推荐
- 【nodejs原理&源码赏析(4)】深度剖析cluster模块源码与node.js多进程(上)
[摘要] 集群管理模块cluster浅析 示例代码托管在:http://www.github.com/dashnowords/blogs 一. 概述 cluster模块是node.js中用于实现和管理 ...
- 华为云备案服务全面升级,EI助力带来极速体验
华为云备案"电子化核验"正式发布,备案更轻松.更快捷.自2019年9月12日起,华为云用户申请办理ICP备案可以通过华为云APP进行"ICP备案主体真实身份信息采集&qu ...
- Python基础之第三方库gevent安装
安装gevent库: 想要安装gevent库,我们需要确定pip版本: 使用 pip3 list: 我们可以发现pip版本为19.3.1,如果你们的pip版本不是最新版可以使用命令python -m ...
- mac install: /usr/bin/unrar: Operation not permitted
按照教程mac下解压缩rar文件工具-rarosx(免费),在mac上安装rar,在执行命令 sudo install -c -o $USER unrar /bin 出现错误:install: /bi ...
- 掘金转载-手写一个Promise
目录 一 什么是Promise ? 二 Promises/A+ 规范 2.1 术语 2.2 基本要求 2.2.1. Promise的状态 2.2.2. Then 方法 2.3 简易版实践 2.4 进一 ...
- BZOJ 3033 太鼓达人(DFS+欧拉回路)
Description 七夕祭上,Vani牵着cl的手,在明亮的灯光和欢乐的气氛中愉快地穿行.这时,在前面忽然出现了一台太鼓达人机台,而在机台前坐着的是刚刚被精英队伍成员XLk.Poet_shy和ly ...
- 四点之间最短路(spfa+优先队列+枚举优化)UESTC1955喜马拉雅山上的猴子
喜马拉雅山上的猴子 Time Limit: 1000 MS Memory Limit: 256 MB Submit Status 余周周告诉我喜马拉雅山上有猴子,他们知道点石成金的方法.我不信 ...
- java发送邮件基础方法(另附部分主流邮箱服务器地址、端口及设置方法)
java发送邮件基础方法,可通过重载简化参数 import java.io.File; import java.io.UnsupportedEncodingException; import java ...
- 分布式事务解决方案,中间件 Seata 的设计原理详解
作者:张乘辉 前言 在微服务架构体系下,我们可以按照业务模块分层设计,单独部署,减轻了服务部署压力,也解耦了业务的耦合,避免了应用逐渐变成一个庞然怪物,从而可以轻松扩展,在某些服务出现故障时也不会影响 ...
- eclipse设置护眼模式,就是设置为黑色背景,
效果如上图 首先下载jar包,然后放到下面的目录,然后打开eclipse然后选择哪个dark的那个主题就可以了 然而这里只是设置软件部分的, 代码的背景和高亮显示,是在另外一个地方设置, 一般是下载e ...