当前位置:   article > 正文

python 绘制分组对比柱状图

python 绘制分组对比柱状图

首先放效果图:

  1. # -*- coding: utf-8 -*-
  2. import numpy as np
  3. import tensorflow as tf
  4. from matplotlib.path import Path
  5. from matplotlib.patches import PathPatch
  6. import matplotlib.pyplot as plt
  7. import matplotlib
  8. from matplotlib.animation import FuncAnimation
  9. import matplotlib as mpl
  10. import datetime
  11. import time
  12. import re
  13. import urllib.request
  14. np.set_printoptions(suppress=True)
  15. mpl.rcParams['font.sans-serif'] = ['SimHei'] #指定默认字体 SimHei为黑体
  16. mpl.rcParams['axes.unicode_minus'] = False #用来正常显示负
  17. import requests
  18. import re
  19. import hashlib
  20. #测试数据 osm的点线面数据
  21. #测试主机 8G 4核 1T机械盘
  22. #mysql 5.7.23
  23. #postgresql 12
  24. #dameng 7
  25. #oracle 19c 19.3
  26. #读取效率 点 线 面
  27. r = [ [24714, 21748, 19298], #Oracle
  28. [44127, 45943, 42199], #GDB
  29. #[0, 0, 0], #SQLITE
  30. # [0, 0, 0], #MySQL
  31. [352641, 352739, 304189], #SQLITE
  32. [213550, 218095, 212749], #MySQL
  33. [36556, 22172, 12741], #PostgreSQL
  34. [52749, 46292, 20040], #dameng
  35. [25111, 12000, 11000], #ArcGIS_GDB
  36. [10102, 9003, 7003] #ArcGIS_ORACLE
  37. ]
  38. #写入效率
  39. w = [ [190, 675, 40], #Oracle
  40. [15815, 9820, 11892], #GDB
  41. [94547, 81847, 57235], #SQLITE
  42. # [0, 0, 0], #SQLITE
  43. [502, 662, 403], #MySQL
  44. #[0, 0, 0], #MySQL
  45. [1631, 1599, 1502], #PostgreSQL
  46. [2004, 1849, 1524], #dameng
  47. [10111, 8000, 5600] , #ArcGIS_GDB
  48. [1100, 1000, 900] #ArcGIS_ORACLE
  49. ]
  50. #这是柱图x轴标签
  51. ysr = ['Oracle','GDB','SQLITE','MySQL','PostgreSQL','DAMENG','ArcGIS_GDB','ArcGIS_ORACLE']
  52. def DrawGeoDtaabse(rcount, wcount, y):
  53. #第一行 第一列图形 2,1 代表2行1列
  54. ax1 = plt.subplot(2,1,1)
  55. #第二行 第一列图形
  56. ax3 = plt.subplot(2,1,2)
  57. #默认时间格式
  58. plt.sca(ax1)
  59. plt.xlabel("",color = 'r') #X轴标签
  60. plt.ylabel("条/s",color = 'r') #Y轴标签
  61. #plt.grid(True) 显示格网
  62. #plt.gcf().autofmt_xdate() 显示时间
  63. plt.legend() # 显示图例
  64. plt.title("[读取]效率") #标题
  65. x1 = [1,5,9,13,17,21,25,29] # x轴点效率位置
  66. x2 = [i + 1 for i in x1] # x轴线效率位置
  67. x3 = [i + 2 for i in x1] # x轴面效率位置
  68. y1 = [i[0] for i in rcount] # y轴点效率位置
  69. y2 = [i[1] for i in rcount] # y轴线效率位置
  70. y3 = [i[2] for i in rcount] # y轴面效率位置
  71. #占位以免 数据源标签丢失
  72. y0 = ["","","","","","","",""]
  73. plt.bar(x1, y1, alpha=0.7, width=1, color='r',label="点", tick_label=y0)
  74. plt.bar(x3, y3, alpha=0.7, width=1, color='b',label="面", tick_label=y0)
  75. plt.bar(x2, y2, alpha=0.7, width=1, color='g',label="线", tick_label=y)
  76. #至此第一行的读取效率绘制完毕,再重复一下第二行的写效率
  77. plt.sca(ax3)
  78. plt.xlabel("数据源",color = 'r') #X轴标签
  79. plt.ylabel("条/s",color = 'r') #Y轴标签
  80. #plt.grid(True)
  81. plt.legend() # 显示图例
  82. plt.title("[写入]效率") #图标题
  83. y1 = [i[0] for i in wcount]
  84. y2 = [i[1] for i in wcount]
  85. y3 = [i[2] for i in wcount]
  86. y0 = ["","","","","","","",""]
  87. plt.bar(x1, y1, alpha=0.7, width=0.6, color='r',label="点", tick_label=y0)
  88. plt.bar(x3, y3, alpha=0.7, width=0.6, color='b',label="面", tick_label=y0)
  89. plt.bar(x2, y2, alpha=0.7, width=0.6, color='g',label="线", tick_label=y)
  90. plt.legend()
  91. plt.show()
  92. DrawGeoDtaabse(r,w,ysr)

以上所有代码在python3.6.4上运行测试成功

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/681776
推荐阅读
相关标签
  

闽ICP备14008679号