1 回答
TA贡献1836条经验 获得超5个赞
我找到了一个在新的单独窗口中显示 matplotlib 图的解决方案
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow
from pyqtgraph import PlotWidget, plot
import pyqtgraph as pg
import pandas as pd
from pandas import *
from datetime import datetime
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import matplotlib
matplotlib.use('Qt5Agg')
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg, NavigationToolbar2QT as NavigationToolbar
from matplotlib.figure import Figure
import psycopg2
from admin import Ui_MainWindow as ui
class MainApp(QMainWindow, ui):
def __init__(self):
QMainWindow.__init__(self)
self.setupUi(self)
self.Handel_Buttons()
def Handel_Buttons(self):
self.pushButton_113.clicked.connect(self.draw_graph_all)
def draw_graph_all(self): #pushButton_113
self.connection = psycopg2.connect(user="postgres",
password="password",
host="localhost",
database="database")
self.cur = self.connection.cursor()
date_0 = str(self.dateEdit_19.text())
date_1 = str(self.dateEdit_20.text())
self.cur.execute( '''SELECT date_d, SUM(montant) FROM transactions WHERE date_d BETWEEN %s AND %s GROUP BY date_d ''', (date_0, date_1))
rows = self.cur.fetchall()
date = []
montant = []
for row in rows:
date.append(row[0])
montant.append(row[1])
plt.figure()
plt.plot(date, montant)
plt.show(block=False)
添加回答
举报