You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.7 KiB

# -*- coding: utf-8 -*-
from matplotlib import pyplot as plt
import matplotlib
import settings
import re
plt.rcParams['font.family'] = settings.FONT
class view:
def __init__(self, itemList):
self.id = itemList[0]
self.string = itemList[1]
def getFont(): # 列出可用的字体
font = sorted([f.name for f in matplotlib.font_manager.fontManager.ttflist])
for i in font:
print(i)
def main(self):
def str2data(string) -> list:
reg = r"[+-]?([0-9]*\.?[0-9]+|[0-9]+\.?[0-9]*)"
pattern = re.compile(reg)
return pattern.findall(string)
def show(itemList):
x = []
y = []
while itemList:
temp = itemList.pop()
date = temp[0] + "" + temp[1] + ""
price = "" + temp[2] + ""
x.append(date)
y.append(price)
date = temp[3] + "" + temp[4] + ""
price = "" + temp[5] + ""
x.append(date)
y.append(price)
plt.title("价格趋势")
plt.bar(x, y, color = 'g', align = 'center')
plt.xticks(size = 10.0, rotation = 45)
plt.xlabel("日期")
plt.ylabel("价格")
plt.plot(x, y, color = 'red', linewidth = 5.0, linestyle = '--')
plt.show()
itemList = []
for astr in self.string.split(';'):
strList = str2data(astr)
try:
print(astr)
itemList.append(strList)
except BaseException:
break
show(itemList)
def getData():
pass