Skip to content

Commit ac00262

Browse files
authored
Merge pull request #31 from gpilab/develop
Minor updates and Matplotlib 3 compatibility
2 parents cddf459 + 2f10a61 commit ac00262

File tree

6 files changed

+41
-3344
lines changed

6 files changed

+41
-3344
lines changed

EXTRA_PKGS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## This file is a collection of extra packages that are either being used in the development of new core nodes, or are of potential general interest to MRI researchers.
2+
3+
- [pyqtgraph]: a graphics library with some advantages over `matplotlib`. Currently being used in development of an image analysis node.
4+
- [BioSPPy](https://github.com/PIA-Group/BioSPPy): A toolbox for biosignal processing written in Python. Useful for processing physiology data. Only available from `pip`, not `conda`, making it difficult to use within GPI itself.

display/GPI/CrossSection_GPI.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@
4141

4242
import numpy as np
4343
from matplotlib.figure import Figure
44-
from matplotlib.backends.backend_qt4agg import (
45-
FigureCanvasQTAgg as FigureCanvas,
46-
NavigationToolbar2QT as NavigationToolbar)
44+
from matplotlib.backends.backend_qt5agg import (
45+
FigureCanvas, NavigationToolbar2QT as NavigationToolbar)
4746

4847
from scipy import ndimage
4948

@@ -54,7 +53,6 @@ class MatplotDisplay2(gpi.GenericWidgetGroup):
5453
def __init__(self, title, parent=None):
5554
super().__init__(title, parent)
5655

57-
#self.data = self.get_data2()
5856
self._data = None
5957
self.create_main_frame()
6058
self.on_draw()
@@ -91,9 +89,6 @@ def create_main_frame(self):
9189
vbox.addWidget(self.mpl_toolbar)
9290
self.setLayout(vbox)
9391

94-
def get_data2(self):
95-
return np.arange(20).reshape([4, 5]).copy()
96-
9792
def on_draw(self):
9893
self.fig.clear()
9994
self.axes = self.fig.add_subplot(111)
@@ -104,8 +99,6 @@ def on_draw(self):
10499
if self._data is None:
105100
return
106101

107-
self.fig.hold(True)
108-
109102
# plot each set
110103
# print "--------------------plot the data"
111104
for data in self._data:

display/GPI/Matplotlib_GPI.py

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,17 @@
3838
import os
3939
import matplotlib
4040

41-
import matplotlib as mpl
42-
print('matplotlib version: ', mpl.__version__)
41+
print('matplotlib version: ', matplotlib.__version__)
4342

4443
import gpi
4544
from gpi import QtCore, QtGui, QtWidgets
4645

4746
import numpy as np
4847
from matplotlib.figure import Figure
4948
#from matplotlib.backend_bases import key_press_handler
50-
from matplotlib.backends.backend_qt4agg import (
51-
FigureCanvasQTAgg as FigureCanvas,
52-
NavigationToolbar2QT as NavigationToolbar)
53-
from matplotlib.backends.backend_qt4 import SubplotToolQt
49+
from matplotlib.backends.backend_qt5agg import (
50+
FigureCanvas, NavigationToolbar2QT as NavigationToolbar)
51+
from matplotlib.backends.backend_qt5 import SubplotToolQt
5452

5553
class MainWin_close(QtWidgets.QMainWindow):
5654
window_closed = gpi.Signal()
@@ -104,8 +102,6 @@ def _init_toolbar(self):
104102
if tooltip_text is not None:
105103
a.setToolTip(tooltip_text)
106104

107-
self.buttons = {}
108-
109105
# Add the x,y location widget at the right side of the toolbar
110106
# The stretch factor is 1 which means any resizing of the toolbar
111107
# will resize this label instead of the buttons.
@@ -119,9 +115,6 @@ def _init_toolbar(self):
119115
labelAction = self.addWidget(self.locLabel)
120116
labelAction.setVisible(True)
121117

122-
# reference holder for subplots_adjust window
123-
self.adj_window = None
124-
125118
###############################################################################
126119
# -*- coding: utf-8 -*-
127120
#
@@ -135,19 +128,14 @@ def _init_toolbar(self):
135128
import os.path as osp
136129

137130
try:
138-
import matplotlib.backends.qt4_editor.formlayout as formlayout
131+
import matplotlib.backends.qt_editor.formlayout as formlayout
139132
except:
140-
try:
141-
import matplotlib.backends.qt_editor.formlayout as formlayout
142-
except:
143-
formlayout = None
144-
print("formlayout can't be found, line options will be disabled")
133+
formlayout = None
134+
print("formlayout can't be found, line options will be disabled")
145135

146-
#from matplotlib.backends.qt4_compat import QtGui
147136
from matplotlib import markers
148137

149138
def get_icon(name):
150-
import matplotlib
151139
basedir = osp.join(matplotlib.rcParams['datapath'], 'images')
152140
return QtGui.QIcon(osp.join(basedir, name))
153141

@@ -268,7 +256,6 @@ def apply_callback(data):
268256
figure = axes.get_figure()
269257
figure.canvas.draw()
270258

271-
# formlayout disappears in matplotlib 1.4.0
272259
if formlayout is not None:
273260
data = formlayout.fedit(datalist, title="Figure options", parent=parent, icon=get_icon('qt4_editor_options.svg'), apply=apply_callback)
274261

@@ -996,8 +983,10 @@ def on_key_press(self, event):
996983

997984
class ExternalNode(gpi.NodeAPI):
998985

999-
"""A Qt embedded plot window using the code from:
986+
"""A Qt embedded plot window originally using the code from:
1000987
http://matplotlib.org/examples/user_interfaces/embedding_in_qt4_wtoolbar.html
988+
Updated by DDB in Feb. 2020 using the qt5 code from:
989+
https://matplotlib.org/examples/user_interfaces/embedding_in_qt5.html
1001990
keyboard shortcuts can be found here:
1002991
http://matplotlib.org/users/navigation_toolbar.html#navigation-keyboard-shortcuts
1003992

0 commit comments

Comments
 (0)