亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在新窗口中顯示 matplotlib 圖形,第二個窗口不顯示結果 pyqt

在新窗口中顯示 matplotlib 圖形,第二個窗口不顯示結果 pyqt

BIG陽 2023-12-12 10:18:21
我正在使用 picot GUI 應用程序來顯示一些圖形和圖表,我嘗試使用 pyqtgraph 來實現,但它不適用于日期或時間,所以我切換到 matplotlib它工作完美,但結果顯示在同一個窗口中,我無法返回主窗口我正在尋找一種在另一個窗口中顯示相同結果的方法,因為我嘗試使用像本例這樣的小部件來完成此操作https://github.com/swharden/Python-GUI-examples/tree/master/2016-07 -30_qt_matplotlib_sine_scroll,在ui內部但有很多問題我嘗試在第二個窗口 pyqt5 中使用這個例子 matplotlib 它工作完美并且它顯示另一個窗口但它是空的這是我的用戶界面<?xml version="1.0" encoding="UTF-8"?><ui version="4.0"> <class>MainWindow</class> <widget class="QMainWindow" name="MainWindow">  <property name="geometry">   <rect>    <x>0</x>    <y>0</y>    <width>800</width>    <height>600</height>   </rect>  </property>  <property name="windowTitle">   <string>MainWindow</string>  </property>  <widget class="QWidget" name="centralwidget">   <widget class="QPushButton" name="pushButton_113">    <property name="geometry">     <rect>      <x>610</x>      <y>90</y>      <width>161</width>      <height>41</height>     </rect>    </property>    <property name="text">     <string>Recherche</string>    </property>   </widget>   <widget class="QDateEdit" name="dateEdit_20">    <property name="geometry">     <rect>      <x>340</x>      <y>90</y>      <width>251</width>      <height>41</height>     </rect>    </property>    <property name="dateTime">     <datetime>      <hour>0</hour>      <minute>0</minute>      <second>0</second>      <year>2020</year>      <month>1</month>      <day>1</day>     </datetime>    </property>    <property name="calendarPopup">     <bool>true</bool>    </property>   </widget>   <widget class="QDateEdit" name="dateEdit_19">    <property name="geometry">     <rect>      <x>40</x>      <y>90</y>      <width>271</width>      <height>41</height>     </rect>    </property>    <property name="dateTime">     <datetime>      <hour>0</hour>      <minute>0</minute>      <second>0</second>      <year>2020</year>      <month>1</month>      <day>1</day>     </datetime>    </property>
查看完整描述

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)

            


查看完整回答
反對 回復 2023-12-12
  • 1 回答
  • 0 關注
  • 212 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號