[Python Study Notes] Stacked histogram drawing

Source: Internet
Author: User


"" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "", "" "". "" "" "" "" "" "" "" "," "" "" "," "" "" "," "" "," "" ">> 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.