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

fix: clear_axis contextually removes second axis #929

Merged
Merged
Show file tree
Hide file tree
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
10 changes: 6 additions & 4 deletions hnn_core/gui/_viz_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,10 +526,12 @@ def _clear_axis(b, widgets, data, fig_idx, fig, ax, widgets_plot_type,
existing_plots, add_plot_button):
ax.clear()

# Remove "plot_spikes_hist"'s inverted second axes object, if exists
for axis in fig.axes:
if axis._label == "Inverted second axis":
axis.remove()
# Remove "plot_spikes_hist"'s inverted second axes object, if exists, and
# if the axis you are clearing is the spike histogram
if ax._label == "Spike histogram":
for axis in fig.axes:
if axis._label == "Inverted spike histogram":
axis.remove()

# remove attached colorbar if exists
if hasattr(fig, f'_cbar-ax-{id(ax)}'):
Expand Down
5 changes: 5 additions & 0 deletions hnn_core/tests/test_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,11 @@ def test_gui_visualization(setup_gui):
for viz_type in _plot_types:
gui._simulate_viz_action("edit_figure", figname,
axname, 'default', viz_type, {}, 'clear')
# Check that extra axes have been successfully removed
assert len(gui.viz_manager.figs[figid].axes) == 1
# Check if data on the axes has been successfully cleared
assert not gui.viz_manager.figs[figid].axes[0].has_data()

gui._simulate_viz_action("edit_figure", figname,
axname, 'default', viz_type, {}, 'plot')
# Check if data is plotted on the axes
Expand Down
3 changes: 2 additions & 1 deletion hnn_core/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,6 @@ def plot_spikes_hist(cell_response, trial_idx=None, ax=None, spike_types=None,
ax1.hist(plot_data, bins,
label=spike_label, color=hist_color, **kwargs_hist)
# Need to add label for easy removal later
ax1.set_label("Inverted second axis")

# Set the y-limits based on the maximum across both axes
if ax1 is not None:
Expand All @@ -549,13 +548,15 @@ def plot_spikes_hist(cell_response, trial_idx=None, ax=None, spike_types=None,
ax.set_ylim(0, y_max)
ax1.set_ylim(0, y_max)
ax1.invert_yaxis()
ax1.set_label("Inverted spike histogram")

if len(cell_response.times) > 0:
ax.set_xlim(left=0, right=cell_response.times[-1])
else:
ax.set_xlim(left=0)

ax.set_ylabel("Counts")
ax.set_label("Spike histogram")

if ax1 is not None:
# Combine legends
Expand Down
Loading