"" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "", "" "". "" "" "" "" "" "" "" "," "" "" "," "" "" "," "" "," "" ">> Stacked Histogram .py>> Author: Liu Yang>> e-mail: [email protected]>> blog: Www.cnblogs.com/liu66blog "" " "" "" "" "" "" "" "" "" "" "" "" "" "" "" "." "" "" "" "" "" "" "" "" "" "" "" "" #!/usr/bin/env python#-*-. " Coding:utf-8-*-import Matplotlib.pyplot as Pltimport matplotlib# defines the font to use to prevent Chinese garbled font=matplotlib.font_manager. Fontproperties (fname=r "C:\Windows\Fonts\Deng.ttf") # double histogram, upper and lower structure applies to one histogram all above another set of Def Barsplot (): Mr. # into a canvas fig=plt.fig Ure () # Generate data x1=[x for X in range (1,9)] y1=[n*2 for n in range (1,9)] x2=[x for x in range (1,9)] y2=[x**2 fo R x in X2] # start Drawing bar Chart 2, first draw a large number, the value is small directly in the original image overlay L2=plt.bar (x2,y2,color= ' B ', width=0.4) # Start Drawing bar 1 L1=plt.bar (x1,y1,color = ' g ', width=0.4) # set X label Plt.xlabel (U ' x axis ', fontproperties=font) # set y-axis label plt.ylabel (' Y axis ', fontproperties=font) # Set Caption Plt.title (U ' stacked histogram ', Fontproperties=font) # Set the note Mania Plt.legend (handles = [L1, L2,], labels = [' Last year ', ' this year '], loc = ' best ', Prop=font) # show the exact numbers for x1,x2, y1, y2 in Zi P (x1,x2, Y1, y2): Plt.text (x1, y1, '%.0f '% y1, ha= ' center ', va= ' bottom ') plt.text (x2, y2, '%.0f '% y2, ha = ' Center ', va= ' Bottom ') # show Plt.show () # If the most main module runs if __name__ = = ' __main__ ': # Instantiate Ba=barsplot ()
[Python Study Notes] stacked histogram drawing