question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

plotnine and pyqt5

See original GitHub issue

Hello,

plotnine is a wonderful package. I am trying to figure out how to incorporate plots into a pyqt5 application. For matplotlib, there are a number of examples, but with plotnine, I don’t know where to start. Any guidance is greatly appreciated.

Thank you.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
breisfeldcommented, Sep 1, 2019

The solution I am using may not be at all useful to others because of the way my application is structured. In any case, here is a little about what I am doing at the moment.

My present application is a PyQT5 wrapper that creates inputs for, runs, and analyzes outputs from a computational engine written in C. I am using plotnine for the analysis phase.

As of now, I am pickling figures from matplotlib (and can now do the same with plotnine) during the analysis phase. These then get stored in an sqlite database. The GUI accesses the database, unpickles the figures, and displays them.

The relevant code for the display (which I have as a QDialog) is something like

from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT
from matplotlib.figure import Figure

class PlotsDialog(QDialog):
    def __init__(self, title, simplot, parent=None, *args):
        super().__init__(parent, *args)
        self._title = title
        self._plot = simplot
        self.setup_ui()

    def setup_ui(self):

        self.figure = Figure()
        self.canvas = FigureCanvas(self._plot)
        self.toolbar = NavigationToolbar2QT(self.canvas, self)

        # set the layout
        layout = QVBoxLayout()
        layout.addWidget(self.toolbar)
        layout.addWidget(self.canvas)
        self.setLayout(layout)
        self.setWindowTitle(f"Simulation results: {self._title}")

        buttons = QDialogButtonBox(QDialogButtonBox.Ok)
        buttons.accepted.connect(self.accept)
        buttons.rejected.connect(self.reject)

        self.show()

Here, the simplot argument is the unpickled figure object.

This approach allows panning and zooming of static plots, which is adequate for now. If matplotlib figure pickles contain the underlying plotted data, something much more interactive could be implemented.

0reactions
has2k1commented, Dec 8, 2020

Added to the tutorial.

Read more comments on GitHub >

github_iconTop Results From Across the Web

A PyQt5 Application — plotnine 0.10.1 documentation
This example applicate creates a gui windows with a canvas and a plot button which when pressed draws out a plot from random...
Read more >
plotnine is broken with matplotlib==3.6 - Stack Overflow
It was due to a internal matplotlib call that is no longer supported and has been replaced. So I guess you could choose...
Read more >
How to embed Matplotlib Graph in a PyQt5 application
In this PyQt5 tutorial, we are going to learn how to embed a matplotlib graph in a PyQt5 application.Buy Me a Coffee?
Read more >
Making Plots With plotnine - Data Carpentry
Objectives. Create a plotnine object. Set universal plot settings. Modify an existing plotnine object. Change the aesthetics of a plot such as color....
Read more >
[Example code]-Axis scaling with plotnine - appsloveworld.com
Coding example for the question Axis scaling with plotnine. ... how to set axis interval in candle stick using pyqtgraph with pyqt5?
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found