Skip to content

Commit

Permalink
Version 0.4.3 (Matplotlib 3.6.0 compatible)
Browse files Browse the repository at this point in the history
removed calls to Axes.change_geometry()
  • Loading branch information
aalhossary committed Nov 1, 2022
1 parent 895b66e commit a8014b3
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 48 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '[email protected]',
Expand Down
55 changes: 32 additions & 23 deletions spmclient/controls/colormap_chooser.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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()
Expand All @@ -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()

Expand Down
38 changes: 16 additions & 22 deletions spmclient/controls/gait_analysis_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spmclient/ui/gui/xml/ui_about_dialogue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "<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>"))
self.label.setText(_translate("About", "<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>"))

from spmclient import resources_rc

Expand Down
2 changes: 1 addition & 1 deletion spmclient/ui/gui/xml/ui_about_dialogue.ui
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="label">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-size:14pt; font-weight:600;&quot;&gt;MovementRx 0.4.2&lt;/span&gt;&lt;/p&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-size:10pt;&quot;&gt;Developped in &lt;/span&gt;&lt;a href=&quot;http://rris.ntu.edu.sg/&quot;&gt;&lt;span style=&quot; font-size:10pt; text-decoration: underline; color:#0000ff;&quot;&gt;Rehabilitation Research Institute of Singapore (RRIS)&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-size:10pt;&quot;&gt;Application credit goes to&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-size:14pt; font-weight:600;&quot;&gt;MovementRx 0.4.3&lt;/span&gt;&lt;/p&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-size:10pt;&quot;&gt;Developped in &lt;/span&gt;&lt;a href=&quot;http://rris.ntu.edu.sg/&quot;&gt;&lt;span style=&quot; font-size:10pt; text-decoration: underline; color:#0000ff;&quot;&gt;Rehabilitation Research Institute of Singapore (RRIS)&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-size:10pt;&quot;&gt;Application credit goes to&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
Expand Down

0 comments on commit a8014b3

Please sign in to comment.