天天看点

曲线图print(data)

from urllib import request

from reportlab.graphics.shapes import *

from reportlab.graphics import renderPDF

from reportlab.graphics.charts.lineplots import LinePlot

from reportlab.graphics.charts.textlabels import Label

data = []

COMMENT_CHARS = '#:'

url = 'http://services.swpc.noaa.gov/text/predicted-sunspot-radio-flux.txt'

for line in request.urlopen(url).readlines():

d = Drawing(400, 200)

lp = LinePlot()

lp.x = 50

lp.y = 50

lp.height = 130

lp.width = 300

high = [ 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.blue

lp.lines[1].strokeColor = colors.red

lp.lines[2].strokeColor = colors.green

d.add(lp)

d.add(String(250, 150, 'Sunspots', fontSize=14, fillColor=colors.gold))

renderPDF.drawToFile(d, r"d:\report.pdf", "ok")

继续阅读