本文共 1031 字,大约阅读时间需要 3 分钟。
from urllib import request
from reportlab.graphics.shapes import *from reportlab.graphics import renderPDFfrom reportlab.graphics.charts.lineplots import LinePlotfrom reportlab.graphics.charts.textlabels import Labeldata = []
COMMENT_CHARS = '#:'url = ''for line in request.urlopen(url).readlines():if not line.isspace() and not chr(line[0]) in COMMENT_CHARS: data.append([float(n) for n in line.split()])
d = Drawing(400, 200)
lp = LinePlot()lp.x = 50lp.y = 50lp.height = 130lp.width = 300high = [ row[3] for row in data]
low = [ row[4] for row in data]pre = [ row[2] for row in data]times = [ row[0] + row[1]/12.0 for row in data]lp.data = [list(zip(times, pre)),list(zip(times, low)), list(zip(times, high))]lp.lines[0].strokeColor = colors.bluelp.lines[1].strokeColor = colors.redlp.lines[2].strokeColor = colors.greend.add(lp)d.add(String(250, 150, 'Sunspots', fontSize=14, fillColor=colors.gold))
renderPDF.drawToFile(d, r"d:\report.pdf", "ok")
转载于:https://blog.51cto.com/victor2016/2112216