diff --git a/doc/users/dflt_style_changes.rst b/doc/users/dflt_style_changes.rst index a2a687ae7620..8cca424289f3 100644 --- a/doc/users/dflt_style_changes.rst +++ b/doc/users/dflt_style_changes.rst @@ -1002,7 +1002,7 @@ a cleaner separation between subplots. with mpl.rc_context(rc=rcparams): ax = fig.add_subplot(2, 2, j) - ax.hist(np.random.beta(0.5, 0.5, 10000), 25, normed=True) + ax.hist(np.random.beta(0.5, 0.5, 10000), 25, density=True) ax.set_xlim([0, 1]) ax.set_title(title) diff --git a/lib/matplotlib/cbook/__init__.py b/lib/matplotlib/cbook/__init__.py index 41197ecf5da2..554abe8d6677 100644 --- a/lib/matplotlib/cbook/__init__.py +++ b/lib/matplotlib/cbook/__init__.py @@ -1991,7 +1991,8 @@ def _warn_external(message, category=None): frame = sys._getframe() for stacklevel in itertools.count(1): # lgtm[py/unused-loop-variable] if not re.match(r"\A(matplotlib|mpl_toolkits)(\Z|\.)", - frame.f_globals["__name__"]): + # Work around sphinx-gallery not setting __name__. + frame.f_globals.get("__name__", "")): break frame = frame.f_back warnings.warn(message, category, stacklevel) diff --git a/lib/matplotlib/cbook/deprecation.py b/lib/matplotlib/cbook/deprecation.py index b93a5ca94f8f..51dacba0dc87 100644 --- a/lib/matplotlib/cbook/deprecation.py +++ b/lib/matplotlib/cbook/deprecation.py @@ -109,7 +109,8 @@ def warn_deprecated( removal=removal) category = (PendingDeprecationWarning if pending else MatplotlibDeprecationWarning) - warnings.warn(message, category, stacklevel=2) + from . import _warn_external + _warn_external(message, category) def deprecated(since, message='', name='', alternative='', pending=False, @@ -216,7 +217,8 @@ def finalize(wrapper, new_doc): else MatplotlibDeprecationWarning) def wrapper(*args, **kwargs): - warnings.warn(message, category, stacklevel=2) + from . import _warn_external + _warn_external(message, category) return func(*args, **kwargs) old_doc = textwrap.dedent(old_doc or '').strip('\n')