Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 896ff6c

Browse files
committed
BUGFIX: remove all but one warning from docs
1 parent be1a01f commit 896ff6c

15 files changed

Lines changed: 83 additions & 50 deletions

File tree

doc/conf.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import sphinx
2121

2222
from datetime import datetime
23-
import warnings
2423

2524
# If your extensions are in another directory, add it here. If the directory
2625
# is relative to the documentation root, use os.path.abspath to make it
@@ -35,6 +34,9 @@
3534
# docs build to fail. This is especially useful for getting rid of deprecated
3635
# usage in the gallery.
3736
warnings.filterwarnings('error', append=True)
37+
#TODO remove when GridSpec allows rect again
38+
warnings.filterwarnings('ignore', message='(\n|.)*This figure includes Axes '
39+
'that are not compatible with tight_layout.*')
3840

3941
# Strip backslahes in function's signature
4042
# To be removed when numpydoc > 0.9.x
@@ -116,8 +118,8 @@ def _check_dependencies():
116118

117119
# we should ignore warnings coming from importing deprecated modules for
118120
# autodoc purposes, as this will disappear automatically when they are removed
119-
warnings.filterwarnings('ignore', message='.*module was deprecated.*',
120-
category=MatplotlibDeprecationWarning)
121+
warnings.filterwarnings('ignore', category=MatplotlibDeprecationWarning,
122+
message=r'(\n|.)*module was deprecated.*')
121123

122124
autodoc_docstring_signature = True
123125
autodoc_default_options = {'members': None, 'undoc-members': None}

doc/devel/documenting_mpl.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ Optional, but recommended:
9191
* `optipng <http://optipng.sourceforge.net>`_
9292
* the font "Humor Sans" (aka the "XKCD" font), or the free alternative
9393
`Comic Neue <http://comicneue.com/>`_.
94+
* the font "Times New Roman"
9495

9596
.. note::
9697

examples/animation/rain.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525

2626
# Create rain data
2727
n_drops = 50
28-
rain_drops = np.zeros(n_drops, dtype=[('position', float, 2),
29-
('size', float, 1),
30-
('growth', float, 1),
31-
('color', float, 4)])
28+
rain_drops = np.zeros(n_drops, dtype=[('position', float, (2,)),
29+
('size', float),
30+
('growth', float),
31+
('color', float, (4,))])
3232

3333
# Initialize the raindrops in random positions and with
3434
# random growth rates.

