Python: Drawing a chart using Matplotlib's Pyplot

Source: Internet
Author: User

Work needs to observe the trend of data changes, with Python to write a small program to display simple charts, to share the convenience of people with the same needs, matplotlib is a very good library.

#!encode=utf8 fromMatplotlibImportPyplot as PltImportSysignore_num= (int) (sys.argv[1]) Data=sys.argv[2]show_type=0ifLen (SYS.ARGV) >3: Show_type= (int) (sys.argv[3]) x=[]valid_ppl=[]train_ll=[]valid_ll=[]fi=open (data,"R") Line=Fi.readline () n=0 whileLine :ifLine.find ("Values") >=0:arr=line.split (" ")N+=1ifN>ignore_num:x.append (n) train_ll.append (arr[6]) valid_ll.append (arr[8]) valid_ppl.append (arr[9]) line=Fi.readline ()ifshow_type==0:plt.plot (X,train_ll,color="Blue", label="Train_ll") Plt.plot (X,valid_ll,color="Red", label="Valid_ll") Plt.plot (X,valid_ppl,color="Orange", label="VALID_PPL")elifShow_type==1: Plt.plot (X,train_ll,color="Blue", label="Train_ll") Plt.plot (X,valid_ll,color="Red", label="Valid_ll")Else: Plt.plot (X,valid_ppl,color="Orange", label="VALID_PPL") plt.legend (Loc='Upper Right') plt.show ()

To run a program using the CMD command window

Operation Result:

Reference: http://www.scipy-lectures.org/intro/matplotlib/matplotlib.html This page has written the detailed usage of pyplot, and how to draw a richer graph with Python, is a very good learning material.

Python: Drawing a chart using Matplotlib's Pyplot

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.