码迷,mamicode.com
首页 > Web开发 > 详细

urllib获取太阳黑子图表程序

时间:2018-12-23 15:31:10      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:and   utf-8   color   port   []   from   图表   urlopen   zha   

技术分享图片
 1 # -*- coding:utf-8 -*-
 2 # Author:Vincent Zhang
 3 
 4 from urllib.request import urlopen
 5 from reportlab.graphics.shapes import *
 6 from reportlab.graphics.charts.lineplots import LinePlot
 7 from reportlab.graphics.charts.textlabels import Label
 8 from reportlab.graphics import renderPDF
 9 
10 URL = ftp://ftp.swpc.noaa.gov/pub/weekly/Predict.txt
11 COMMENT_CHARS = #:
12 drawing = Drawing(400, 200)
13 data = []
14 for line in urlopen(URL).readlines():
15     line = line.decode()
16     if not line.isspace() and line[0] not in COMMENT_CHARS:
17         data.append([float(n) for n in line.split()])
18 pred = [row[2] for row in data]
19 high = [row[3] for row in data]
20 low = [row[4] for row in data]
21 times = [row[0] + row[1] / 12.0 for row in data]
22 lp = LinePlot()
23 lp.x = 50
24 lp.y = 50
25 lp.height = 125
26 lp.width = 300
27 lp.data = [list(zip(times, pred)),
28            list(zip(times, high)),
29            list(zip(times, low))]
30 lp.lines[0].strokeColor = colors.blue
31 lp.lines[1].strokeColor = colors.red
32 lp.lines[2].strokeColor = colors.green
33 drawing.add(lp)
34 drawing.add(String(250, 150, Sunspots,
35                    fontSize=14, fillColor=colors.red))
36 renderPDF.drawToFile(drawing, report2.pdf, Sunspots)
View Code

 

urllib获取太阳黑子图表程序

标签:and   utf-8   color   port   []   from   图表   urlopen   zha   

原文地址:https://www.cnblogs.com/zijue/p/10164027.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!