当前位置:网站首页>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)]
边栏推荐
- Unity 安装 Device Simulator
- C for循环内定义int i变量出现的重定义问题
- Not optimistic about Apple making AR, Luo Yonghao: I'll do it myself
- Developing NES games with C language (cc65) 06. Sprites
- Some API interfaces purchased by Yiwu hope to bring you some help
- Four authentic postures after suffering and trauma, Zizek
- Developing NES games with C language (cc65) 04. Complete background
- PHP ⽉ the simplest way to add and subtract ⽅
- New progress in the implementation of the industry | the openatom openharmony sub forum of the 2022 open atom global open source summit was successfully held
- 公司在什么情况下可以开除员工
猜你喜欢

一台电脑上 多个项目公用一个 公私钥对拉取gerrit服务器代码

MySQL之知识点(十三)

Zadig v1.13.0 believes in the power of openness, and workflow connects all values

Come to tdengine Developer Conference and have an insight into the future trend of data technology development

Brief discussion on open source OS distribution

Yan Ji lost Beijing again, and more than half of the stores in the country were closed

Kafaka丢消息吗

Localization, low latency, green and low carbon: Alibaba cloud officially launched Fuzhou data center

HC-05蓝牙模块调试从模式和主模式经历

金九银十 再不卷就来不及了
随机推荐
Basic use of JSON server
With the continuous waves of infringement, the U.S. patent and trademark office began to study the impact of NFT on copyright
Functions and pointers in 08 go language
Laravel $object->updated_ At returns the carbon object. How to return the normal time format
新零售电商O2O模式解析
Uninstall Navicat: genuine MySQL official client, really fragrant!
Developing NES games (cc65) 05 and palette with C language
界面控件Telerik UI for WPF - 如何使用RadSpreadsheet记录或评论
Most of the interfaces of Tiktok are already available, and more interfaces are still open. Please look forward to it
【萌新解题】爬楼梯
Analysys analysis: focus on users, improve the user experience of mobile banking, and help the growth of user value
leetcode:数组
Deployment之滚动更新策略。
C for循环内定义int i变量出现的重定义问题
1331. Array sequence number conversion: simple simulation question
开源社区三十年 | 2022 开放原子全球开源峰会开源社区三十年专题活动圆满召开
Implementation method of mouse hover, click and double click in ue4/5
新东方单季营收5.24亿美元同比降56.8% 学习中心减少925间
Unity 安装 Device Simulator
让arduino支持nuvotom新唐