"" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "", "" "". "" "" "" "" "" "" "" "," "" "" "," "" "" "," "" "," "" ">> Double histogram .py>> Author: Liu Yang>> e-mail: [email protected]>> blog: Www.cnblogs.com/liu66blog "" " "" "" "" "" "" "" "" "" "" "" "" "" "" "" "." "" "" "" "" "" "" "" "" "" "" "" "" #!/usr/bin/env python#-*-. " Coding:utf-8-*-import Matplotlibimport Matplotlib.pyplot as plt# specifies the font to prevent font=matplotlib.font_manager. Fontproperties (fname=r "C:\Windows\Fonts\Deng.ttf") # double histogram Def barsplot (): # Mr. # into a canvas fig=plt.figure () # Generate Data x1= [x-0.2 for X in range (1,9)] y1=[n*2 for n in range (1,9) "x2=[x+0.2 for x in range (1,9)] y2=[x**2 for x in X2] # Start Drawing bar Figure 1 L1=plt.bar (x1,y1,color= ' G ', width=0.4) # start to draw bar graph 2 L2=plt.bar (x2,y2,color= ' B ', width=0.4) # Show picture of the drawing plt . Xlabel (' x axis information ', Fontproperties=font) plt.ylabel (' Y axis info ', Fontproperties=font) plt.title (' Double histogram ', Fontproperties=font ) Plt.legend (handles = [L1, L2,], labels = [' Last year ', ' this year '], loc = ' best ', prop=font) for x1,x2, Y1, y2 in zip (x1,x2, y1, y2): Plt.text (x1, y1, '%.0f '% y1, ha= ' center ', va= ' bottom ') Plt.text (x2, y2, '%.0f '% y2, ha= ' center ', va= ' bottom ') plt.show () # If the most main module runs if __name__ = = ' __main__ ': # Instantiate BA =barsplot ()
[Python Study Notes] Double-layered histogram drawing