-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEletrocrom_Gera_grafico.py
144 lines (110 loc) · 5.17 KB
/
Eletrocrom_Gera_grafico.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# -*- coding: utf-8 -*-
"""
Copyright (c) 2017 Guilherme Taborda Ribas.
Copyright (c) 2012-2013 Matplotlib Development Team; All Rights Reserved.
Copyright (c) 2017 NumPy developers.
Copyright (c) 2016 Riverbank Computing Limited.
Copyright (c) 2017 The Qt Company.
This file is part of EletroCrom.
EletroCrom is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or any later version.
EletroCrom is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with EletroCrom. If not, see <http://www.gnu.org/licenses/>.
"""
import os
import sys
import datetime
from tkinter import *
from tkinter.filedialog import asksaveasfilename
from tkinter.messagebox import showerror
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
from matplotlib.widgets import Button, CheckButtons
from matplotlib.cbook import get_sample_data
from PyQt5.QtWidgets import QTableWidget,QTableWidgetItem,QFileDialog
class Gera_grafico():
def __init__(self, resultado):
self.dados_ef = resultado
self.str_relatorio = []
self.show_imagem = False
self.tabela = []
def show_grafico(self, ciclos):
carga_red = self.dados_ef[0]
carga_oxi = self.dados_ef[1]
vabs_red = self.dados_ef[2]
vabs_oxi = self.dados_ef[3]
ec = self.dados_ef[4]
eer = self.dados_ef[5]
eeo = self.dados_ef[6]
saldo_aux = 0
fig = plt.figure(figsize=(10, 5))
fig.canvas.set_window_title('Resultado de Eficiência')
## fig.patch.set_facecolor('#222211')
font_color1 = 'Black'
width = 0.35
#######################
##Eficiência Coulômbica
#######################
ax1_range = np.arange(len(ec))
ax1 = plt.subplot(2,3,1)
ax1.bar(ax1_range, ec, width,alpha=0.9, color='DarkGreen')
ax1.set_xticks(ax1_range)
ax1.set_xticklabels(ciclos, rotation='horizontal', fontsize = 8)
ax1.set_xlabel('Nº de Ciclos', color = font_color1)
ax1.set_title('Eficiência Coulômbica (%)', fontsize = 10, color = font_color1)
ax1.tick_params(colors=font_color1)
ax1.yaxis.grid(True)
############################
####Eficiência Eletrocrômica
############################
ax2_range = np.arange(len(eer))
ax2 = plt.subplot(2,3,2)
ax2.bar(ax2_range, eer, width,alpha=0.9, color='DarkBlue', label='Redução')
ax2.bar(ax2_range+width, eeo, width,alpha=0.9, color='DarkRed', label='Oxidação')
ax2.set_xticks(ax2_range + width/2)
ax2.set_xticklabels(ciclos, rotation='horizontal', fontsize = 8)
ax2.set_xlabel('Nº de Ciclos', color = font_color1)
ax2.set_title('Eficiência Eletrocrômica (%)', fontsize = 10, color = font_color1)
ax2.tick_params(colors=font_color1)
ax2.yaxis.grid(True)
ax2.legend(bbox_to_anchor=(1.05, 1), loc=2, shadow=True)
################################
####Tabela com dados
################################
nomes = ['Ciclos', 'Carga Red', 'Carga Oxi', 'EC%', 'Abs Red', 'Abs Oxi', 'EER', 'EEO']
collabel=ciclos
i = 0
while i < len(collabel):
self.tabela.append([collabel[i],round(1000*carga_red[i],2),round(1000*carga_oxi[i],2),round(ec[i],1),round(vabs_red[i],4),round(vabs_oxi[i],4),round(eer[i],2),round(eeo[i],2)])
i+=1
ax3 = plt.subplot(2,3,(4,6))
ax3.axis('off')
ax3.table(cellText=self.tabela, colLabels=nomes,loc='center')
fig.tight_layout()
ax_dados_csv = plt.axes([0.725, 0.565, 0.25, 0.05])
button_dados_csv = Button(ax_dados_csv, "Salvar Dados da Tabela'.csv'")
button_dados_csv.on_clicked(self.clicked_button_dados_csv)
plt.show()
def clicked_button_dados_csv(self, label):
filename = asksaveasfilename(initialdir = os.getenv('HOME'),
filetypes =(("Csv File", "*.csv"),
("Text File", "*.txt"),
("All Files","*.*")),
title = "Salvar como")
if filename:
##Primeira Linha
saveLine = 'Ciclos,Carga Red,Carga Oxi,EC%,Abs Red,Abs Oxi,EER,EEO\n'
saveFile = open(filename, 'a')
saveFile.write(saveLine)
saveFile.close()
for linha in self.tabela:
saveLine = str(linha[0])+','+str(linha[1])+','+str(linha[2])+','+str(linha[3])+','+str(linha[4])+','+str(linha[5])+',' +str(linha[6])+','+str(linha[7])+'\n'
saveFile = open(filename, 'a')
saveFile.write(saveLine)
saveFile.close()