diff --git a/doc/whats_new.rst b/doc/whats_new.rst index 5e32893723..b57d934f1c 100644 --- a/doc/whats_new.rst +++ b/doc/whats_new.rst @@ -35,6 +35,9 @@ Changelog - Add feature to convert param and json files to HDF5 format, by `George Dang`_ in :gh:`723` + +- Fixed figure annotation overlap in multiple sub-plots, + by `Camilo Diaz`_ in :gh:`741` - Fix bug in :func:`~hnn_core/network/pick_connection` where connections are returned for cases when there should be no valid matches, by `George Dang`_ @@ -466,3 +469,5 @@ People who contributed to this release (in alphabetical order): .. _Steven Brandt: https://github.com/spbrandt .. _Kaisu Lankinen: https://github.com/klankinen .. _George Dang: https://github.com/gtdang +.. _Camilo Diaz: https://github.com/kmilo9999 + diff --git a/hnn_core/gui/_viz_manager.py b/hnn_core/gui/_viz_manager.py index b8f1e0e888..5821ad22e8 100644 --- a/hnn_core/gui/_viz_manager.py +++ b/hnn_core/gui/_viz_manager.py @@ -362,13 +362,31 @@ def _plot_on_axes(b, simulations_widget, widgets_plot_type, else: dpl = dpls_processed rmse = _rmse(dpl, target_dpl_processed, t0, tstop) - # Show the RMSE between the two dipoles. - ax.annotate(f'RMSE({sim_name}, {target_sim_name}): {rmse:.4f}', - xy=(0.95, 0.05), - xycoords='axes fraction', - horizontalalignment='right', - verticalalignment='bottom', - fontsize=12) + annotation_text = f'RMSE({sim_name}, {target_sim_name}): {rmse:.4f}' + + # find subplot's annotation + annotation = next((child for child in ax.get_children() + if isinstance(child, plt.Annotation)), None) + + # if the subplot already has an annotation, update its text. + # Otherwise, create a new one. + if annotation is not None: + annotation.set_text(annotation_text) + else: + ax.annotate(annotation_text, + xy=(0.95, 0.05), + xycoords='axes fraction', + horizontalalignment='right', + verticalalignment='bottom', + fontsize=12) + + rmse_logger_text = (f'RMSE {rmse:.4f} (' + f'{sim_name} smooth:{dipole_smooth.value} ' + f'scale:{dipole_scaling.value} \n' + f'{target_sim_name} smooth:{data_smooth.value} ' + f'scale:{data_scaling.value})') + + logger.info(rmse_logger_text) existing_plots.children = (*existing_plots.children, Label(f"{sim_name}: {plot_type}"))