码迷,mamicode.com
首页 > 编程语言 > 详细

python生成折线图

时间:2017-09-03 15:37:33      阅读:345      评论:0      收藏:0      [点我收藏+]

标签:plot   request   lines   comm   折线图   rom   imp   targe   blank   

图形生成工具包 reportlab (下载地址:https://bitbucket.org/rptlab/reportlab/get/ddf3d4f5066a.zip

数据地址:ftp://ftp.swpc.noaa.gov/pub/weekly/Predict.txt

 

#! /usr/bin/env python
#coding=utf-8
#sunspots_final.py

from urllib import request
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=ftp://ftp.swpc.noaa.gov//pub//weekly//Predict.txt
COMMENT_CHARS=#:

drawing=Drawing(400,200)
data=[]
for line in request.urlopen(URL,r).readlines():
    line=line.decode(utf-8)
    if not line.isspace() and not line[0] in COMMENT_CHARS:
        data.append([float(n) for n in line.split()])
        
pred=[row[5]-40 for row in data]
high=[row[6]-40 for row in data]
low=[row[7]-40 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=[list(zip(times,pred)),list(zip(times,high)),list(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,SunSopts,fontSize=14,fillColor=colors.orange))

renderPDF.drawToFile(drawing,report2.pdf,SunSpots)
        
#print(data)
        

 

python生成折线图

标签:plot   request   lines   comm   折线图   rom   imp   targe   blank   

原文地址:http://www.cnblogs.com/soul-mate/p/7469611.html

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