2

My head is spinning from trying to get finplot to create an embedded graph for days with no luck. I decided to restart small.

The code that I included works as-is. However, if I change the import to PyQt6 from PyQt5, it stops working.

The application that I am trying to integrate this into is all done in PyQt6. finplot works and displays externally in my PyQt6 attempts, but I cannot use fplt.create_plot_widget while passing self.window() with PyQt6, it seems.

Honestly, I keep running into trouble any time i try to use pyqtgraph. I sidetracked to do something clever with mplfinance, but I'm back to where i was 6 months ago with trying to get anything graph and Qt related to show up in a layout nicely with the other widgets :/

Any help is appreciated. Thank you.

import sys
import finplot as fplt
from PyQt5.QtWidgets import *
import yfinance

class App(QMainWindow):
    def __init__(self):
        super().__init__()
        self.title = 'PyQt5 - QTabWidget'
        self.left = 0
        self.top = 0
        self.width = 600
        self.height = 400
        self.setWindowTitle(self.title)
        self.setGeometry(self.left, self.top, self.width, self.height)
        self.menu = self.menuBar()

        self.widget = MyGraphWidget(self)
        self.setCentralWidget(self.widget)

        fplt.show(qt_exec=False)
        self.show()

class MyGraphWidget(QWidget):
    def __init__(self, parent):
        super(QWidget, self).__init__(parent)
        self.layout = QVBoxLayout(self)

        self.resize(600, 400)
        self.label = QLabel("AAPL")
        self.df = yfinance.download('AAPL')
        self.fplt_widget1, self.fplt_widget2 = fplt.create_plot_widget(self.window(), rows=2)
        fplt.candlestick_ochl(self.df[['Open', 'Close', 'High', 'Low']])

        self.layout.addWidget(self.label)
        self.window().axs = [self.fplt_widget1]
        self.layout.addWidget(self.fplt_widget1.ax_widget)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = App()

    sys.exit(app.exec())
sduffy89
  • 97
  • 7

1 Answers1

1

This is not an issue with pyqtgraph. That project currently supports PyQt6/PySide6.

However, looking at finplot project's setup.py here, it looks like it is currently on PyQt5 (evidenced by the configuration line install_requires=['pandas', 'PyQt5', 'pyqtgraph>=0.11.1'],). The migration to PyQt6 would have to start there. There is some visible mention of hints toward PyQt6 in the project's issues here and here.

As of today, it appears that your options are:

  1. Submit an issue to finplot's maintainer to request support for PyQt6.
  2. Fork finplot, do the migration work yourself and submit a PR back.
  3. Keep using finplot with PyQt5.
Basil
  • 659
  • 4
  • 11