当前位置:网站首页>03 pyechars 直角坐标系图表(示例代码+效果图)
03 pyechars 直角坐标系图表(示例代码+效果图)
2022-07-28 11:42:00 【懒笑翻】
目录
1.Bar柱状图/条形图
# 柱状图/条形图
from pyecharts.charts import Bar
x_data = ["语文", "数学", "英语", "生物", "物理", "化学"] # x轴数据 数据必须是字符串
y_data = [114, 95, 107, 81, 85, 87] # y轴数据 数据必须是整数或者小数
bar = Bar() # 初始化图表
bar.add_xaxis(x_data) # x轴
bar.add_yaxis('成绩', y_data) # y轴
bar.render("bar.html") # 渲染html文件
2 Line折线图
# 折线图
from pyecharts.charts import Line
x_data = ['1月', '2月', '3月', '4月', '5月', '6月'] # x轴数据 数据必须是字符串
y_data = [1123, 1153, 1089, 1207, 1298, 1123] # y轴数据 数据必须是整数或者小数
line = Line() # 初始化图表
line.add_xaxis(x_data) # x轴
line.add_yaxis('月消费', y_data) # y轴
line.render("line.html") # 渲染html文件
3 Scatter散点图
# 散点图
from pyecharts.charts import Scatter
x_data = ['1月', '2月', '3月', '4月', '5月', '6月'] # x轴数据
y_data = [1123, 1153, 1089, 1207, 1298, 1123] # y轴数据
scatter = Scatter() # 初始化图表
scatter.add_xaxis(x_data) # x轴
scatter.add_yaxis('月消费', y_data) # y轴
scatter.render("scatter.html") # 渲染html文件
4 EffectScatter涟漪特效散点图
from pyecharts.charts import EffectScatter
x_data = ['1月', '2月', '3月', '4月', '5月', '6月'] # x轴数据
y_data = [1123, 1153, 1089, 1207, 1298, 1123] # y轴数据
effectScatter = EffectScatter()
effectScatter.add_xaxis(x_data) # x轴
effectScatter.add_yaxis('月消费', y_data) # y轴
effectScatter.render("effectScatter.html") # 渲染html文件
5 Boxplot箱型图
# 箱型图
from pyecharts.charts import Boxplot
import random
x_data = ['A', 'B', 'C', 'D', 'E', 'F']
y_data = [[random.randint(100, 200) for i in range(10)] for item in x_data] #[[164, 102, 161, 106, 144, 186, 197, 186, 196, 125], [158, 131, 143, 111, 110, 175, 109, 107, 104, 153], [163, 174, 182, 142, 134, 158, 113, 149, 176, 183], [198, 142, 182, 125, 105, 149, 171, 122, 105, 156], [146, 126, 100, 164, 149, 117, 118, 170, 138, 155], [177, 110, 119, 178, 126, 164, 131, 176, 195, 134]]
print(y_data)
Boxplot = Boxplot()
Boxplot.add_xaxis(x_data) # x轴
Boxplot.add_yaxis('', Boxplot.prepare_data(y_data)) # y轴
Boxplot.render("Boxplot.html") # 渲染html文件
6 Kline k线图
# k线图
from pyecharts.charts import Kline
date_list = ["2022/6/{}".format(i + 1) for i in range(30)]
y_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],
]
kline = (Kline()
.add_xaxis(date_list)
.add_yaxis('', y_data)
)
kline.render("kline.html") # 渲染html文件
7 HeatMap热力图
# 热力图
from pyecharts.charts import HeatMap
import random
data = [[i, j, random.randint(0, 100)] for i in range(24) for j in range(7)]
hour_list = [str(i) for i in range(24)]
week_list = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
heat = (HeatMap()
.add_xaxis(hour_list)
.add_yaxis("", week_list, data)
)
heat.render("heat.html")
8 PictorialBar象型柱状图
# 象型图
from pyecharts.charts import PictorialBar
x_data = ['1月', '2月', '3月', '4月', '5月', '6月'] # x轴数据
y_data = [1123, 1153, 1089, 1207, 1298, 1123] # y轴数据
pictorialBar = PictorialBar() # 初始化图表
pictorialBar.add_xaxis(x_data) # x轴
pictorialBar.add_yaxis('月消费', y_data) # y轴
pictorialBar.render("pictorialBar .html") # 渲染html文件
9 overlap层叠图
9.1 Overlap_bar_line
# 层叠图Overlap_bar_line
from pyecharts.charts import Bar
from pyecharts.charts import Line
x_data = ['1月', '2月', '3月', '4月', '5月', '6月']
y_data_bar = [1123, 1153, 1089, 1207, 1298, 1123]
y_data_line = [1300, 1200, 1100, 1400, 1500, 1200]
bar = (Bar()
.add_xaxis(x_data)
.add_yaxis('', y_data_bar)
)
line = (Line()
.add_xaxis(x_data)
.add_yaxis('', y_data_line)
)
overlap = bar.overlap(line)
overlap.render("overlap_bar_line .html")
9.2 Overlap_line_scatter
# 层叠图 Overlap_line_scatter
from pyecharts import options as opts
from pyecharts.charts import Line, Scatter
from pyecharts.faker import Faker
x = Faker.choose()
line = (
Line()
.add_xaxis(x)
.add_yaxis("商家A", Faker.values())
.add_yaxis("商家B", Faker.values())
.set_global_opts(title_opts=opts.TitleOpts(title="Overlap-line+scatter"))
)
scatter = (
Scatter()
.add_xaxis(x)
.add_yaxis("商家A", Faker.values())
.add_yaxis("商家B", Faker.values())
)
line.overlap(scatter)
line.render("overlap_line_scatter.html")
Faker.values() 详解:生成7个随机整数,这7个随机整数一般是两位数和三位数的组合
Faker中函数的介绍:
class _Faker:
clothes = ["衬衫", "毛衣", "领带", "裤子", "风衣", "高跟鞋", "袜子"]
drinks = ["可乐", "雪碧", "橙汁", "绿茶", "奶茶", "百威", "青岛"]
phones = ["小米", "三星", "华为", "苹果", "魅族", "VIVO", "OPPO"]
fruits = ["草莓", "芒果", "葡萄", "雪梨", "西瓜", "柠檬", "车厘子"]
animal = ["河马", "蟒蛇", "老虎", "大象", "兔子", "熊猫", "狮子"]
cars = ["宝马", "法拉利", "奔驰", "奥迪", "大众", "丰田", "特斯拉"]
dogs = ["哈士奇", "萨摩耶", "泰迪", "金毛", "牧羊犬", "吉娃娃", "柯基"]
week = ["周一", "周二", "周三", "周四", "周五", "周六", "周日"]
week_en = "Saturday Friday Thursday Wednesday Tuesday Monday Sunday".split()
clock = (
"12a 1a 2a 3a 4a 5a 6a 7a 8a 9a 10a 11a 12p "
"1p 2p 3p 4p 5p 6p 7p 8p 9p 10p 11p".split()
)
visual_color = [
"#313695",
"#4575b4",
"#74add1",
"#abd9e9",
"#e0f3f8",
"#ffffbf",
"#fee090",
"#fdae61",
"#f46d43",
"#d73027",
"#a50026",
]
months = ["{}月".format(i) for i in range(1, 13)]
provinces = ["广东", "北京", "上海", "江西", "湖南", "浙江", "江苏"]
guangdong_city = ["汕头市", "汕尾市", "揭阳市", "阳江市", "肇庆市", "广州市", "惠州市"]
country = [
"China",
"Canada",
"Brazil",
"Russia",
"United States",
"Africa",
"Germany",
]
days_attrs = ["{}天".format(i) for i in range(30)]
days_values = [random.randint(1, 30) for _ in range(30)]
边栏推荐
- [try to hack] intranet Foundation
- C for循环内定义int i变量出现的重定义问题
- SuperMap arsurvey license module division
- Developing NES game (cc65) 07 and controller with C language
- Anhui Jingzhun: Beidou satellite synchronous clock | Beidou synchronous clock | NTP network clock server
- 30 years of open source community | 2022 open atom global open source summit 30 years of special activities of open source community were successfully held
- 微创电生理通过注册:年营收1.9亿 微创批量生产上市企业
- OpenAtom OpenHarmony分论坛圆满举办,生态与产业发展迈向新征程
- Fastjson parses multi-level JSON strings
- Multi Chain and multi currency wallet system development cross chain technology
猜你喜欢

