import sys from PySide6.QtWidgets import QApplication, QWidget, QVBoxLayout,…
- User
import sys from PySide6.QtWidgets import QApplication, QWidget, QVBoxLayout, QPushButton, QFileDialog, QLabel from PySide6.QtGui import QPixmap import matplotlib.pyplot as plt from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas from matplotlib.figure import Figure
class MainWindow(QWidget): def init(self): super().init()
self.setWindowTitle("File Loader and Plotter") self.setGeometry(100, 100, 800, 600) self.layout = QVBoxLayout() self.setLayout(self.layout) self.file_label = QLabel("No file loaded") self.layout.addWidget(self.file_label) self.load_button = QPushButton("Load File") self.load_button.clicked.connect(self.load_file) self.layout.addWidget(self.load_button) self.plot_button = QPushButton("Plot") self.plot_button.clicked.connect(self.plot) self.layout.addWidget(self.plot_button) self.figure = Figure() self.canvas = FigureCanvas(self.figure) self.layout.addWidget(self.canvas) self.cid = self.canvas.mpl_connect('pick_event', self.on_pick) def load_file(self): file_name, _ = QFileDialog.getOpenFileName(self, "Open File", "", "All Files (*)") if file_name: self.file_label.setText(file_name) # Process the file here self.data = self.process_file(file_name) def process_file(self, file_name): # Replace this with your own file processing logic with open(file_name, 'r') as f: data = [float(line.strip()) for line in f.readlines()] return data def plot(self): if hasattr(self, 'data'): self.figure.clear() ax = self.figure.add_subplot(111) ax.plot(self.data, picker=5) # 5 points tolerance self.canvas.draw() def on_pick(self, event): if event.artist: x = event.mouseevent.xdata y = event.mouseevent.ydata ax = self.figure.axes[0] ax.plot(x, y, 'ro') # plot a red dot at the clicked point ax.annotate(f"({x:.2f}, {y:.2f})", (x, y), textcoords="offset points", xytext=(0,10), ha='center') self.canvas.draw_idle()app = QApplication(sys.argv) window = MainWindow() window.show() sys.exit(app.exec())
Добавь в эту программу возможность убрать любые поставленные точки
- Assistant
- User
можно ли сделать несколько осей Y, иногда для разных данных нужна другая мера измерения
- Assistant