1 acc 0.2
2 acc 0.05
4 acc 0.3
6 acc 0.15
8 acc 0.05
10 acc 0.15
12 acc 0.05
14 acc 0.1
16 acc 0.2
18 acc 0.15
20 acc 0.05
# -*- coding: utf-8 -*-
'''
绘制数据界面
'''
import matplotlib.pyplot as plt
import numpy as np
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, \
QPushButton, QTextEdit, QLineEdit, QMessageBox, QLabel
class my_plot_Data_class(QMainWindow):
def __init__(self):
super(my_plot_Data_class, self).__init__()
self.InitUi()
def InitUi(self):
self.resize(600, 500)
self.setWindowTitle('绘制数据专用软件')
self.btn_1 = QPushButton('plot', self)
self.btn_1.setGeometry(450, 250, 100, 50)
self.btn_1.clicked.connect(self.push_btn_1_function)
self.btn_2 = QPushButton('exit', self)
self.btn_2.setGeometry(450, 350, 100, 50)
self.btn_2.clicked.connect(self.push_btn_2_function)
self.btn_3 = QPushButton('clear', self)
self.btn_3.setGeometry(50, 350, 100, 50)
self.btn_3.clicked.connect(self.push_btn_3_function)
self.lintext_1 = QLineEdit(self)
self.lintext_1.setGeometry(50, 250, 300, 50)
self.label_1 = QLabel('请输入文件路径:', self)
self.label_1.setGeometry(50, 190, 200, 50)
self.show()
def push_btn_1_function(self):
x = []
y = []
filename = self.lintext_1.text()
try:
if filename == '':
reply = QMessageBox.warning(self, '警告', '输入框不能为空', QMessageBox.Ok)
else:
with open('{}'.format(filename), 'r') as f:
lines = f.readlines()
for line in lines:
data = line.split(' ')
x.append(data[0])
y.append(data[2])
plt.figure()
plt.plot(x, y, 'r-')
plt.show()
except Exception as e:
reply = QMessageBox.warning(self, '警告', '{}'.format(e), QMessageBox.Cancel)
def push_btn_3_function(self):
self.lintext_1.clear()
def push_btn_2_function(self):
self.close()
if __name__ == '__main__':
app = QApplication(sys.argv)
w = my_plot_Data_class()
sys.exit(app.exec_())
# -*- coding: utf-8 -*-
'''
绘制数据界面
'''
import matplotlib.pyplot as plt
import numpy as np
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, \
QPushButton, QTextEdit, QLineEdit, QMessageBox, QLabel
from matplotlib.font_manager import FontProperties
class my_plot_Data_class(QMainWindow):
def __init__(self):
super(my_plot_Data_class, self).__init__()
self.InitUi()
def InitUi(self):
self.resize(600, 500)
self.setWindowTitle('绘制数据专用软件')
self.font = FontProperties(fname=r"c:\windows\fonts\simsun.ttc", size=14)
self.btn_1 = QPushButton('plot', self)
self.btn_1.setGeometry(450, 250, 100, 50)
self.btn_1.clicked.connect(self.push_btn_1_function)
self.btn_2 = QPushButton('exit', self)
self.btn_2.setGeometry(450, 350, 100, 50)
self.btn_2.clicked.connect(self.push_btn_2_function)
self.btn_3 = QPushButton('clear', self)
self.btn_3.setGeometry(50, 350, 100, 50)
self.btn_3.clicked.connect(self.push_btn_3_function)
self.lintext_1 = QLineEdit(self)
self.lintext_1.setGeometry(50, 250, 300, 50)
self.label_1 = QLabel('请输入文件路径:', self)
self.label_1.setGeometry(50, 190, 200, 50)
self.show()
def push_btn_1_function(self):
x = []
y = []
filename = self.lintext_1.text()
try:
if filename == '':
reply = QMessageBox.warning(self, '警告', '输入框不能为空', QMessageBox.Ok)
else:
with open('{}'.format(filename), 'r') as f:
lines = f.readlines()
for line in lines:
data = line.split(' ')
x.append(data[0])
y.append(data[1])
plt.figure()
if filename == '***.txt':
plt.xlabel('**次数', fontproperties=self.font)
plt.ylabel('**的值', fontproperties=self.font)
elif filename == '***.txt':
plt.xlabel('**次数', fontproperties=self.font)
plt.ylabel('**精度', fontproperties=self.font)
else:
pass
plt.scatter(x[0], y[0], c='b', marker='*', s=200)
plt.text(x[0], y[0], "{}".format(y[0]), size=15, alpha=1, color='b')
plt.scatter(x[len(x)-1], y[len(y)-1], c='b', marker='*', s=200)
plt.text(x[len(x)-1], y[len(y)-1], "{}".format(y[len(y)-1]), size=15, alpha=1, color='b')
line = plt.plot(x, y, 'r.-')
plt.legend(line, ('value',))
plt.show()
except Exception as e:
reply = QMessageBox.warning(self, '警告', '{}'.format(e), QMessageBox.Cancel)
def push_btn_3_function(self):
self.lintext_1.clear()
def push_btn_2_function(self):
self.close()
if __name__ == '__main__':
app = QApplication(sys.argv)
w = my_plot_Data_class()
sys.exit(app.exec_())
我爱你就像天上的太阳,太阳它将我照亮。--鲁迅