Two, Python development --- 40, matplotlib (3)

Histogram

  Bar function can be used to draw a histogram, the histogram of the x-coordinate values ​​of the required level, and each x-coordinate value corresponding to a y-coordinate value, thereby forming a columnar FIG.

  Bar width is not a function of the width of a pixel, depending on how much the size of bar function of two-dimensional coordinate system, x-coordinate value and automatically determines the width of each column, and the width is a multiple of the width specified standard column width, the parameter value may be a float, such as 0.5, represents the width of the column is 0.5 times the standard width

  

# A histogram 
Import matplotlib.pyplot AS PLT 
X = [1997,1998,1999,2000 ] 
x_labels = [ ' 1997 ' , ' 1998 ' , ' 1999 ' , ' Year 2000 ' ] 
Y = [1000, 3000 , 4000,5000 ] 
plt.bar (X, Y, width = 0.1 ) 
plt.rcParams [ ' font.sans serif- ' ] = [ ' SimHei ' ] # for normal display Chinese label 
plt.xticks (x, x_labels)   # set the scale of the x-axis, rotation angle of the rotation
plt.xlabel ( ' year ' ) 
plt.ylabel ( ' volume ' ) 
plt.title ( ' according to FIG Comparative sales year ' ) 
plt.savefig ( ' histogram .jpg ' ) 
plt.show ()

  Using a histogram bar and barh

 

Guess you like

Origin www.cnblogs.com/lanzhijie/p/12466522.html