Tencent two sides: @bean and @component are used in the same class, what will happen?

新零售电商O2O模式解析

Open source huizhichuang future | 2022 open atom global open source summit openatom openeuler sub forum was successfully held

MarkDown简明语法手册

VS1003调试例程

OpenAtom OpenHarmony分论坛圆满举办,生态与产业发展迈向新征程

金山云冲刺港股拟双重主要上市:年营收90亿 为雷军力挺项目

leetcode:704二分查找

开源社区三十年 | 2022 开放原子全球开源峰会开源社区三十年专题活动圆满召开

Redis实现分布式锁
随机推荐
卸载 Navicat:正版 MySQL 官方客户端,真香!
Multi Chain and multi currency wallet system development cross chain technology
Tik tok "founder" Yang Luyu, farewell byte?
用C语言开发NES游戏(CC65)07、控制器(和精灵碰撞)
【一知半解】零值拷贝
用C语言开发NES游戏(CC65)04、完整的背景
[half understood] zero value copy
用C语言开发NES游戏(CC65)11、Metatiles
leetcode:数组
How to build knowledge management system in enterprises and institutions
The openatom openharmony sub forum was successfully held, and ecological and industrial development entered a new journey
设计一个线程池
【vulnhub】Raven2
[try to hack] UDF raises rights
Redis implements distributed locks
Solve the PHP prompt warning: division by zero in error
用arduino开发ESP8266 搭建开发环境
AVL tree (balanced search tree)
Is it overtime to be on duty? Take up legal weapons to protect your legitimate rights and interests. It's time to rectify the working environment
Aopmai biological has passed the registration: the half year revenue is 147million, and Guoshou Chengda and Dachen are shareholders