Skip to content

how can i use matplotlib by PyhtonQt in a qt/C++ application? Thanks #239

Description

@chenwenjingdev

image

Activity

  1. chenwenjingdev commented on Oct 26, 2024

    @chenwenjingdev
    Author

    mainwindow.cpp

    image

  2. usiems commented on Oct 29, 2024

    @usiems
    Contributor

    Well, first, did you install matplotlib into your embedded Python interpreter? Because it seems like you didn't. Perhaps you just need to extend the PYTHON_PATH for matplotlib to be found? This can be done with PythonQt::self()->addSysPath().

    Second: Matplotlib is not prepared to work with PythonQt. In MeVisLab we patch matplotlib to make it work with PythonQt. These patches can be found here.

    Third: To use matplotlib in an already running event loop (like you seem to do), you need additional support. In MeVisLab we currently use qasync, which we also patched to work with PythonQt. The patches can be found here.
    qasync is then initialized with the following code:

    import qasync
    import asyncio
    
    qtLoop = qasync.QEventLoop()
    asyncio.set_event_loop(qtLoop)
    # this is a 'trick', we start the event loop BUT leave it to MeVisLab to call QApplication.exec()
    qtLoop.run_forever_start()
    
  3. locked and limited conversation to collaborators on Feb 14, 2025
  4. converted this issue into a discussion #254 on Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions