我试图在pyqt5程序的主gui上显示图。一切正常,减去文件加载...
我有两个类,即App(主要)和PlotCanvas:
我使用Tkinter进行了相同的程序,并且效果很好,我试图将文件名解析为字符串,但是不起作用。需要帮助,我是新手...
处理打开的文件系统:
def openFileNameDialog(self):
options = fd.Options()
options |= fd.DontUseNativeDialog
fileName = fd.getOpenFileName(self,"fd.getOpenFileName()", "/","All Files (*);;CSV Files (*.csv)", options=options)
new_file = fileName.__str__()
myplot = PlotCanvas(self, width=5, height=4, dpi=100)
myplot._plot(new_file)
然后是绘图方法:
def _plot(self, myselected_file):
x = []
y = []
with open(myselected_file,'r') as csvfile:
plots = csv.reader(csvfile, delimiter=';')
for row in plots:
x.append(double(row[0]))
y.append(double(row[1]))
plt.plot(x,y, label='CSV')
plt.xlabel('Tempo milisegundos')
plt.ylabel('Vetor X do acelerometro')
# plt.title('Salto 1 TEMPO x Vetor X')
plt.legend()
plt.draw()
del x [:], y[:]
错误:
Traceback (most recent call last):
File "/Users/diegomota/Projects/py_workspace/Athetech/gui/__main__.py", line 55, in on_click
self.openFileNameDialog()
File "/Users/diegomota/Projects/py_workspace/Athetech/gui/__main__.py", line 51, in openFileNameDialog
myplot._plot(new_file)
File "/Users/diegomota/Projects/py_workspace/Athetech/gui/PlotCanvas.py", line 32, in _plot
with open(myselected_file,'r') as csvfile:
FileNotFoundError: [Errno 2] No such file or directory: "('/Users/diegomota/Desktop/salto_1_1.csv', 'All Files (*)')"