polyline()函数画曲线图

from reportlab.graphics.shapes import *
from reportlab.graphics import renderPDF
from reportlab.lib import colors

data = [(2017, 10 , 100.4 , 110.4 , 90.4),
(2017, 11 , 100.4 , 120.4 , 80.4),
(2017 ,12 , 100.6 , 130.6 , 70.6),
(2018 , 1 , 100.8 ,150.8, 50.8),
(2018 ,2 , 100.6 ,150.6 , 50.6),
(2018 ,3 , 90.6 ,150.6 , 90.6),
(2018 ,4 , 90.1 ,160.1 , 80.1),
(2018 ,5 , 90.5 , 160.5 , 90.5 ),
(2018 ,6 , 100.0 , 180.0 , 92.0),
(2018 ,7 , 100.4 , 190.4 , 91.4),
(2018 ,8 ,100.7 ,190.7 ,91.7)
]

d = Drawing(200, 150)
pre = [row[2]-40 for row in data]
high = [row[3]-40 for row in data]
low = [row[4]-40 for row in data]
times = [200*((row[0] + row[1]/12.0) - 2017) - 110 for row in data]

d.add(PolyLine(list(zip(times, pre)), strokeColor=colors.red))
d.add(PolyLine(list(zip(times, high)), strokeColor=colors.blue))
d.add(PolyLine(list(zip(times, low)), strokeColor=colors.green))
d.add(String(0,100,'SUNSPOT', fontSize=18, fillColor=colors.green))
renderPDF.drawToFile(d, r'd:\sun.pdf', 'simple')

转载于:https://blog.51cto.com/victor2016/2108595

你可能感兴趣的:(polyline()函数画曲线图)