| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Dear maintainers, first of all: sorry if I've broken any bug reporting rules, I'm quite new to this.
Bug summary
The navigation history seems to be broken in matplotlib 2.1.0. I've tested the following code with v2.1.0 and v2.0.0 and it works fine with v2.0.0 and in v2.1.0, the home & back button behave very strangely.
GUIControllerClass.py
from PyQt5.QtWidgets import QMainWindow, QWidget
from PyQt5.QtWidgets import QFileDialog
from GUI import Ui_foo
from factory import factory as parser
from utils import coefficients_to_dbc
import matplotlib
from matplotlib.ticker import EngFormatter
import numpy as np
class GUIController(QMainWindow):
def __init__(self, parent=None):
QWidget.__init__(self, parent)
self.ui = Ui_foo()
self.ui.setupUi(self)
self.ui.btn_clr_graph.clicked.connect(self.clear_graph)
self.ui.btn_file.clicked.connect(self.select_file)
print(matplotlib.__version__)
self.clear_graph()
def select_file(self):
# I use this section
# ----------------------------------
# options = QFileDialog.Options()
# options |= QFileDialog.DontUseNativeDialog
# file, _ = QFileDialog.getOpenFileName(
# self, 'QFileDialog.getOpenFileName()', '/home/rgr/Documents/KULeuven',
# 'All Files (*);;', options=options)
# bar = parser(file, revision=10)
# self.plot_graph(
# bar.frequencies,
# coefficients_to_dbc(bar.coefficients))
# del bar
#----------------------------------
#but it works the same with this, and yes, I've tested it
frequencies = np.random.random_integers(500E6, 700E6,size=(1000))
coefficients_dbc = np.random.random_integers(-3,3, size=(1000))
self.plot_graph(frequencies, coefficients_dbc)
def plot_graph(self, frequencies, coefficients_dbc):
graph = self.ui.graph.canvas.axes
graph.plot(frequencies, coefficients_dbc)
# self.cursor = mplcursors.cursor(graph.lines, hover=True)
graph.set_ylim(min(0, min(coefficients_dbc),
graph.get_ylim()[0]),
max(0, max(coefficients_dbc),
graph.get_ylim()[1]))
self.ui.graph.canvas.draw()
def clear_graph(self):
graph = self.ui.graph.canvas.axes
graph.clear()
graph.set_ylim(-3, 3)
formatter = EngFormatter(unit='Hz', places=2)
graph.xaxis.set_major_formatter(formatter)
formatter = EngFormatter(unit='dBc', places=2)
graph.yaxis.set_major_formatter(formatter)
graph.grid(True)
self.ui.graph.canvas.draw()
mplwidget.py
from PyQt5 import QtWidgets
from matplotlib.backends.backend_qt5agg import (
FigureCanvasQTAgg as FigureCanvas,
NavigationToolbar2QT as NavigationToolbar)
from matplotlib.figure import Figure
class MplCanvas(FigureCanvas):
"""Class to represent the FigureCanvas widget"""
def __init__(self):
self.fig = Figure()
self.axes = self.fig.add_subplot(111)
# initialization of the canvas
FigureCanvas.__init__(self, self.fig)
# we define the widget as expandable
FigureCanvas.setSizePolicy(self,
QtWidgets.QSizePolicy.Expanding,
QtWidgets.QSizePolicy.Expanding)
# notify the system of updated policy
FigureCanvas.updateGeometry(self)
class MplWidget(QtWidgets.QWidget): # pylint: disable= too-few-public-methods
"""Widget defined in Qt Designer"""
def __init__(self, parent=None):
''' initialization of Qt MainWindow widget'''
QtWidgets.QWidget.__init__(self, parent)
# set the canvas to the Matplotlib widget
self.canvas = MplCanvas()
# create a vertical box layout
self.vbl = QtWidgets.QVBoxLayout()
self.toolbar = NavigationToolbar(self.canvas, parent, coordinates=True)
# add mpl widget to vertical box
self.vbl.addWidget(self.canvas)
self.vbl.addWidget(self.toolbar)
# set the layout to th vertical box
self.setLayout(self.vbl)test_gui.py
import sys
from GUIControllerClass import GUIController
from PyQt5 import QtWidgets
if __name__ == "__main__":
APP = QtWidgets.QApplication(sys.argv)
GUI = GUIController()
GUI.show()
sys.exit(APP.exec_())GUI.py
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'GUI.ui'
#
# Created by: PyQt5 UI code generator 5.7
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_foo(object):
def setupUi(self, foo):
foo.setObjectName("foo")
foo.resize(988, 891)
self.centralwidget = QtWidgets.QWidget(foo)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
self.verticalLayout.setObjectName("verticalLayout")
self.tabs = QtWidgets.QTabWidget(self.centralwidget)
self.tabs.setObjectName("tabs")
self.tab_foo = QtWidgets.QWidget()
self.tab_foo.setObjectName("tab_foo")
self.gridLayout_2 = QtWidgets.QGridLayout(self.tab_foo)
self.gridLayout_2.setContentsMargins(0, 0, 0, 0)
self.gridLayout_2.setObjectName("gridLayout_2")
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
self.btn_file = QtWidgets.QPushButton(self.tab_foo)
self.btn_file.setObjectName("btn_file")
self.horizontalLayout.addWidget(self.btn_file)
self.btn_clr_graph = QtWidgets.QPushButton(self.tab_foo)
self.btn_clr_graph.setObjectName("btn_clr_graph")
self.horizontalLayout.addWidget(self.btn_clr_graph)
self.gridLayout_2.addLayout(self.horizontalLayout, 0, 0, 1, 3)
self.graph = MplWidget(self.tab_foo)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.graph.sizePolicy().hasHeightForWidth())
self.graph.setSizePolicy(sizePolicy)
self.graph.setObjectName("graph")
self.gridLayout_2.addWidget(self.graph, 1, 0, 1, 2)
self.tabs.addTab(self.tab_foo, "")
self.verticalLayout.addWidget(self.tabs)
foo.setCentralWidget(self.centralwidget)
self.retranslateUi(foo)
self.tabs.setCurrentIndex(0)
QtCore.QMetaObject.connectSlotsByName(foo)
foo.setTabOrder(self.tabs, self.btn_file)
def retranslateUi(self, foo):
_translate = QtCore.QCoreApplication.translate
foo.setWindowTitle(_translate("foo", "foo"))
self.btn_file.setText(_translate("foo", "plot"))
self.btn_clr_graph.setText(_translate("foo", "Clear graph"))
self.tabs.setTabText(self.tabs.indexOf(self.tab_foo), _translate("foo", "foo"))
from mplwidget import MplWidgetActual outcome
In 2.1.0, the figure plots OK, but if I zoom in on it and then click on 'back' or 'home', it doesn't go back to my figure. In 2.0.0 everything works as expected.
Matplotlib version
I've installed matplotlib with pip3.5, tested for 2.1.0, then uninstalled matplotlib and reinstalled forcing the version to 2.0.0:
sudo pip3.5 install -Iv matplotlib==2.0.0I've also confirmed the bug exists both for pyqt4 as well as pyqt5.
| Back | FazBrowse Home | New Git URL |
Activity
fredrik-1 commented on Feb 14, 2018
That bug is fixed in 2.1.1
jklymak commented on Feb 14, 2018
Yes this was fixed.