
python plt绘制统计图实例
发布日期:2021-05-14 21:18:20
浏览次数:37
分类:精选文章
本文共 2750 字,大约阅读时间需要 9 分钟。
������������������������������������������������������������������������������������������������
������������������������
- ���������������������������������������������������������������������������
- ������������������
with
������������������������������������������������������
import osfrom config import database_configdb = Nonetry: db = MySQLdb.connect(**database_config) cursor = db.cursor()except Exception as e: print(f'������������������������{e}') exit()
���������������������
-
getcurrentversion
���������def getcurrentversion(): global version_data query = "SELECT current_ota_version FROM aiot_analysis.device_runtime WHERE model=30100" cursor.execute(query) results = cursor.fetchall() temp_dict = {} for result in results: version = str(result[0]).strip().rstrip('"') temp_dict[version] = temp_dict.get(version, 0) + 1 version_data = sorted(temp_dict.items(), key=lambda x: x[0], reverse=True) return version_data
-
Showfig
���������def Showfig(version_data): global save_path data_list = [] count_list = [] for item in version_data: version = item[0] count = item[1] if not version: version = "null" data_list.append(version) count_list.append(count) fig = plt.figure(figsize=(10, 6)) ax = fig.add_subplot(111) bar_width = 0.6 max_count = max(count_list) if count_list else 0 bar heights = [(count / max_count if max_count else 0) * 100 for count in count_list] bar = ax.bar(data_list, bar_heights, bar_width, ) for i, (version, count) in enumerate(zip(data_list, bar_heights)): ax.text(i + bar_width/2, count + 0.1, f'{int(count)}%', ha='center', va='bottom', color='black', fontsize=10) fig.autofmt_xdate() plt.legend locus='upper right' plt.savefig(save_path + 'version_count.png', dpi=300) plt.close() ```
������������������������������
- ������
try-except
������������������������������������������������ with
���������������������������������������������������������
������������������
- ���������������������������������
model=30100
��������������� - ������������������������������������������������������������������������������������
������������������������
- ���������������������������������������������������������������������
- ���������������������������������������������������������������
- ���������������������������������������������������������������������������
������������������
- ������������������������������������������
- ������������������������������������������������������������������������������������������
������������������������������������������������������������������������������������������������������������������
发表评论
最新留言
哈哈,博客排版真的漂亮呢~
[***.90.31.176]2025年04月28日 19时01分55秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
推荐几篇近期必看的视觉综述,含GAN、Transformer、人脸超分辨、遥感等
2021-05-12
BUU-MISC-认真你就输了
2021-05-12
BUU-MISC-caesar
2021-05-12
【专题2:电子工程师 之 上位机】 之 【36.事件重载】
2021-05-12
【专题3:电子工程师 之 上位机】 之 【46.QT音频接口】
2021-05-12
一文理解设计模式--命令模式(Command)
2021-05-12
VTK:可视化之RandomProbe
2021-05-12
block多队列分析 - 2. block多队列的初始化
2021-05-12
Java时间
2021-05-12
不编译只打包system或者vendor image命令
2021-05-12
The wxWindows Library Licence (WXwindows)
2021-05-12
leetcode——第203题——虚拟头结点
2021-05-12
【编程】C语言入门:1到 100 的所有整数中出现多少个数字9
2021-05-12
MySQL----基础及常用命令
2021-05-12
flink启动(二)
2021-05-12
前端开发进阶手册.pdf
2021-05-12
软件架构设计和MESH经验之谈
2021-05-12
关于宝塔面板安装的mysql用Navicat连接出现2003的错误解决
2021-05-12
Windows2016 FTP用户隔离
2021-05-12