Advertisement
rbpp

Programa estatística

Nov 4th, 2013
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.12 KB | None | 0 0
  1. # coding=UTF-8
  2. import numpy as np
  3. from matplotlib import pylab
  4. from scipy.stats.mstats import mquantiles
  5. from Tkinter import *
  6. import tkMessageBox
  7. import tkSimpleDialog
  8. import matplotlib.pyplot as plt
  9.  
  10.  
  11.  
  12. prefixo = "vetor"
  13.  
  14. def makeWidgets():
  15.     global entries
  16.     global entries2
  17.     window = Tk()
  18.     window.title('Vetores')
  19.     form = Frame(window)
  20.     form.pack()
  21.     entries = {}
  22.     entries2 ={}
  23.     numero = tkSimpleDialog.askinteger("Vetores", "Digite o número de vetores a serem usados:")  
  24.     for ix in range(numero):
  25.         label = "%s %s" % (prefixo , ix + 1)
  26.         lab = Label(form, text=label)
  27.         ent = Entry(form)
  28.         lab.grid(row=ix, column=0)
  29.         ent.grid(row=ix, column=1)
  30.         entries[label] = ent
  31.    
  32.        
  33.     Button(window, text="Histograma",  command=histograma).pack(side=LEFT)
  34.     Button(window, text="Média",  command=media).pack(side=LEFT)
  35.     Button(window, text="Mediana", command=mediana).pack(side=LEFT)  
  36.     Button(window, text="Quartis", command=quartis).pack(side=LEFT)    
  37.     Button(window, text="Desvio Padrão", command=desvio).pack(side=LEFT)    
  38.  
  39.     window.mainloop()
  40.    
  41. def pegavalores():
  42.     valores = []
  43.     for chave, entrada in sorted(entries.items()):
  44.         valores.append(entrada.get())
  45.     valores = np.asarray(valores, dtype=np.float64)
  46.     return valores
  47.  
  48.  
  49.  
  50. def histograma():
  51.     histograma = pegavalores()
  52.     pylab.grid(True)  
  53.     plt.hist(histograma)
  54.     plt.show()
  55.  
  56. def media():
  57.     media = pegavalores()
  58.     valormedio = np.mean(media)
  59.     tkMessageBox.showinfo("Média", valormedio)
  60.    
  61. def mediana():
  62.     mediana = pegavalores()
  63.     mediana = np.median(mediana)
  64.     tkMessageBox.showinfo("Mediana", mediana)
  65.    
  66. def quartis():
  67.     quartis = pegavalores()
  68.     quartis = mquantiles(quartis, prob=[0.25, 0.5, 0.75, 1])
  69.     y = "%s" % (quartis)
  70.     tkMessageBox.showinfo("Quartis", y)
  71.     plt.hist(quartis)
  72.     plt.show()
  73.    
  74. def desvio():
  75.     desvio = pegavalores()
  76.     desvio = np.std(desvio)
  77.     if desvio == 0:
  78.         tkMessageBox.showinfo("Desvio Padrão", "Não há desvio Padrão!")
  79.     else:
  80.         tkMessageBox.showinfo("Desvio Padrão", desvio)
  81. window = makeWidgets()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement