当前位置:   article > 正文

python生成折线图

python reportlab折线图

图形生成工具包 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)
        

 

转载于:https://www.cnblogs.com/soul-mate/p/7469611.html

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/黑客灵魂/article/detail/856734
推荐阅读
相关标签
  

闽ICP备14008679号