python plt绘制统计图实例
发布日期:2021-05-14 21:18:20 浏览次数:37 分类:精选文章

本文共 2750 字,大约阅读时间需要 9 分钟。

������������������������������������������������������������������������������������������������

  • ������������������������

    • ���������������������������������������������������������������������������
    • ������������������with������������������������������������������������������
    import os
    from config import database_config
    db = None
    try:
    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���������������
    • ������������������������������������������������������������������������������������
  • ������������������������

    • ���������������������������������������������������������������������
    • ���������������������������������������������������������������
    • ���������������������������������������������������������������������������
  • ������������������

    • ������������������������������������������
    • ������������������������������������������������������������������������������������������
  • ������������������������������������������������������������������������������������������������������������������

    上一篇:Python prettytable美化你的输出
    下一篇:golang reflect实例

    发表评论

    最新留言

    哈哈,博客排版真的漂亮呢~
    [***.90.31.176]2025年04月28日 19时01分55秒