10000 PySide2/PyQt5: Graphics issues in QScrollArea for OSX · Issue #14160 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

PySide2/PyQt5: Graphics issues in QScrollArea for OSX #14160

@pshriwise

Description

@pshriwise

Bug report

Bug summary

Figure graphics aren't re-drawn correctly in a QScrollArea when using matplotlib>2.2.4 on OSX. I've put together a short program based on one of the examples which demonstrates this.

This seems specific to Macs as I've run the same code on Ubuntu without these issues.

Code for reproduction

import sys
import os
import random
import numpy as np

# PySide2 here gives the same result
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *

import matplotlib
# Make sure that we are using QT5
matplotlib.use('Qt5Agg')

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

class MyMplCanvas(FigureCanvas):
    """Ultimately, this is a QWidget (as well as a FigureCanvasAgg, etc.)."""

    def __init__(self, parent=None, width=5, height=4, dpi=100):
        fig = Figure(figsize=(width, height), dpi=dpi)
        self.axes = fig.add_subplot(111)

        self.compute_initial_figure()

        FigureCanvas.__init__(self, fig)
        self.setParent(parent)

        FigureCanvas.setSizePolicy(self,
                                   QSizePolicy.Expanding,
                                   QSizePolicy.Expanding)
        FigureCanvas.updateGeometry(self)

    def compute_initial_figure(self):
        pass

class MyStaticMplCanvas(MyMplCanvas):
    """Simple canvas with a sine plot."""

    def compute_initial_figure(self):
        t = np.linspace(0.0, 3.0, 2000)
        s = np.sin(2*np.pi*t)
        self.axes.plot(t, s)

class Widget(QWidget):

    def __init__(self, parent= None):
        super(Widget, self).__init__()

        #Container Widget
        widget = QWidget()
        #Layout of Container Widget
        layout = QVBoxLayout(self)

        fc = MyStaticMplCanvas()
        layout.addWidget(fc)
        widget.setLayout(layout)

        #Scroll Area Properties
        scroll = QScrollArea()
        scroll.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
        scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
        scroll.setWidgetResizable(False)
        scroll.setWidget(widget)

        #Scroll Area Layer add
        vLayout = QVBoxLayout(self)
        vLayout.addWidget(scroll)
        self.setLayout(vLayout)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    dialog = Widget()
    dialog.show()
    app.exec_()

The plot looks like this with window larger than the plot:

Screen Shot 2019-05-07 at 1 09 30 PM

Actual outcome

After resizing the window and scrolling to see the rest of the canvs, parts of the plot aren't drawn correctly both during and after the scroll event:

Screen Shot 2019-05-07 at 1 10 29 PM

This is true for any version of matplotlib>=2.2.4.

Expected outcome

When reverting the matplotlib version to 2.2.4 using pip3, the plot appears normally during and after scrolling:

Screen Shot 2019-05-07 at 1 12 14 PM

Matplotlib version

Matplotlib version >= 2.2.4 installed with pip3.
Python 3.7
OSX 10.14.3
Backend: backend_qt5agg
Other libraries (installed with pip3)

  • PySide2 (5.12.3)
  • PyQt5.QtCore.QT_VERSION_STR (5.12.2)
  • PyQt5.QtCore.PYQT_VERSION_STR (5.12.2)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0