Skip to content

Commit

Permalink
MAINT: Deal with mpl deps (mne-tools#10578)
Browse files Browse the repository at this point in the history
  • Loading branch information
larsoner authored Apr 28, 2022
1 parent ceb381a commit f059f8f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
3 changes: 1 addition & 2 deletions mne/viz/_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -2189,7 +2189,6 @@ def plot_volume_source_estimates(stc, src, subject=None, subjects_dir=None,
>>> fig = stc_vol_sample.plot(morph) # doctest: +SKIP
""" # noqa: E501
from matplotlib import pyplot as plt, colors
from matplotlib.cbook import mplDeprecation
import nibabel as nib
from ..source_estimate import VolSourceEstimate
from ..morph import SourceMorph
Expand Down Expand Up @@ -2480,7 +2479,7 @@ def plot_and_correct(*args, **kwargs):
if params.get('fig_anat') is not None and plot_kwargs['colorbar']:
params['fig_anat']._cbar.ax.clear()
with warnings.catch_warnings(record=True): # nilearn bug; ax recreated
warnings.simplefilter('ignore', mplDeprecation)
warnings.simplefilter('ignore', DeprecationWarning)
params['fig_anat'] = partial(
plot_func, **plot_kwargs)(*args, **kwargs)
params['fig_anat']._cbar.outline.set_visible(False)
Expand Down
2 changes: 1 addition & 1 deletion mne/viz/_mpl_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1994,7 +1994,7 @@ def _resize_by_factor(self, factor=None):
size[1] * factor[1])
else:
size = [int(x * factor) for x in size]
self.canvas.manager.canvas.resize(*size)
self.canvas.manager.resize(*size)

def _get_ticklabels(self, orientation):
if orientation == 'x':
Expand Down
2 changes: 1 addition & 1 deletion mne/viz/evoked.py
Original file line number Diff line number Diff line change
Expand Up @@ -1483,7 +1483,7 @@ def plot_evoked_joint(evoked, times="peaks", title='', picks=None,

# XXX BUG destroys ax -> fig assignment if title & axes are passed
if title is not None:
title_ax = plt.subplot(4, 3, 2)
title_ax = fig.add_subplot(4, 3, 2)
if title == '':
title = old_title
title_ax.text(.5, .5, title, transform=title_ax.transAxes,
Expand Down
3 changes: 1 addition & 2 deletions mne/viz/tests/test_evoked.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from mne import (read_events, Epochs, read_cov, compute_covariance,
make_fixed_length_events, compute_proj_evoked)
from mne.io import read_raw_fif
from mne.utils import catch_logging, requires_version
from mne.utils import catch_logging
from mne.viz import plot_compare_evokeds, plot_evoked_white
from mne.viz.utils import _fake_click
from mne.datasets import testing
Expand Down Expand Up @@ -170,7 +170,6 @@ def test_plot_evoked():
assert 'Need more than one' in log_file.getvalue()


@requires_version('matplotlib', '2.2')
def test_constrained_layout():
"""Test that we handle constrained layouts correctly."""
fig, ax = plt.subplots(1, 1, constrained_layout=True)
Expand Down
13 changes: 11 additions & 2 deletions mne/viz/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1364,7 +1364,7 @@ def key_press(self, event):
self.index = 0
cmap = self.cycle[self.index]
self.cbar.mappable.set_cmap(cmap)
self.cbar.draw_all()
_draw_without_rendering(self.cbar)
self.mappable.set_cmap(cmap)
self._update()

Expand Down Expand Up @@ -1403,11 +1403,20 @@ def _update(self):
from matplotlib.ticker import AutoLocator
self.cbar.set_ticks(AutoLocator())
self.cbar.update_ticks()
self.cbar.draw_all()
_draw_without_rendering(self.cbar)
self.mappable.set_norm(self.cbar.norm)
self.cbar.ax.figure.canvas.draw()


def _draw_without_rendering(cbar):
# draw_all deprecated in Matplotlib 3.6
try:
meth = cbar.ax.figure.draw_without_rendering
except AttributeError:
meth = cbar.draw_all
return meth()


class SelectFromCollection:
"""Select channels from a matplotlib collection using ``LassoSelector``.
Expand Down

0 comments on commit f059f8f

Please sign in to comment.