我尝试根据文件中的数据绘制图表。比如一组数据有几个图表点是没问题的,就画出来了。然而,我要绘制的数据量在不断增长,目前约为15000点。当我尝试加载和绘制它们时,应用程序界面崩溃。我的代码如下。数据文件在这里:testdata.txt你能告诉我如何处理吗?
import sys
from PyQt5.QtWidgets import QDialog, QApplication, QPushButton, QVBoxLayout
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar
import matplotlib.pyplot as plt
class Window(QDialog):
def __init__(self):
super().__init__()
title = "Wykresy"
self.setWindowTitle(title)
# a figure instance to plot on
self.figure = plt.figure()
# this is the Canvas Widget that
# displays the 'figure'it takes the
# 'figure' instance as a parameter to __init__
self.canvas = FigureCanvas(self.figure)
# this is the Navigation widget
# it takes the Canvas widget and a parent
self.toolbar = NavigationToolbar(self.canvas, self)
# Just some button connected to 'plot' method
self.button = QPushButton('Plot')
# adding action to the button
self.button.clicked.connect(self.plot)
# creating a Vertical Box layout
layout = QVBoxLayout()
# adding tool bar to the layout
layout.addWidget(self.toolbar)
# adding canvas to the layout
layout.addWidget(self.canvas)
# adding push button to the layout
layout.addWidget(self.button)
# setting layout to the main window
self.setLayout(layout)
self.showMaximized()
def plot(self):
with open('testdata.txt') as f:
lines = f.readlines()
x = [line.split('\t')[0] for line in lines]
y = [line.split('\t')[1] for line in lines]
# clearing old figure
self.figure.clear()
有只小跳蛙
慕哥9229398
相关分类