在一的基础上,想着把所有的折线图放在一个图中,然后图的结果如图所示:

不是略丑,是很丑~

依然的单进程,只是将图标结果放在了一张图里

代码如下:

#-*-coding:utf-8 -*-
import urllib
import re
import json
import urllib2
from lxml import etree
import requests
import time
from Queue import Queue
import matplotlib.pyplot as plt
URL = 'http://quote.fx678.com/exchange/WH'
nation_que = Queue()
nation = Queue()
high = Queue()
start_time = Queue() Chart = [] def download(url, headers, num_try=2):
while num_try >0:
num_try -= 1
try:
content = requests.get(url, headers=headers)
return content.text except urllib2.URLError as e:
print 'Download error', e.reason return None def sub_sort(array,array1,low,high):
key = array[low]
key1 = array1[low]
while low < high:
while low < high and array[high] >= key:
high -= 1
while low < high and array[high] < key:
array[low] = array[high]
array1[low] = array1[high]
low += 1
array[high] = array[low]
array1[high] = array1[low]
array[low] = key
array1[low] = key1
return low def quick_sort(array,array1,low,high):
if low < high:
key_index = sub_sort(array,array1,low,high)
quick_sort(array,array1,low,key_index)
quick_sort(array,array1,key_index+1,high)
def get_type_url():
headers = {
'User_agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36',
'Referer': 'http://quote.fx678.com/exchange/WH',
'Cookie': 'io=-voMclEjiizK9nWKALqB; UM_distinctid=15f5938ddc72db-089cf9ba58d9e5-31657c00-fa000-15f5938ddc8b24; Hm_lvt_d25bd1db5bca2537d34deae7edca67d3=1509030420; Hm_lpvt_d25bd1db5bca2537d34deae7edca67d3=1509031023',
'Accept-Language': 'zh-CN,zh;q=0.8',
'Accept-Encoding': 'gzip, deflate',
'Accept': '*/*'
}
content = download(URL,headers)
html = etree.HTML(content)
result = html.xpath('//a[@class="mar_name"]/@href')
for each in result:
print each
st = each.split('/')
nation_que.put(st[len(st)-1]) get_precent() def get_precent(): while not nation_que.empty():
ss = nation_que.get(False)
print ss
url = 'http://api.q.fx678.com/history.php?symbol=' + ss +'&limit=288&resolution=5&codeType=8100&st=0.8274405615006541'
print url
headers = {'Accept':'application/json, text/javascript, */*; q=0.01',
'Accept-Encoding':'gzip, deflate',
'Accept-Language':'zh-CN,zh;q=0.8',
'Connection':'keep-alive',
'Host':'api.q.fx678.com',
'Origin':'http://quote.fx678.com',
'Referer':'http://quote.fx678.com/symbol/USD',
'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36'
}
num_try = 2
while num_try >0:
num_try -= 1
try:
content = requests.get(url, headers=headers)
html = json.loads(content.text)
st = html['h']
T_time = html['t']
if len(st) > 0 and len(T_time) > 0:
draw_pict(T_time,st)
break
except urllib2.URLError as e:
print 'Download error', e.reason
nation_que.task_done()
List = []
def draw_pict(T_time1,high_rate):
print T_time1
print high_rate
num = 0 High = T_time1
Time = high_rate High_Rate = []
num = 0
T_time = []
for each,high1 in zip(T_time1,high_rate):
st = time.localtime(float(each)) if st.tm_min == 0:
T_time.append(st.tm_hour)
High_Rate.append(high1)
else:
pass
if len(T_time) == len(High_Rate):
quick_sort(T_time,High_Rate,0,len(High_Rate)-1)
List.append(High_Rate) def draw_picture():
colu = len(List) num = 1
for each in List:
plt.subplot(colu/2 + 1,2,num)
num+=1 list = each
T_time = []
for i in range(len(list)):
T_time.append(i)
print len(list)
print len(T_time)
plt.plot(T_time, list, marker='*') plt.show()
plt.title('Share Message') if __name__ == '__main__':
get_type_url()
draw_picture()

折线图结果如图

ps:1的是将图的结果进行单个显示,每支股票是单独的一张图

最新文章

  1. Spark Streaming资源动态申请和动态控制消费速率剖析
  2. C语言基础--while循环
  3. linux下解决端口被占用的问题
  4. 鼠标悬停移除更换class
  5. 杭电acm阶段之理工大版
  6. 从编译安装Keepalived 到 配置 负载均衡(LVS-DR)
  7. 今天遇到了一个Spring出现的一个未知错误,分享下
  8. git出现错误原因解释
  9. Union和Union All 的区别
  10. RecyclerView嵌套RecyclerView
  11. python-----HTMLTestRunner报告生成注意点!
  12. [一]FileDescriptor文件描述符 标准输入输出错误 文件描述符
  13. DirectX11 With Windows SDK--22 立方体映射:静态天空盒的读取与实现
  14. 完美脱离Windows!! Linux发行版第一系统 Manjaro 开箱教程 :)
  15. Ubuntu 硬盘分区只读,重新挂载为读写分区之后,文件依然创建出错
  16. 迭代和JDB调试
  17. Mongodb中经常出现的错误(汇总)child process failed, exited with error number
  18. 导入jar包的方法
  19. AIM Tech Round 3 (Div. 1) B. Recover the String 构造
  20. IOS设计模式第四篇之装饰设计模式的类别设计模式

热门文章

  1. 【BZOJ5319】军训列队(主席树)
  2. splay tree 学习笔记
  3. NOI2014魔法森林题解报告
  4. SVN跨服务器自动更新--实现文件分发
  5. 【spoj】DIVCNTK
  6. python基础----再看property、描述符(__get__,__set__,__delete__)
  7. Python3 字典 update() 方法
  8. db2 数据库操作JDBC .addBatch() 方法执行时,报错排查结果
  9. 省选模拟赛 LYK loves rabbits(rabbits)
  10. bzoj 1070 费用流