How to draw grouping and comparing histogram by python
Today, I would like to share with you the relevant knowledge points about how to draw grouped comparison bar charts by python. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.
First of all, show the effect picture:
#-*-coding: utf-8-*-import numpy as np import tensorflow as tffrom matplotlib.path import Pathfrom matplotlib.patches import PathPatchimport matplotlib.pyplot as pltimport matplotlibfrom matplotlib.animation import FuncAnimationimport matplotlib as mplimport datetimeimport timeimport reimport urllib.requestnp.set_printoptions (suppress=True) mpl.rcParams ['font.sans-serif'] = [' SimHei'] # specifies that the default font SimHei is boldface mpl.rcParams ['axes.unicode_minus'] = False # to display negative import requestsimport reimport hashlib # test data normally Osm point line surface data # test host 8G 4 core 1T mechanical disk # mysql 5.7.23#postgresql 12#dameng 7#oracle 19c 19.3 # read efficiency point line surface r = [24714 21748, 19298], # Oracle [44127, 45943, 42199], # GDB # [0, 0, 0], # SQLITE # [0, 0, 0], # MySQL [352641, 352739, 304189], # SQLITE [213550, 218095 212749], # MySQL [36556, 22172, 12741], # PostgreSQL [52749, 46292, 20040], # dameng [25111, 12000, 11000], # ArcGIS_GDB [10102, 9003 7003] # ArcGIS_ORACLE] # write efficiency w = [190,675,40], # Oracle [15815, 9820, 11892], # GDB [94547, 81847, 57235], # SQLITE # [0,0,0] # SQLITE [502, 662, 403], # MySQL # [0, 0, 0], # MySQL [1631, 1599, 1502], # PostgreSQL [2004, 1849, 1524], # dameng [10111, 8000, 5600] # ArcGIS_GDB [1100, 1000] # ArcGIS_ORACLE] # this is the bar chart x-axis label ysr = ['Oracle','GDB','SQLITE','MySQL','PostgreSQL','DAMENG','ArcGIS_GDB','ArcGIS_ORACLE'] def DrawGeoDtaabse (rcount, wcount, y): # the first row, the first column figure 2 represents 2 rows and 1 column ax1 = plt.subplot 1) # second row, first column graphics ax3 = plt.subplot (2 ax1 1) # default time format plt.sca (ax1) plt.xlabel ("", color ='r') # X axis label plt.ylabel ("bar / s") Color ='r') # Y axis label # plt.grid (True) display grid # plt.gcf (). Autofmt_xdate () display time plt.legend () # display legend plt.title ("[read] efficiency") # title x1 = [1P5 # X axis efficiency position x2 = [I + 1 for i in x1] # x axis efficiency position x3 = [I + 2 for i in x1] # x axis efficiency position y1 = [I [0] for i in rcount] # y axis point efficiency position y2 = [I [1] for i in rcount] # y axis efficiency location y3 = [I [2] for i in rcount] # y Axis efficiency position # occupies space to avoid loss of data source label y0 = ["" ",", "] plt.bar (x1, y1, alpha=0.7, width=1, color='r',label=" point, tick_label=y0) plt.bar (x3, y3, alpha=0.7, width=1, color='b',label= "face", tick_label=y0) plt.bar (x2, y2, alpha=0.7, width=1, color='g',label= "line", tick_label=y) # so far the reading efficiency of the first line has been drawn Repeat the write efficiency of the second line plt.sca (ax3) plt.xlabel ("data source", color ='r') # X axis label plt.ylabel ("bar / s") Color ='r') # Y axis label # plt.grid (True) plt.legend () # display legend plt.title ("[write] efficiency") # figure title y1 = [I [0] for i in wcount] y2 = [I [1] for i in wcount] y3 = [I [2] for i in wcount] y0 = ["" "] plt.bar (x1, y1, alpha=0.7, width=0.6, color='r',label=" point ", tick_label=y0) plt.bar (x3, y3, alpha=0.7, width=0.6, color='b',label=" face ", tick_label=y0) plt.bar (x2, y2, alpha=0.7, width=0.6, color='g',label=" line ", tick_label=y) plt.legend () plt.show () DrawGeoDtaabse (RMagnew Ysr) these are all the contents of the article "how to draw a grouped comparison histogram by python" Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.