# -*- coding: utf-8 -*-
"""
Created on Tue May 14 18:58:50 2019
把图片保存成了文件,供gui窗口读取,取消了Label_img的显示,调整按钮位置
添加大小比例,新的分析数据
大小比例数据写好了,下一步画图
改变工具栏背景色为白色,大小比例取百分之一的数据
奇偶比例也写好了,并且先切百分之一的数据,然后再分类统计,这样提升程序速度
增加了数据预处理,pl3qh,提前切好排列3百分之一的数据,省得临时切费时间
把横向轴X上写上中奖号,省得不知道中奖号多少,程序写错了也不知道
把pl3重新排序,前后顺序互换一下
把质合数和质合比例都统计出来了
加了组选3组选6
@author: Administrator
"""
import pandas as pd
from tqdm import tqdm
from pandas.core.frame import DataFrame
import numpy as np #科学计算数据分析库,另起名为np
import matplotlib.pyplot as plt #擅长画二维图曲线,股票均线,另起名为plt
from sklearn.preprocessing import MinMaxScaler #机器学习库,数据预处理,把数据定为0,1之间
from keras.models import Sequential #深度学习库,建立模型,多网络层线性堆叠顺序模型
from keras.layers import LSTM, Dense, Activation #准备用三种神经网络层,长短期记忆网络,全连接网络层,激活层
#from keras.utils import plot_model#模型可视化做图
#from IPython.display import SVG
#from keras.utils.vis_utils import model_to_dot
import xlrd#读excel文件
from tkinter import *
import tkinter as tk
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg,NavigationToolbar2Tk #NavigationToolbar2TkAgg
import matplotlib
matplotlib.use('Agg')
from matplotlib.pyplot import plot,savefig
from PIL import Image, ImageTk
from tkinter import ttk
plt.rcParams['font.family'] = 'SimHei' ## 设置字体
def read_to_excel():#自定义函数,读取excel表里排列三中奖号
# 设置路径
path = 'pl3.xls'
# 打开execl
workbook = xlrd.open_workbook(path)
# 根据sheet索引或者名称获取sheet内容
Data_sheet = workbook.sheets()[0] # 通过索引获取
#rowNum = Data_sheet.nrows # sheet行数
#colNum = Data_sheet.ncols # sheet列数
# 获取整行和整列的值(列表)
#rows = Data_sheet.row_values(0) # 获取第一行内容
pl3 = Data_sheet.col_values(1) # 获取第二列内容
pl3=pl3[1:]
pl3.reverse()
# print (rows)
#print (cols)#打印开奖号
baiwei=[x[0] for x in pl3]
shiwei=[x[1] for x in pl3]
gewei=[x[2] for x in pl3]
return pl3,baiwei,shiwei,gewei
#创建窗口
root = tk.Tk()
root.wm_title("体育彩票排列3统计预测系统")
root.geometry("1920x1010+0+0")
#img_open = Image.open('zft.jpg')
#img_png = ImageTk.PhotoImage(img_open)
#label_img = tk.Label(root, image = img_png)
#label_img.pack()
f=plt.figure(figsize=(19.20,10.80))
# 将绘制的图形显示到tkinter:创建属于root的canvas画布,并将图f置于画布上
pl3,baiwei,shiwei,gewei=read_to_excel()#读excel表里的开奖号并做成开奖号,百位,十位,个位,四个数组
#数据切片显示百分之1的数据,因为五千多期号做到一个屏幕上根本看不清
qiep=int(np.array(pl3).shape[0] *0.98)#数据切片,设定要切多少
zb=['0','1','2','3','4','5','6','7','8','9','10']#校正Y轴,就是竖轴
pl3qh=pl3[qiep:]
pl3q=DataFrame(np.array(pl3)[qiep:])
def zft(event):
plt.clf()
create_matplotlibzft()
def k(event):
plt.clf()
create_matplotlibk()
def dx(event):
plt.clf()
create_matplotlibdx()
def jo(event):
plt.clf()
create_matplotlibjo()
def dxbl(event):
plt.clf()
create_matplotlibdxbl()
def jobl(event):
plt.clf()
create_matplotlibjobl()
def dxbljj(event):
plt.clf()
create_matplotlibdxbljj()
def jobljj(event):
plt.clf()
create_matplotlibjobljj()
def zh(event):
plt.clf()
create_matplotlibzh()
def zhbl(event):
plt.clf()
create_matplotlibzhbl()
def zhbljj(event):
plt.clf()
create_matplotlibzhbljj()
def z3z6(event):
plt.clf()
create_matplotlibz3z6()
def hz(event):
plt.clf()
create_matplotlibhz()
def ac(event):
plt.clf()
create_matplotlibac()
def lh(event):
plt.clf()
create_matplotliblh()
def ycz(event):
plt.clf()
create_matplotlibycz()
def create_matplotlibzft():
#统计每个数字在个十百位出现次数
baiweidata={}
for i in range(10):
i=str(i)
print('排列3百位数字 %d 出现次数 %s ' % (int(i),baiwei.count(i)))
baiweidata [i]= baiwei.count(i)
i=int(i)
print(baiweidata)
shiweidata={}
for i in range(10):
i=str(i)
print('排列3十位数字 %d 出现次数 %s ' % (int(i),shiwei.count(i)))
shiweidata[i]=shiwei.count(i)
i=int(i)
print(shiweidata)
geweidata={}
for i in range(10):
i=str(i)
print('排列3个位数字 %d 出现次数 %s ' % (int(i),gewei.count(i)))
geweidata[i]=gewei.count(i)
i=int(i)
print(geweidata)
#转换数据类型,转换成做图函数能认识的参数
bwcs=baiweidata.values()
swcs=shiweidata.values()
gwcs=geweidata.values()
#画直方图
plt.bar(np.arange(10),bwcs,width=0.3)
plt.bar(np.arange(10)+0.3,swcs,width=0.3)
plt.bar(np.arange(10)+0.6,gwcs,width=0.3)
#每个数字出现次数写直方柱上边
for x,y in zip(np.arange(10),bwcs):
plt.text(x,y+0.5,'%d'%y, ha='center', va= 'bottom')
for x,y in zip(np.arange(10),swcs):
plt.text(x+0.3,y+0.05,'%d'%y, ha='center', va= 'bottom')
for x,y in zip(np.arange(10),gwcs):
plt.text(x+0.6,y+0.05,'%d'%y, ha='center', va= 'bottom')
#显示X横轴0到9数字
new_ticks = np.linspace(0, 9, 10)
plt.xticks(new_ticks)
#直方图标题等文字信息
plt.xlabel("0到9,从左到右按百十个位排")
plt.ylabel("出现次数")
plt.title("排列三0到9在百十个位出现次数统计表")
plt.legend(['百位','十位','个位'])
savefig('0到9出现次数.jpg')
#canvas.draw()
def create_matplotlibk():
plt.clf()
#百十个位K线图
baiweik=np.array(baiwei)[qiep:]
shiweik=np.array(shiwei)[qiep:]
geweik=np.array(gewei)[qiep:]#要百分之一的数据
print(baiweik,shiweik,geweik)
#开始做图
plt.xtick