Repository: yt-project/yt

Issue:
Matplotlib deprecation warnings
### Bug report

**Bug summary**

There are currently two matplotlib deprecation warnings in our CI logs
```
yt.visualization.tests.test_plotwindow.test_symlog_colorbar ... MatplotlibDeprecationWarning: default base will change from np.e to 10 in 3.4.  To suppress this warning specify the base keyword argument.
2803MatplotlibDeprecationWarning: default base will change from np.e to 10 in 3.4.  To suppress this warning specify the base keyword argument.
2804MatplotlibDeprecationWarning: default base will change from np.e to 10 in 3.4.  To suppress this warning specify the base keyword argument.
2805ok (6.1096s)
2806yt.visualization.tests.test_plotwindow.test_nan_data ... MatplotlibDeprecationWarning: default base will change from np.e to 10 in 3.4.  To suppress this warning specify the base keyword argument.
```
```
yt.visualization.tests.test_mesh_slices.test_perfect_element_intersection ... ok (0.5227s)
2761Tests functionality of off_axis_projection and write_projection. ... MatplotlibDeprecationWarning: Passing parameters norm and vmin/vmax simultaneously is deprecated since 3.3 and will become an error two minor releases later. Please pass vmin/vmax directly to the norm when creating it.
```
Those need to be addressed to future-proof Yt against matplotlib 3.4 and 3.5


Discussion:

Resolving patch:
diff --git a/yt/visualization/base_plot_types.py b/yt/visualization/base_plot_types.py
--- a/yt/visualization/base_plot_types.py
+++ b/yt/visualization/base_plot_types.py
@@ -224,9 +224,21 @@ def _init_image(self, data, cbnorm, cblinthresh, cmap, extent, aspect):
         elif cbnorm == "symlog":
             if cblinthresh is None:
                 cblinthresh = float((np.nanmax(data) - np.nanmin(data)) / 10.0)
-            norm = matplotlib.colors.SymLogNorm(
-                cblinthresh, vmin=float(np.nanmin(data)), vmax=float(np.nanmax(data))
+
+            symlog_kwargs = dict(
+                linthresh=cblinthresh,
+                vmin=float(np.nanmin(data)),
+                vmax=float(np.nanmax(data)),
             )
+            MPL_VERSION = LooseVersion(matplotlib.__version__)
+            if MPL_VERSION >= "3.2.0":
+                # note that this creates an inconsistency between mpl versions
+                # since the default value previous to mpl 3.4.0 is np.e
+                # but it is only exposed since 3.2.0
+                symlog_kwargs.update(dict(base=10))
+
+            norm = matplotlib.colors.SymLogNorm(**symlog_kwargs)
+
         extent = [float(e) for e in extent]
         # tuple colormaps are from palettable (or brewer2mpl)
         if isinstance(cmap, tuple):
diff --git a/yt/visualization/image_writer.py b/yt/visualization/image_writer.py
--- a/yt/visualization/image_writer.py
+++ b/yt/visualization/image_writer.py
@@ -3,7 +3,7 @@
 import numpy as np
 
 from yt.config import ytcfg
-from yt.funcs import get_brewer_cmap, get_image_suffix, mylog
+from yt.funcs import get_brewer_cmap, get_image_suffix, issue_deprecation_warning, mylog
 from yt.units.yt_array import YTQuantity
 from yt.utilities import png_writer as pw
 from yt.utilities.exceptions import YTNotInsideNotebook
@@ -341,6 +341,8 @@ def write_projection(
     colorbar=True,
     colorbar_label=None,
     title=None,
+    vmin=None,
+    vmax=None,
     limits=None,
     take_log=True,
     figsize=(8, 6),
@@ -372,9 +374,10 @@ def write_projection(
         the label associated with your colorbar
     title : string
         the label at the top of the figure
-    limits : 2-element array_like
-        the lower limit and the upper limit to be plotted in the figure
-        of the data array
+    vmin : float or None
+        the lower limit of the zaxis (part of matplotlib api)
+    vmax : float or None
+        the lower limit of the zaxis (part of matplotlib api)
     take_log : boolean
         plot the log of the data array (and take the log of the limits if set)?
     figsize : array_like
@@ -390,7 +393,7 @@ def write_projection(
     >>> image = off_axis_projection(ds, c, L, W, N, "Density", no_ghost=False)
     >>> write_projection(image, 'test.png',
                          colorbar_label="Column Density (cm$^{-2}$)",
-                         title="Offaxis Projection", limits=(1e-5,1e-3),
+                         title="Offaxis Projection", vmin=1e-5, vmax=1e-3,
                          take_log=True)
     """
     if cmap_name is None:
@@ -400,27 +403,30 @@ def write_projection(
 
     from ._mpl_imports import FigureCanvasAgg, FigureCanvasPdf, FigureCanvasPS
 
+    if limits is not None:
+        if vmin is not None or vmax is not None:
+            raise ValueError(
+                "The `limits` keyword argument is deprecated and can not "
+                "be used simultaneously with `vmin` or `vmax`."
+            )
+        issue_deprecation_warning(
+            "The `limits` keyword argument is deprecated and will "
+            "be removed in a future version of yt. Use `vmin` and `vmax` instead."
+        )
+        vmin, vmax = limits
+
     # If this is rendered as log, then apply now.
     if take_log:
-        norm = matplotlib.colors.LogNorm()
+        norm_cls = matplotlib.colors.LogNorm
     else:
-        norm = matplotlib.colors.Normalize()
-
-    if limits is None:
-        limits = [None, None]
+        norm_cls = matplotlib.colors.Normalize
+    norm = norm_cls(vmin=vmin, vmax=vmax)
 
     # Create the figure and paint the data on
     fig = matplotlib.figure.Figure(figsize=figsize)
     ax = fig.add_subplot(111)
 
-    cax = ax.imshow(
-        data.to_ndarray(),
-        vmin=limits[0],
-        vmax=limits[1],
-        norm=norm,
-        extent=extent,
-        cmap=cmap_name,
-    )
+    cax = ax.imshow(data.to_ndarray(), norm=norm, extent=extent, cmap=cmap_name,)
 
     if title:
         ax.set_title(title)


Test patch:
diff --git a/tests/tests.yaml b/tests/tests.yaml
--- a/tests/tests.yaml
+++ b/tests/tests.yaml
@@ -162,7 +162,7 @@ answer_tests:
   local_axialpix_006:
     - yt/geometry/coordinates/tests/test_axial_pixelization.py:test_axial_pixelization
 
-  local_cylindrical_background_003:  # PR 2902
+  local_cylindrical_background_004:  # PR 2915
     - yt/geometry/coordinates/tests/test_cylindrical_coordinates.py:test_noise_plots
 
   #local_particle_trajectory_001:
diff --git a/yt/visualization/tests/test_offaxisprojection.py b/yt/visualization/tests/test_offaxisprojection.py
--- a/yt/visualization/tests/test_offaxisprojection.py
+++ b/yt/visualization/tests/test_offaxisprojection.py
@@ -55,7 +55,8 @@ def test_oap(self):
         wp_kwargs["colorbar"] = (True, False)
         wp_kwargs["colorbar_label"] = "test"
         wp_kwargs["title"] = "test"
-        wp_kwargs["limits"] = (None, (1e3, 1e5))
+        wp_kwargs["vmin"] = (None,)
+        wp_kwargs["vmax"] = (1e3, 1e5)
         wp_kwargs["take_log"] = (True, False)
         wp_kwargs["figsize"] = ((8, 6), [1, 1])
         wp_kwargs["dpi"] = (100, 50)