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 grid plots on newer matplotlib versions #173

Merged
merged 1 commit into from
Oct 3, 2024

Conversation

b-grimaud
Copy link
Contributor

Grid plots fail on matplotlib 3.9.2 with the following trace :

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[17], line 1
----> 1 mr.plot_waveforms(recgen, electrode='max', cmap='rainbow')

File ~/Documents/GitHub/MEArec/src/MEArec/tools.py:3339, in plot_waveforms(recgen, spiketrain_id, ax, color, cmap, electrode, max_waveforms, ncols, cut_out)
   3336     nrows = 1
   3337     ncols = len(spiketrain_id)
-> 3339 gs = gridspec.GridSpecFromSubplotSpec(nrows, ncols, subplot_spec=ax)
   3341 # find ylim
   3342 min_wf = 0

File ~/.conda/envs/simul/lib/python3.10/site-packages/matplotlib/gridspec.py:490, in GridSpecFromSubplotSpec.__init__(self, nrows, ncols, subplot_spec, wspace, hspace, height_ratios, width_ratios)
    488     self._subplot_spec = subplot_spec
    489 else:
--> 490     raise TypeError(
    491                     "subplot_spec must be type SubplotSpec, "
    492                     "usually from GridSpec, or axes.get_subplotspec.")
    493 self.figure = self._subplot_spec.get_gridspec().figure
    494 super().__init__(nrows, ncols,
    495                  width_ratios=width_ratios,
    496                  height_ratios=height_ratios)

TypeError: subplot_spec must be type SubplotSpec, usually from GridSpec, or axes.get_subplotspec.

The matplotlib blame traces back to this commit which seems to have shipped with the latest version.

The fix involves explicitely calling ax.get_subplotspec() instead of just passing ax.
It doesn't seem to be a breaking change, and I've successfully tested it with matplotlib 3.8.0

@alejoe91 alejoe91 merged commit 38ba7b4 into SpikeInterface:main Oct 3, 2024
2 checks passed
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