Skip to content

Commit

Permalink
save radar plot
Browse files Browse the repository at this point in the history
  • Loading branch information
mattclifford1 committed Jul 18, 2024
1 parent 7ba27ce commit 0cbf4a1
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 12 deletions.
49 changes: 43 additions & 6 deletions IQM_Vis/UI/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ def display_metric_range_plot(self):
plot.show()

def plot_metric_range_mlp(self, i):
# TODO: reduce copy of code from above function
# make sure we have somethign to plot
if not hasattr(self, 'metric_over_range_results'):
return
Expand All @@ -383,12 +384,7 @@ def plot_metric_range_mlp(self, i):
fig.canvas.manager.set_window_title(
f"{self.data_stores[i].get_reference_image_name()}-{trans_to_plot}")

# set the default save path
image_name = f"{self.data_stores[i].get_reference_image_name()}-export"
save_path = os.path.join(self.default_save_dir, image_name)
if not os.path.exists(save_path):
save_path = self.default_save_dir
gui_utils.matplotlib.rcParams['savefig.directory'] = save_path
self.set_save_dir_mpl(i)

# show fig in new window
gui_utils.matplotlib.pyplot.show()
Expand Down Expand Up @@ -436,6 +432,47 @@ def plot_radar_graph(self, results, i):
axes = self.widget_row[i]['metrics']['avg']['data']
radar_plotter = plot_utils.get_radar_plots_avg_plots(results, metrics_names, transformation_names, axes, self.plot_data_lim)
radar_plotter.show()

def plot_radar_mlp(self, i):
# TODO: reduce copy of code from above function
# make sure we have somethign to plot
if not hasattr(self, 'metric_over_range_results'):
return

# plot our data on a new axis
fig = gui_utils.plt.figure()
axes = fig.add_subplot(projection='polar')
all_trans = list(self.checked_transformations.keys())
transformation_names = list(self.sliders['transforms'].keys())
if 'avg' in self.widget_row[i]['metrics'].keys():
# get current metrics used for this data_store
metrics_names = []
for metric in self.data_stores[i].metrics:
if metric in self.checked_metrics:
metrics_names.append(metric)

if len(metrics_names) == 0:
return

plot = plot_utils.get_radar_plots_avg_plots(
self.metric_over_range_results[i], metrics_names, transformation_names, axes, self.plot_data_lim)
plot.set_style()

fig.canvas.manager.set_window_title(
f"{self.data_stores[i].get_reference_image_name()}-radar")

self.set_save_dir_mpl(i)

# show fig in new window
gui_utils.matplotlib.pyplot.show()

def set_save_dir_mpl(self, i=0):
# set the default save path
image_name = f"{self.data_stores[i].get_reference_image_name()}-export"
save_path = os.path.join(self.default_save_dir, image_name)
if not os.path.exists(save_path):
os.makedirs(save_path)
gui_utils.matplotlib.rcParams['savefig.directory'] = save_path

'''
metric correlation plots
Expand Down
5 changes: 4 additions & 1 deletion IQM_Vis/UI/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ def _init_generic_layout(self):
graph = QGridLayout()
graph.addWidget(self.widget_row[i]['metrics']['avg']['data'], 0, 0, im_height, im_width)
avg_graph.addLayout(graph) # need for matplotlib? - test this... (grid)
graph_save = QHBoxLayout()
graph_save.addWidget(self.widget_row[i]['metrics']['avg']['save_button'])
avg_graph.addLayout(graph_save)
utils.add_layout_to_tab(self.tabs['graph'], avg_graph, 'Radar')
if 'range' in self.widget_row[i]['metrics'].keys():
range_graph = QVBoxLayout()
Expand All @@ -93,8 +96,8 @@ def _init_generic_layout(self):
range_graph.addLayout(graph_controls)
graph_save = QHBoxLayout()
graph_save.addWidget(self.widget_row[i]['metrics']['range']['save_button'])
utils.add_layout_to_tab(self.tabs['graph'], range_graph, 'Range')
range_graph.addLayout(graph_save)
utils.add_layout_to_tab(self.tabs['graph'], range_graph, 'Range')
if 'correlation' in self.widget_row[i]['metrics'].keys():
correlation_graph = QVBoxLayout()
correlation_graph.addWidget(self.widget_row[i]['metrics']['correlation']['label'])
Expand Down
9 changes: 4 additions & 5 deletions IQM_Vis/UI/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def _init_widgets(self):
self.widget_row[i]['metrics']['info']['data'] = QLabel(self)
self.widget_row[i]['metrics']['info']['data'].setAlignment(Qt.AlignmentFlag.AlignCenter)
self.widget_row[i]['metrics']['info']['data'].setText('')
# metrics avgerage graphs
# metrics average graphs
if self.metrics_avg_graph:
self.widget_row[i]['metrics']['avg'] = {}
self.widget_row[i]['metrics']['avg']['label'] = QLabel(self)
Expand All @@ -83,6 +83,8 @@ def _init_widgets(self):
self.widget_row[i]['metrics']['avg']['data'] = gui_utils.MplCanvas(size=(self.graph_size/10, self.graph_size/10), polar=True)
self.widget_row[i]['metrics']['avg']['data'].setToolTip('Mean metric value over the range of each transform.')
self.widget_row[i]['metrics']['avg']['data'].setStyleSheet(self.tool_tip_style)
self.widget_row[i]['metrics']['avg']['save_button'] = QPushButton('Adjust or Save', self)
self.widget_row[i]['metrics']['avg']['save_button'].clicked.connect(partial(self.plot_radar_mlp, i))
if self.metric_range_graph:
self.widget_row[i]['metrics']['range'] = {}
self.widget_row[i]['metrics']['range']['label'] = QLabel(self)
Expand All @@ -92,10 +94,7 @@ def _init_widgets(self):
self.widget_row[i]['metrics']['range']['data'].setToolTip('Single transformation value range for all metrics.')
self.widget_row[i]['metrics']['range']['data'].setStyleSheet(self.tool_tip_style)
self.widget_row[i]['metrics']['range']['save_button'] = QPushButton('Adjust or Save', self)
self.widget_row[i]['metrics']['range']['save_button'].clicked.connect(
# partial(self.open_mlp_new, self.widget_row[i]['metrics']['range']['data'])
partial(self.plot_metric_range_mlp, i)
)
self.widget_row[i]['metrics']['range']['save_button'].clicked.connect(partial(self.plot_metric_range_mlp, i))
self.widget_row[i]['metrics']['correlation'] = {}
self.widget_row[i]['metrics']['correlation']['label'] = QLabel(self)
self.widget_row[i]['metrics']['correlation']['label'].setAlignment(Qt.AlignmentFlag.AlignCenter)
Expand Down

0 comments on commit 0cbf4a1

Please sign in to comment.