[Python Study Notes] Double-decker histogram drawing

Source: Internet
Author: User


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

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.