Matplotlib --- histogram

Coding _ * _ #: GBK _ * _ 
# @author: Wonde 
# histogram bar 

import matplotlib.pyplot as plt # drawing 
from matplotlib.font_manager import FontProperties # font management 

font = FontProperties (fname = r'STLITI.TTF ' ) # setting the path to the font settings 
plt.style.use ( 'ggplot') # style optional, and the default ggplot Classic 
# Print (plt.style.available) # can be used to view the background style 
classes = [ 'class1', ' class2 ',' class3 ',' class4 '] # x -axis data 
studentnum = [11, 21, 33 , 25] # y -axis data 
classes_index = range (len (classes) ) # pass a iterable range is a iterable , the purpose is to make digital X-axis non uniform distribution achieved by the index 
# canvas design 
fig = plt.figure () # instantiate an object 
ax1 = fig.add_subplot (1, 1, 1) # a canvas into several (1) line (1) the selected column and the first (1) Zhang add_subplot (1, 1, 1) 

AX1 of the. bar (classes_index , StudentNum ) set some parameters # 
# DEF bar (Self, X , height , width = 0.8, bottom = None, *, align = left = "Center", kwargs **): 
# Scale value display position 
ax1.xaxis. set_ticks_position ( 'bottom') # x is the scale at the bottom of the scale, y scale on the left 
ax1.yaxis.set_ticks_position ( 'left') 

# set the X-axis and the scale data, the X-axis because it is not specific data, it is located with his array position arithmetic value. plt.xticks (classes_index, classes, rotation = 0, = 12 is fontSize, FontProperties = font) 
# Set x and y axes and the name of the title bar 
plt.xlabel ( 'class', FontProperties = font, fontSize = 15) 
plt.ylabel ( 'the number of students', FontProperties = font, FONTSIZE = 15) 
plt.title ( 'number of students in class ----', FontProperties = font, FONTSIZE = 19) 
plt.show ()



 

 

 

****************************************************************************************************************************************************

 

 

Coding _ * _ #: GBK _ * _ 
# @author: Wonde 
# histogram bar 

import matplotlib.pyplot as plt # drawing 
from matplotlib.font_manager import FontProperties # font management 

font = FontProperties (fname = r'STLITI.TTF ' ) # setting the path to the font settings 
plt.style.use ( 'ggplot') # style optional, and the default ggplot Classic 
# Print (plt.style.available) # can be used to view the background style 
classes = [ 'class1', ' class2 ',' class3 ',' class4 '] # x -axis data 
studentnum = [11, 21, 33 , 25] # y -axis data 
classes_index = range (len (classes) ) # pass a iterable range is a iterable 
# canvas design 
fig = plt.figure () # instantiate an object 
ax1 = fig.add_subplot (1, 1, 1) # a canvas into several (1) OK (1) and a selected first column (1) Double add_subplot (. 1,. 1,. 1) 

AX1. Barh ( classes_index ,StudentNum ) set some parameters # 
# DEF Barh (Self, Y , width , height = 0.8, left = None, *, align = left = "Center", kwargs **): 
# Scale value display position 
ax1.xaxis.set_ticks_position ( 'bottom') # x is the scale at the bottom of the scale, the scale on the left y 
ax1.yaxis.set_ticks_position ( 'left') 

# yticks scale value data and the y-axis, Y-axis at this time is the class, not a specific value, so it is necessary to do with the average interval index. plt.yticks (classes_index, classes, rotation = 0, fontSize = 12, FontProperties = font) 
# set the x and y axes and title bar name 
plt.xlabel ( 'the number of students', FontProperties = font, FONTSIZE = 15) 
plt. ylabel ( 'class', FontProperties = font, FONTSIZE = 15) 
plt.title ( 'number of students in class ----', FontProperties = font, FONTSIZE = 19) 
plt.show ()



  

 

 

  Focusing on understanding! ! !

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/csic716/p/11939320.html