examples/images_contours_and_fields/contourf_demo.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
66
How to use the `.axes.Axes.contourf` method to create filled contour plots.
77
"""
8+
import copy
89

910
import numpy as np
1011
import matplotlib.pyplot as plt
@@ -88,6 +89,8 @@
8889
# Illustrate all 4 possible "extend" settings:
8990
extends = ["neither", "both", "min", "max"]
9091
cmap = plt.cm.get_cmap("winter")
92+
# we need a copy of the colormap to modify it
93+
cmap = copy.copy(cmap)
9194
cmap.set_under("magenta")
9295
cmap.set_over("yellow")
9396
# Note: contouring simply excludes masked or nan regions, so

examples/images_contours_and_fields/pcolormesh_grids.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,16 @@ def _annotate(ax, x, y, title):
5555
# -----------------------------
5656
#
5757
# Often, however, data is provided where *X* and *Y* match the shape of *Z*.
58-
# As of Matplotlib v3.3, ``shading='flat'`` is deprecated when this is the
59-
# case, a warning is raised, and the last row and column of *Z* are dropped.
60-
# This dropping of the last row and column is what Matplotlib did silently
61-
# previous to v3.3, and is compatible with what Matlab does.
58+
# While this makes sense for other ``shading`` types, it is no longer permitted
59+
# when ``shading='flat'`` (and will raise a MatplotlibDeprecationWarning as of
60+
# Matplotlib v3.3). Historically, Matplotlib silently dropped the last row and
61+
# column of *Z* in this case, to match Matlab's behavior. If this behavior is
62+
# still desired, simply drop the last row and column manually:
6263

6364
x = np.arange(ncols) # note *not* ncols + 1 as before
6465
y = np.arange(nrows)
6566
fig, ax = plt.subplots()
66-
ax.pcolormesh(x, y, Z, shading='flat', vmin=Z.min(), vmax=Z.max())
67+
ax.pcolormesh(x, y, Z[:-1, :-1], shading='flat', vmin=Z.min(), vmax=Z.max())
6768
_annotate(ax, x, y, "shading='flat': X, Y, C same shape")
6869

6970
###############################################################################

examples/images_contours_and_fields/pcolormesh_levels.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,12 @@
5151
# ---------------------
5252
#
5353
# Often a user wants to pass *X* and *Y* with the same sizes as *Z* to
54-
# `.axes.Axes.pcolormesh`. This is also allowed if ``shading='auto'`` is
55-
# passed (default set by :rc:`pcolor.shading`). Pre Matplotlib 3.3,
54+
# `.axes.Axes.pcolormesh`. This is also allowed if ``shading='auto'`` is
55+
# passed (default set by :rc:`pcolor.shading`). Pre Matplotlib 3.3,
5656
# ``shading='flat'`` would drop the last column and row of *Z*; while that
5757
# is still allowed for back compatibility purposes, a DeprecationWarning is
58-
# raised.
58+
# raised. If this is really what you want, then simply drop the last row and
59+
# column of Z manually:
5960

6061
x = np.arange(10) # len = 10
6162
y = np.arange(6) # len = 6
@@ -64,7 +65,8 @@
6465
fig, axs = plt.subplots(2, 1, sharex=True, sharey=True)
6566
axs[0].pcolormesh(X, Y, Z, vmin=np.min(Z), vmax=np.max(Z), shading='auto')
6667
axs[0].set_title("shading='auto' = 'nearest'")
67-
axs[1].pcolormesh(X, Y, Z, vmin=np.min(Z), vmax=np.max(Z), shading='flat')
68+
axs[1].pcolormesh(X, Y, Z[:-1, :-1], vmin=np.min(Z), vmax=np.max(Z),
69+
shading='flat')
6870
axs[1].set_title("shading='flat'")
6971

7072
###############################################################################

examples/specialty_plots/advanced_hillshading.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def display_colorbar():
2525
# Use a proxy artist for the colorbar...
2626
im = ax.imshow(z, cmap=cmap)
2727
im.remove()
28-
fig.colorbar(im)
28+
fig.colorbar(im, ax=ax)
2929

3030
ax.set_title('Using a colorbar with a shaded plot', size='x-large')
3131

examples/style_sheets/style_sheets_reference.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ def plot_figure(style_label=""):
137137

138138
# Plot a demonstration figure for every available style sheet.
139139
for style_label in style_list:
140-
with plt.style.context(style_label):
141-
fig = plot_figure(style_label=style_label)
140+
with plt.rc_context({"figure.max_open_warning": len(style_list)}):
141+
with plt.style.context(style_label):
142+
fig = plot_figure(style_label=style_label)
142143

143144
plt.show()

examples/subplots_axes_and_figures/secondary_axis.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,19 @@ def rad2deg(x):
5757
ax.set_title('Random spectrum')
5858

5959

60-
def forward(x):
61-
return 1 / x
60+
def safe_inverse(x):
61+
x = np.array(x).astype(float)
62+
near_zero = np.isclose(x, 0)
63+
x[near_zero] = np.inf
64+
x[~near_zero] = 1 / x[~near_zero]
65+
return x
6266

6367

64-
def inverse(x):
65-
return 1 / x
68+
# the function "1/x" is its own inverse
69+
forward = safe_inverse
6670

6771

68-
secax = ax.secondary_xaxis('top', functions=(forward, inverse))
72+
secax = ax.secondary_xaxis('top', functions=(forward, safe_inverse))
6973
secax.set_xlabel('period [s]')
7074
plt.show()
7175

examples/text_labels_and_annotations/usetex_baseline_test.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ def __init__(self, *args, preview=False, **kwargs):
3030
super().__init__(*args, **kwargs)
3131

3232
def draw(self, renderer):
33-
with plt.rc_context({"text.latex.preview": self.preview}):
34-
super().draw(renderer)
33+
from matplotlib import _api # internal, *do not use*
34+
with _api.suppress_matplotlib_deprecation_warning():
35+
with plt.rc_context({"text.latex.preview": self.preview}):
36+
super().draw(renderer)
3537

3638

3739
def test_window_extent(ax, usetex, preview):

0 commit comments

Comments
 (0)