From a8014b3d8b3f8bf630aca161bfb272b4a0f2b911 Mon Sep 17 00:00:00 2001 From: Amr Date: Mon, 31 Oct 2022 19:28:50 -0400 Subject: [PATCH] Version 0.4.3 (Matplotlib 3.6.0 compatible) removed calls to Axes.change_geometry() --- setup.py | 2 +- spmclient/controls/colormap_chooser.py | 55 +++++++++++++--------- spmclient/controls/gait_analysis_window.py | 38 +++++++-------- spmclient/ui/gui/xml/ui_about_dialogue.py | 2 +- spmclient/ui/gui/xml/ui_about_dialogue.ui | 2 +- 5 files changed, 51 insertions(+), 48 deletions(-) diff --git a/setup.py b/setup.py index ef45523..7b9bdbf 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ setup( name = 'movementrx', - version = '0.4.1', + version = '0.4.3', description = 'Gait analysis using One-Dimensional Statistical Parametric Mapping', author = 'Amr ALHOSSARY', author_email = 'aalhossary@ntu.edu.sg', diff --git a/spmclient/controls/colormap_chooser.py b/spmclient/controls/colormap_chooser.py index 2b57a46..dd9cc0d 100644 --- a/spmclient/controls/colormap_chooser.py +++ b/spmclient/controls/colormap_chooser.py @@ -1,17 +1,21 @@ import sys +from typing import cast from PyQt5 import QtCore from PyQt5.QtWidgets import QDialog, QApplication from matplotlib import cm +from matplotlib.axes import Axes from matplotlib.colors import Normalize +from matplotlib.figure import Figure from spmclient.ui.gui.xml.ui_colormap_chooser import Ui_colorMapChooser -from spmclient.ui.gui.xml.customcomponents import Singleton +from spmclient.ui.gui.xml.customcomponents import Singleton, LegendMplCanvas class ColorMapChooserMeta(Singleton, QDialog.__class__, Ui_colorMapChooser.__class__): pass + class ColorMapChooser(QDialog, Ui_colorMapChooser, metaclass = ColorMapChooserMeta): def __init__(self): @@ -26,25 +30,27 @@ def __init__(self): def setupUi(self, colorMapChooser: Ui_colorMapChooser): super().setupUi(colorMapChooser) + @staticmethod + def prepare_figure(colormap_legend: LegendMplCanvas): + figure = colormap_legend.figure + ax = colormap_legend.ax + if ax.get_subplotspec().get_geometry() == (1, 1, 0, 0): + figure = cast(Figure, ax.figure) + figure.clear() + axs = figure.subplots(1, 3) + for i in [0, 2]: + axi = cast(Axes, axs[i]) + axi.set_visible(False) + ax = cast(Axes, axs[1]) + figure.ax = ax + ax.clear() + return figure, ax + @QtCore.pyqtSlot() def update_legend(self): print('update called') - ax1 = self.individual_colormap_legend.ax - if ax1.get_geometry() == (1, 1, 1): - ax1.change_geometry(1, 3, 2) - ax1.clear() - ax2 = self.three_components_colormap_legend.ax - if ax2.get_geometry() == (1, 1, 1): - ax2.change_geometry(1, 3, 2) - ax2.clear() - - figure1 = self.individual_colormap_legend.figure -# figure1.gca().set_axis_off() - figure2 = self.three_components_colormap_legend.figure -# figure2.gca().set_axis_off() - -# if ax1 is not figure1.gca(): -# print('=======', ax1, figure1.gca()) + figure1, ax1 = ColorMapChooser.prepare_figure(self.individual_colormap_legend) + figure2, ax2 = ColorMapChooser.prepare_figure(self.three_components_colormap_legend) num_levels1 = self.individ_num_levels_spinBox.value() num_levels2 = self.threecomp_num_levels_spinBox.value() @@ -59,12 +65,15 @@ def update_legend(self): self.norm1 = Normalize(vmin=self.individ_min_value_spinbox.value(), vmax=self.individ_max_value_spinbox.value()) self.norm2 = Normalize(vmin=self.threecomp_min_value_spinbox.value(), vmax=self.threecomp_max_value_spinbox.value()) - colorbar1 = figure1.colorbar(cm.ScalarMappable(norm=self.norm1, cmap=self.cmap1), cax=ax1, orientation="vertical", - use_gridspec=True, fraction=1.0, shrink=1.0, extend='both', - ) - colorbar2 = figure2.colorbar(cm.ScalarMappable(norm=self.norm2, cmap=self.cmap2), cax=ax2, orientation="vertical", - use_gridspec=True, fraction=1.0, shrink=1.0, extend='both', - ) + # print(ax1.get_subplotspec(), figure1.bbox, ax1.get_subplotspec().get_position(figure=figure1)) + colorbar1 = figure1.colorbar(cm.ScalarMappable(norm=self.norm1, cmap=self.cmap1), + cax=ax1, orientation="vertical", + fraction=1.0, shrink=1.0, + extend='both', extendfrac='auto',pad=0.0) + colorbar2 = figure2.colorbar(cm.ScalarMappable(norm=self.norm2, cmap=self.cmap2), + cax=ax2, orientation="vertical", + fraction=1.0, shrink=1.0, + extend='both', extendfrac='auto',pad=0.0) self.individual_colormap_legend.canvas.draw() self.three_components_colormap_legend.canvas.draw() diff --git a/spmclient/controls/gait_analysis_window.py b/spmclient/controls/gait_analysis_window.py index 42acc85..b9e2053 100644 --- a/spmclient/controls/gait_analysis_window.py +++ b/spmclient/controls/gait_analysis_window.py @@ -11,6 +11,7 @@ from matplotlib import cm from matplotlib.axes import Axes from matplotlib.colors import Normalize +from matplotlib.gridspec import GridSpec from matplotlib.image import AxesImage from matplotlib.lines import Line2D # print("going to import matplotlib.pyplot as plt") @@ -255,45 +256,40 @@ def add_colorbar_to_legend(self, axes_image1, axes_image2): cmc = ColorMapChooser() figure = self.legend_heatmap_panel.figure - ax1 = self.legend_heatmap_panel.ax - - ax1.change_geometry(1, 5, 2) + figure.clear() + + # ax1.set_subplotspec(GridSpec(1, 5, figure=ax1.figure)[1]) # change_geometry(1, 5, 2) + axs = figure.subplots(1, 5) + for i in [0, 2, 4]: + axi = cast(Axes, axs[i]) + axi.set_visible(False) + ax1 = self.legend_heatmap_panel.ax = cast(Axes, axs[1]) + ax2 = axs[3] ax1.clear() + ax2.clear() if axes_image1: cmap1 = cmc.cmap1 norm1 = cmc.norm1 labels = ['Mild', 'Mod', 'Severe', 'Xtreme'] for j, lab in enumerate(labels): - ax1.text(0.9, norm1.vmin + ((2 * j + 1) / (2 * len(labels)) * (norm1.vmax - norm1.vmin)), + ax1.text(0.0, norm1.vmin + ((2 * j + 1) / (2 * len(labels)) * (norm1.vmax - norm1.vmin)), lab, ha='right', va='center_baseline') figure.colorbar(cm.ScalarMappable(norm=norm1, cmap=cmap1), orientation="vertical", - cax=ax1, use_gridspec=True, fraction=1.0, shrink=1.0, extend='both', - ticks=np.arange(norm1.vmax + 1), - # anchor = (0.0, 0.5), panchor = (0.0, 0.5), drawedges=True, pad=0.2 + cax=ax1, use_gridspec=True, fraction=1.0, shrink=1.0, extend='both', extendfrac='auto', + ticks=np.arange(norm1.vmax + 1) ) else: ax1.axis("off") cmap2 = cmc.cmap2 norm2 = cmc.norm2 - # figure = self.legend_heatmap_panel.figure - for ax in figure.get_axes(): - if 'ax2' == ax.get_label(): - ax2 = ax - break - else: # Loop else (no_break) - ax2 = figure.add_subplot(1, 5, 4, label='ax2') # Remember having a unique label. - - ax2.clear() - # ax.change_geometry(1, 5, 4) - # figure.gca().set_axis_off() if axes_image2: figure.colorbar(cm.ScalarMappable(norm=norm2, cmap=cmap2), orientation="vertical", - cax=ax2, use_gridspec=True, fraction=1.0, shrink=1.0, extend='both', - ticks=np.arange(norm2.vmax + 1), + cax=ax2, use_gridspec=True, fraction=1.0, shrink=1.0, extend='both', extendfrac='auto', + ticks=np.arange(norm2.vmax + 1) ) else: ax2.axis("off") @@ -512,8 +508,6 @@ def show_analysis_result(self, ankle_x_only: bool = False): if d is None: analysis_legend_image2 = draw_heatmap(mose_canvas, temp_display_data, norm=norm2, cmap=cmap2) else: - if i_d > 0: - continue analysis_legend_image1 = draw_heatmap(mose_canvas, temp_display_data, norm=norm1, cmap=cmap1) # Add vertical line diff --git a/spmclient/ui/gui/xml/ui_about_dialogue.py b/spmclient/ui/gui/xml/ui_about_dialogue.py index 57f3512..ede8d03 100644 --- a/spmclient/ui/gui/xml/ui_about_dialogue.py +++ b/spmclient/ui/gui/xml/ui_about_dialogue.py @@ -46,7 +46,7 @@ def setupUi(self, About): def retranslateUi(self, About): _translate = QtCore.QCoreApplication.translate About.setWindowTitle(_translate("About", "Dialog")) - self.label.setText(_translate("About", "

MovementRx 0.4.2

Developped in Rehabilitation Research Institute of Singapore (RRIS)

Application credit goes to

")) + self.label.setText(_translate("About", "

MovementRx 0.4.3

Developped in Rehabilitation Research Institute of Singapore (RRIS)

Application credit goes to

")) from spmclient import resources_rc diff --git a/spmclient/ui/gui/xml/ui_about_dialogue.ui b/spmclient/ui/gui/xml/ui_about_dialogue.ui index a0626f1..58dec66 100644 --- a/spmclient/ui/gui/xml/ui_about_dialogue.ui +++ b/spmclient/ui/gui/xml/ui_about_dialogue.ui @@ -17,7 +17,7 @@ - <html><head/><body><p align="center"><span style=" font-size:14pt; font-weight:600;">MovementRx 0.4.2</span></p><p align="center"><span style=" font-size:10pt;">Developped in </span><a href="http://rris.ntu.edu.sg/"><span style=" font-size:10pt; text-decoration: underline; color:#0000ff;">Rehabilitation Research Institute of Singapore (RRIS)</span></a></p><p align="center"><span style=" font-size:10pt;">Application credit goes to</span></p></body></html> + <html><head/><body><p align="center"><span style=" font-size:14pt; font-weight:600;">MovementRx 0.4.3</span></p><p align="center"><span style=" font-size:10pt;">Developped in </span><a href="http://rris.ntu.edu.sg/"><span style=" font-size:10pt; text-decoration: underline; color:#0000ff;">Rehabilitation Research Institute of Singapore (RRIS)</span></a></p><p align="center"><span style=" font-size:10pt;">Application credit goes to</span></p></body></html>