Python basic Tutorial Project two frame good painting

Source: Internet
Author: User
This article is mainly for you to introduce the Basic Python Tutorial Project Two, a good picture, with a certain reference value, interested in small partners can refer to

This is the second item in the basic Python tutorial, about Python operations pdf.

The knowledge points involved

1, the use of urllib

2, the use of Reportlab library

This is a very simple example, but I found that in Python you can write a for loop directly in the array [], which is more convenient.

Here's the code:

From urllib import urlopenfrom reportlab.graphics.shapes import *from reportlab.graphics.charts.lineplots Import Lineplotfrom reportlab.graphics.charts.textlabels Import labelfrom reportlab.graphics Import renderpdfurl = '/http/ Www.swpc.noaa.gov/ftpdir/weekly/Predict.txt ' Comment_chars = ' #: ' drawing = drawing (+) data = []for line in Urlopen ( URL). ReadLines (): If not line.isspace () and not line[0] in COMMENT_CHARS:data.append ([Float (n) for N in Line.split ()]) PR ed = [Row[2] for row in Data]high = [row[3] for row in data]low = [row[4] for row in data]times = [row[0] + row[1]/12.0 fo R row in DATA]LP = LinePlot () lp.x = 50LP.Y = 50lp.height = 125lp.width = 300lp.data = [Zip (times, pred), Zip (times,high), Zi P (Times, low)]lp.lines[0].strokecolor = Colors.bluelp.lines[1].strokecolor = Colors.redlp.lines[2].strokecolor = COLORS.GREENDRAWING.ADD (LP) Drawing.add (String (250,150, ' sunspots ', fontsize=14,fillcolor=colors.red)) Renderpdf.drawtofile (drawing, ' report3.pdf ', ' sunspots ')

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.