# Excel dosyasını yükleyip grafik elde etmek.import sysimport matplotlibmatplotlib.use("Qt5Agg")import pandas as pdfrom PyQt5.QtWidgets import *from PyQt5.QtGui import *from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg,NavigationToolbar2QT as NavigationToolbarfrom matplotlib.figure import Figurefrom collections import Counterfrom functools import partialimport warningsclass help_(QWidget):def __init__(self):super().__init__()self.textEdit = QLabel('Excel dosyası ekleyiniz.\n''Cikis yapmak icin exit tiklayiniz.')self.layout = QHBoxLayout()self.layout.addWidget(self.textEdit)self.setLayout(self.layout)self.setWindowTitle('Help Window')self.setGeometry(350,200,200,100)class MplCanvas(FigureCanvasQTAgg):def __init__(self, parent=None, width=5, height=4, dpi=100) -> object:fig = Figure(figsize=(width, height), dpi=dpi)self.axes = fig.add_subplot(111)super(MplCanvas, self).__init__(fig)class analiz(QMainWindow):def __init__(self):super(analiz, self).__init__()self._createAction()self._cretaMenuBar()self._connectActions()def _cretaMenuBar(self):self.setWindowTitle("Loads Excel")self.setGeometry(200,190,770, 598)menuBar = self.menuBar()fileMenu = QMenu("&File", self)fileMenu.addAction(self.newAction)fileMenu.addAction(self.openAction)fileMenu.addAction(self.saveAction)fileMenu.addSeparator()fileMenu.addAction(self.exitAction)menuBar.addMenu(fileMenu)editMenu = menuBar.addMenu("&Edit")editMenu.addAction(self.copyAction)editMenu.addAction(self.pasteAction)editMenu.addAction(self.cutAction)editMenu.addSeparator()findMenu = editMenu.addMenu("Find and Replace")findMenu.addAction("Find...")findMenu.addAction("Replace...")graphMenu = menuBar.addMenu("Graph")graphMenu.addAction(self.graphMenuAction)helpMenu = menuBar.addMenu("&Help")helpMenu.addAction(self.aboutAction)self.openRecentMenu = fileMenu.addMenu("Open Recent")self.show()def _createAction(self):self.newAction = QAction("&New", self)self.openAction = QAction("&Open...", self)self.saveAction = QAction("&Save...", self)self.exitAction = QAction("&Exit...", self)self.copyAction = QAction("&Copy...", self)self.pasteAction = QAction("&Paste...", self)self.cutAction = QAction("&Cut...", self)self.aboutAction = QAction("&About...", self)self.newAction.setShortcut("Ctrl+N")self.openAction.setShortcut("Ctrl+O")self.saveAction.setShortcut("Ctrl+S")self.copyAction.setShortcut(QKeySequence.Copy)self.pasteAction.setShortcut(QKeySequence.Paste)self.copyAction.setShortcut(QKeySequence.Cut)self.graphMenuAction = QAction("Draw Graph", self)def _connectActions(self):self.newAction.triggered.connect(self.newFile)self.openAction.triggered.connect(self.openFile)self.saveAction.triggered.connect(self.saveFile)self.exitAction.triggered.connect(self.close)self.copyAction.triggered.connect(self.copyContent)self.pasteAction.triggered.connect(self.pasteContent)self.cutAction.triggered.connect(self.cutContent)self.aboutAction.triggered.connect(self.aboutContent)self.openRecentMenu.aboutToShow.connect(self.populateOpenRecent)self.graphMenuAction.triggered.connect(self.grafik)def newFile(self):self.centralWidget.setText("<b>File > New </b> Clicked")def openFile(self):# self.centralWidget.setText("<b>File > Open </b> Clicked")self.fname = QFileDialog.getOpenFileName(self, "Open File")self.file = ",".join(self.fname).split(",")[0].replace("/", "\\")# test = open(self.file, "r")# print(test)# with test:# text = pd.read_excel(self.file)# print(text)def saveFile(self):self.centralWidget.setText("<b>File > Save </b> Clicked")def copyContent(self):self.centralWidget.setText("<b>File > Copy </b> Clicked")def pasteContent(self):self.centralWidget.setText("<b>File > Paste </b> Clicked")def cutContent(self):self.centralWidget.setText("<b>File > Cut </b> Clicked")def aboutContent(self):# self.centralWidget.setText("<b>File > About </b> Clicked")self.w1 = help_()self.w1.show()def populateOpenRecent(self):self.openRecentMenu.clear()actions = []filenames = [f"File-{n}" for n in range(5)]for filename in filenames:action = QAction(filename, self)action.triggered.connect(partial(self.openRecentFile, filename))actions.append(action)self.openRecentMenu.addActions(actions)def grafik(self):with warnings.catch_warnings(record=True):warnings.simplefilter("always")self.df = pd.read_excel(self.file)text1, ok = QInputDialog.getText(self,'X Coords Start position', 'Enter Row Number')text2, ok = QInputDialog.getText(self,'X Coords Start position', 'Enter Column Number')# text3, ok = QInputDialog.getText(self,'Y Coords Start position', 'Enter Column Number')# text4, ok = QInputDialog.getText(self,'Y Coords Stop position', 'Enter Column Number')# text5, ok = QInputDialog.getText(self,'Y Coords start position', 'Enter Row Number')ok = Trueif ok:self.sutun = int(text2)self.satir = int(text1)self.namesRow = self.df.iloc[self.satir:, self.sutun]# self.basSutun = int(text3)# self.bitSutun = int(text4)# self.basSatir = int(text5)# self.values = self.veri.iloc[self.basSatir:,self.basSutun:self.bitSutun]x = Counter(self.namesRow)self.listt1 = []self.listt2 = []for value in set(self.namesRow):self.listt1.append(value)self.listt2.append(x[value])sc = MplCanvas(self, width=5, height=4, dpi=100)sc.axes.bar(self.listt1, self.listt2)# Grafikte degrleri yazmak için yapıldı.for i, txt in enumerate(self.listt2):sc.axes.annotate(txt, (self.listt1[i], self.listt2[i]))toolbar = NavigationToolbar(sc, self)layout = QVBoxLayout()layout.addWidget(toolbar)layout.addWidget(sc)widget = QWidget()widget.setLayout(layout)self.setCentralWidget(widget)self.show()if __name__ == '__main__':app = QApplication(sys.argv)w = analiz()app.exec_()
Bu Blogda Ara
Python ile Grafik Çizimi etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
Python ile Grafik Çizimi etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
9 Mayıs 2021 Pazar
Python ile Grafik Çizimi
Kaydol:
Kayıtlar (Atom)