zoukankan      html  css  js  c++  java
  • urllib获取太阳黑子图表程序

     1 # -*- coding:utf-8 -*-
     2 # Author:Vincent Zhang
     3 
     4 from urllib.request import urlopen
     5 from reportlab.graphics.shapes import *
     6 from reportlab.graphics.charts.lineplots import LinePlot
     7 from reportlab.graphics.charts.textlabels import Label
     8 from reportlab.graphics import renderPDF
     9 
    10 URL = 'ftp://ftp.swpc.noaa.gov/pub/weekly/Predict.txt'
    11 COMMENT_CHARS = '#:'
    12 drawing = Drawing(400, 200)
    13 data = []
    14 for line in urlopen(URL).readlines():
    15     line = line.decode()
    16     if not line.isspace() and line[0] not in COMMENT_CHARS:
    17         data.append([float(n) for n in line.split()])
    18 pred = [row[2] for row in data]
    19 high = [row[3] for row in data]
    20 low = [row[4] for row in data]
    21 times = [row[0] + row[1] / 12.0 for row in data]
    22 lp = LinePlot()
    23 lp.x = 50
    24 lp.y = 50
    25 lp.height = 125
    26 lp.width = 300
    27 lp.data = [list(zip(times, pred)),
    28            list(zip(times, high)),
    29            list(zip(times, low))]
    30 lp.lines[0].strokeColor = colors.blue
    31 lp.lines[1].strokeColor = colors.red
    32 lp.lines[2].strokeColor = colors.green
    33 drawing.add(lp)
    34 drawing.add(String(250, 150, 'Sunspots',
    35                    fontSize=14, fillColor=colors.red))
    36 renderPDF.drawToFile(drawing, 'report2.pdf', 'Sunspots')
    View Code
  • 相关阅读:
    括号序列
    乘积最大
    装箱问题
    开心的金明
    金明的预算方案(有依赖的背包问题)
    砝码称重
    (枚举)算法竞赛入门经典(7.1.2)最大乘积
    (枚举)算法竞赛入门经典(7.1.1)除法
    Zabbix历史数据清理
    sonarqube6.7.1使用
  • 原文地址:https://www.cnblogs.com/zijue/p/10164027.html
Copyright © 2011-2022 走看看