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

Add limit check to add_event #49

Merged
merged 4 commits into from
Jul 20, 2022

Conversation

kohlerca
Copy link
Contributor

When using the add_event function to add events to one or more plots (e.g., the output of rasterplot_rates), if the Axes limits were changed and the Event object includes events out of the boundaries, they will be plotted regardless, leading to an unpleasant visualization in notebooks (saving the figure to a file seems to work).

import quantities as pq
from elephant.spike_train_generation import StationaryPoissonProcess
from viziphant.rasterplot import rasterplot_rates
from viziphant.events import add_event
import matplotlib.pyplot as plt
import neo

spiketrains = StationaryPoissonProcess(rate=20 * pq.Hz, t_stop= 2 * pq.s).generate_n_spiketrains(20)

event = neo.Event([0.25, 1, 1.75], units=pq.s, labels=['event_1', 'event_2', 'event_3'])

fig, ax = plt.subplots(figsize=(20,15))
ax = rasterplot_rates(spiketrains, ax=ax)
ax[0].set_xlim([0, 0.75])
ax[1].set_xlim([0, 0.75])
add_event([ax[1], ax[0]], event)

old

This PR fixes this by adding boundary checks (with respect to the last Axes in the list passed as the function axes parameter).

new

Copy link
Contributor

@Moritz-Alexander-Kern Moritz-Alexander-Kern left a comment

Choose a reason for hiding this comment

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

Thanks for this enhancement !

viziphant/events.py Show resolved Hide resolved
viziphant/events.py Show resolved Hide resolved
@Moritz-Alexander-Kern Moritz-Alexander-Kern merged commit 3bdd8c9 into master Jul 20, 2022
@Moritz-Alexander-Kern Moritz-Alexander-Kern deleted the feature/add_events_limits branch November 30, 2022 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants