Python read the CSV format document and use Matplotlib to draw the chart

Source: Internet
Author: User

  • import csvfrom matplotlib import pyplot as pltfrom datetime import Datetimefilename = ' sitka_weather_07-2014.csv ' with open (fileName) as F:reader = Csv.reader (f) header_row = Next (rea    Der) # Print (header_row) # for index, Column_header in Enumerate (header_row): # When you need both index and value values, you can use enumerate # # Print (index, column_header) dates,hights = [], [] for row in reader:current_date = Datetime.strpt IME (row[0], '%y-%m-%d ') dates.append (current_date) hights.append (int (row[1))) print (hights) FIG = plt. Figure (dpi=128, figsize= (6)) Plt.plot (dates, hights, c= ' Red ') # Sets the format of the graphic Plt.title ("Dialy High Temperatures,ju     Ly ", fontsize=24) Plt.xlabel (", fontsize=16) Fig.autofmt_xdate () Plt.ylabel ("Temperature (F)", fontsize=16) Plt.tick_params (axis= ' both ', which= ' major ', labelsize=16) plt.savefig ("Temperature.png", bbox_inches= ' tight ') pl T.show () 

    Run result

  • Temperature.png

Python read the CSV format document and use Matplotlib to draw the chart

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.