Python基础教程实践2,画幅好画(win7,64位系统)
一、下载reportlab下载地址http://www.reportlab.com/ftp/下载reportlab-2.5.win32-py2.7.exe二、获取数据源由于宿舍没有网络,只能能先下载好txt,然后放到虚拟机linux,里面的apache服务器里面,以此来实现。下载地址http://www.swpc.noaa.gov/ftpdir/weekly/Predi
·
一、下载reportlab
- 下载地址http://www.reportlab.com/ftp/
- 下载reportlab-2.5.win32-py2.7.exe
二、获取数据源
由于宿舍没有网络,只能能先下载好txt,然后放到虚拟机linux,里面的apache服务器里面,以此来实现。下载地址http://www.swpc.noaa.gov/ftpdir/weekly/Predict.txt
三、代码
Sunspots_roto.py
from urllib import urlopen
from reportlab.graphics.shapes import *
from reportlab.graphics.charts.lineplots import LinePlot
from reportlab.graphics.charts.textlabels import Label
from reportlab.graphics import renderPDF
URL='http://192.168.177.128/Predict.txt'
COMMENT_CHAR ='#:'
drawing = Drawing(400,200)
data = []
for line in urlopen(URL).readlines():
if not line.isspace() and not line[0] in COMMENT_CHAR:
data.append([float(n) for n in line.split()])
pred = [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 for row in data]
lp = LinePlot()
lp.x = 50
lp.y = 50
lp.height =125
lp.width =300
lp.data = [zip(times,pred),zip(times,high),zip(times,low)]
lp.lines[0].strokeColor = colors.blue
lp.lines[1].strokeColor = colors.red
lp.lines[2].strokeColor = colors.green
drawing.add(lp)
drawing.add(String(250,150,'Sunspots',
fontSize=14,fillColor=colors.red))
renderPDF.drawToFile(drawing,'report2.pdf','Sunspots')
三、实现效果
更多推荐
已为社区贡献4条内容
所有评论(0)