Skip to content

Commit

Permalink
Merge pull request #31 from gpilab/develop
Browse files Browse the repository at this point in the history
Minor updates and Matplotlib 3 compatibility
  • Loading branch information
borupdaniel authored Feb 6, 2020
2 parents cddf459 + 2f10a61 commit ac00262
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 3,344 deletions.
4 changes: 4 additions & 0 deletions EXTRA_PKGS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## 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.

- [pyqtgraph]: a graphics library with some advantages over `matplotlib`. Currently being used in development of an image analysis node.
- [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.
11 changes: 2 additions & 9 deletions display/GPI/CrossSection_GPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@

import numpy as np
from matplotlib.figure import Figure
from matplotlib.backends.backend_qt4agg import (
FigureCanvasQTAgg as FigureCanvas,
NavigationToolbar2QT as NavigationToolbar)
from matplotlib.backends.backend_qt5agg import (
FigureCanvas, NavigationToolbar2QT as NavigationToolbar)

from scipy import ndimage

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

#self.data = self.get_data2()
self._data = None
self.create_main_frame()
self.on_draw()
Expand Down Expand Up @@ -91,9 +89,6 @@ def create_main_frame(self):
vbox.addWidget(self.mpl_toolbar)
self.setLayout(vbox)

def get_data2(self):
return np.arange(20).reshape([4, 5]).copy()

def on_draw(self):
self.fig.clear()
self.axes = self.fig.add_subplot(111)
Expand All @@ -104,8 +99,6 @@ def on_draw(self):
if self._data is None:
return

self.fig.hold(True)

# plot each set
# print "--------------------plot the data"
for data in self._data:
Expand Down
31 changes: 10 additions & 21 deletions display/GPI/Matplotlib_GPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,17 @@
import os
import matplotlib

import matplotlib as mpl
print('matplotlib version: ', mpl.__version__)
print('matplotlib version: ', matplotlib.__version__)

import gpi
from gpi import QtCore, QtGui, QtWidgets

import numpy as np
from matplotlib.figure import Figure
#from matplotlib.backend_bases import key_press_handler
from matplotlib.backends.backend_qt4agg import (
FigureCanvasQTAgg as FigureCanvas,
NavigationToolbar2QT as NavigationToolbar)
from matplotlib.backends.backend_qt4 import SubplotToolQt
from matplotlib.backends.backend_qt5agg import (
FigureCanvas, NavigationToolbar2QT as NavigationToolbar)
from matplotlib.backends.backend_qt5 import SubplotToolQt

class MainWin_close(QtWidgets.QMainWindow):
window_closed = gpi.Signal()
Expand Down Expand Up @@ -104,8 +102,6 @@ def _init_toolbar(self):
if tooltip_text is not None:
a.setToolTip(tooltip_text)

self.buttons = {}

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

# reference holder for subplots_adjust window
self.adj_window = None

###############################################################################
# -*- coding: utf-8 -*-
#
Expand All @@ -135,19 +128,14 @@ def _init_toolbar(self):
import os.path as osp

try:
import matplotlib.backends.qt4_editor.formlayout as formlayout
import matplotlib.backends.qt_editor.formlayout as formlayout
except:
try:
import matplotlib.backends.qt_editor.formlayout as formlayout
except:
formlayout = None
print("formlayout can't be found, line options will be disabled")
formlayout = None
print("formlayout can't be found, line options will be disabled")

#from matplotlib.backends.qt4_compat import QtGui
from matplotlib import markers

def get_icon(name):
import matplotlib
basedir = osp.join(matplotlib.rcParams['datapath'], 'images')
return QtGui.QIcon(osp.join(basedir, name))

Expand Down Expand Up @@ -268,7 +256,6 @@ def apply_callback(data):
figure = axes.get_figure()
figure.canvas.draw()

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

Expand Down Expand Up @@ -996,8 +983,10 @@ def on_key_press(self, event):

class ExternalNode(gpi.NodeAPI):

"""A Qt embedded plot window using the code from:
"""A Qt embedded plot window originally using the code from:
http://matplotlib.org/examples/user_interfaces/embedding_in_qt4_wtoolbar.html
Updated by DDB in Feb. 2020 using the qt5 code from:
https://matplotlib.org/examples/user_interfaces/embedding_in_qt5.html
keyboard shortcuts can be found here:
http://matplotlib.org/users/navigation_toolbar.html#navigation-keyboard-shortcuts
Expand Down
Loading

0 comments on commit ac00262

Please sign in to comment.