Python a histogram

A histogram with Python, using a bar () function.

 

A simple example:

# Create a 8 x 6 points to the window, and set a resolution of 80 pixels / inch per 
plt.figure (figsize = (10, 10), dpi = 80 )
 # then create a specification for the 1 x 1 subgraph 
# plt.subplot (1, 1, 1) 
# total number of columns
N = 10
# Comprising a sequence of values corresponding to each column 
values = (56796,42996,24872,13849,8609,5331,1971,554,169,26 )
 # comprises the target sequence in each column 
index = np.arange (N)
 # column width
width = 0.45
# A histogram, of each column violet color 
P2 = plt.bar (index, values, width, label = " NUM " , Color = " # 87CEFA " )
 # Set the horizontal axis label 
plt.xlabel ( ' Clusters ' )
 # set vertical axis labels 
plt.ylabel ( ' Number of Reviews ' )
 # add header 
plt.title ( ' the Cluster Distribution's ' )
 # Add-axis scale aspect 
plt.xticks (index, ( ' mentioned1cluster ' , ' mentioned2cluster ' , 'mentioned3cluster', 'mentioned4cluster', 'mentioned5cluster', 'mentioned6cluster', 'mentioned7cluster', 'mentioned8cluster', 'mentioned9cluster', 'mentioned10cluster'))
# plt.yticks(np.arange(0, 10000, 10))
# 添加图例
plt.legend(loc="upper right")
plt.show()

 

result:

 

【Reference】

. 1, https://blog.csdn.net/qq_41011336/article/details/83016709  (including of parameters)

Guess you like

Origin www.cnblogs.com/shenxiaolin/p/11100094.html