Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MRG] feat: post-processing function to adjust figures #893

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions hnn_core/gui/_viz_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,31 @@ def _add_figure(b, widgets, data, template_type, scale=0.95, dpi=96):
data['fig_idx']['idx'] += 1


def _postprocess_template(template_name, fig, idx,
use_ipympl=True, widgets=None):
"""Post-processes and re-renders plot templates with determined styles

Templates are constructed on panel-by-panel basis. If adjustments need to
be made based on information other plots in the figure, it is adjusted with
this function. For example, L2 and L5 dipole plots should have the same
y-axis range.
"""
if template_name not in ['Dipole Layers (3x1)']:
return

if template_name == 'Dipole Layers (3x1)':
# Make the L2 and L5 plots the same y-range
y_lims_list = [ax.get_ylim() for ax in fig.axes[0:2]]
y_lims = (np.min(y_lims_list), np.max(y_lims_list))
[ax.set_ylim(y_lims) for ax in fig.axes[0:2]]

# Re-render
if not use_ipympl:
_static_rerender(widgets, fig, idx)
else:
_dynamic_rerender(fig)


class _VizManager:
"""GUI visualization panel manager class.

Expand Down Expand Up @@ -958,6 +983,15 @@ def add_figure(self, b=None):
# paint fig in axis
self._simulate_edit_figure(fig_name, ax_name, sim_name,
plot_type, {}, "plot")
# template post-processing
fig_key = self.data['fig_idx']['idx'] - 1
_postprocess_template(template_name,
fig=self.figs[fig_key],
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ntolley
This was the PR I was showing you that was glitching and preventing further figure creation after deleting figures a few times. The issue was at this line where I was previously indexing self.figs with a the length of itself, because I assumed it was a list and I wanted the latest created figure. Turns out thatself.figs is a dict with ints as keys and the length of the dict doesn't correspond to the keys after you delete from and add to it. Using the int stored in self.data['fig_idx']['idx'] as the key fixed the issue.

idx=fig_key,
use_ipympl=self.use_ipympl,
widgets=self.widgets,
)

logger.info(f"Figure {template_name} for "
f"simulation {sim_name} "
"has been created"
Expand Down
Loading