Repository: wright-group/WrightTools

Issue:
Matplotlib deprecation for clim
```
/home/kyle/venvs/source/WrightTools/WrightTools/artists/_base.py:532: MatplotlibDeprecationWarning:
The process_projection_requirements function was deprecated in Matplotlib 3.1 and will be removed in 3.3.
  self, *args, **kwargs

/venvs/source/WrightTools/WrightTools/artists/_helpers.py:687: MatplotlibDeprecationWarning:
The set_clim function was deprecated in Matplotlib 3.1 and will be removed in 3.3. Use ScalarMappable.set_clim instead.
  cbar.set_clim(clim)
```

Two deprecation warnings appear on current matplotlib master.
Pretty easy to fix, though currently there is a regression that I may track down and PR before mpl is released causing a breakage (not just a warning) for the clim, as we pass `set_clim(clim[0], clim[1])`

~~This is fixed by calling `set_clim(clim)` (though the warning still appears for now, have not tried using the suggested alternative yet)~~ Fix submitted upstream see matplotlib/matplotlib#13789 the function signature was incorrect.


Discussion:
the process_projection_requirements is in `add_subplot` of our `Figure` subclass in `_base.py`.
`clim` is in `plot_colorbar` in `_helpers.py`

See also matplotlib/matplotlib#13234

process_projection_requirements is becoming a private method, not going away completely.

While I don't like using private methods which can change more rapidly, we are using it in a subclass already, so private methods are more reasonable. Just need someone to stay on track and make sure things don't break (which means myself).
https://github.com/matplotlib/matplotlib/commit/4ffe21beb8c6afb02f179c3ff40cd487f0f3b7bf

The commit in question

Will require a try/except to support both old and new, but not too bad on the whole, there

Sorry for the change (I did the deprecation), but it looks like your entire `add_subplot` (which I only quickly skimmed thru) could just be (untested)
```
def add_subplot(self, *args, **kwargs):
    kwargs.setdefault("projection", "wright")
    super().add_subplot(*args, **kwargs)
```
and then you don't have to bother with the change?
https://github.com/wright-group/WrightTools/blob/10a29b10baf06d7971e21b6568476bfe661ae19f/WrightTools/artists/_helpers.py#L687

Everytime I call `plot_colorbar` I get a `MatplotlibDeprecationWarning` of 
>The set_clim function was deprecated in Matplotlib 3.1 and will be removed in 3.3. Use ScalarMappable.set_clim instead.

Do we have plans for fixing this?
Currently that function is a no-op, So basically, if we are happy with the colorbars being plotted, we can remove/selectively call it only on older matplotlibs. Otherwise, we need to actually call the right set_clim function (on the colormap itself)

Resolving patch:
diff --git a/WrightTools/artists/_helpers.py b/WrightTools/artists/_helpers.py
--- a/WrightTools/artists/_helpers.py
+++ b/WrightTools/artists/_helpers.py
@@ -70,7 +70,7 @@ def _title(fig, title, subtitle="", *, margin=1, fontsize=20, subfontsize=18):
     """
     fig.suptitle(title, fontsize=fontsize)
     height = fig.get_figheight()  # inches
-    distance = margin / 2.  # distance from top of plot, in inches
+    distance = margin / 2.0  # distance from top of plot, in inches
     ratio = 1 - distance / height
     fig.text(0.5, ratio, subtitle, fontsize=subfontsize, ha="center", va="top")
 
@@ -78,7 +78,7 @@ def _title(fig, title, subtitle="", *, margin=1, fontsize=20, subfontsize=18):
 def add_sideplot(
     ax,
     along,
-    pad=0.,
+    pad=0.0,
     *,
     grid=True,
     zero_line=True,
@@ -237,7 +237,7 @@ def create_figure(
     width="single",
     nrows=1,
     cols=[1],
-    margin=1.,
+    margin=1.0,
     hspace=0.25,
     wspace=0.25,
     cbar_width=0.25,
@@ -320,11 +320,11 @@ def create_figure(
     """
     # get width
     if width == "double":
-        figure_width = 14.
+        figure_width = 14.0
     elif width == "single":
         figure_width = 6.5
     elif width == "dissertation":
-        figure_width = 13.
+        figure_width = 13.0
     else:
         figure_width = float(width)
     # check if aspect constraints are valid
@@ -486,7 +486,7 @@ def get_scaled_bounds(ax, position, *, distance=0.1, factor=200):
         ha = "right"
     else:
         print("corner not recognized")
-        v_scaled = h_scaled = 1.
+        v_scaled = h_scaled = 1.0
         va = "center"
         ha = "center"
     return [h_scaled, v_scaled], [va, ha]
@@ -590,9 +590,10 @@ def plot_colorbar(
         WrightTools colormaps dictionary. Default is `default`.
     ticks : 1D array-like (optional)
         Ticks. Default is None.
-    clim : two element list (optional)
+    clim : two element list (optional, deprecated)
         The true limits of the colorbar, in the same units as ticks. If None,
         streaches the colorbar over the limits of ticks. Default is None.
+        Deprecated: Use ``vlim`` directly instead.
     vlim : two element list-like (optional)
         The limits of the displayed colorbar, in the same units as ticks. If
         None, displays over clim. Default is None.
@@ -644,6 +645,11 @@ def plot_colorbar(
     # parse clim
     if clim is None:
         clim = [min(ticks), max(ticks)]
+    else:
+        warnings.warn(
+            "Parameter 'clim' is deprecated, use 'vlim' instead",
+            wt_exceptions.VisibleDepricationWarning,
+        )
     # parse clim
     if vlim is None:
         vlim = clim
@@ -684,7 +690,6 @@ def fmt(x, _):
         extendrect=extendrect,
     )
     # coerce properties
-    cbar.set_clim(clim[0], clim[1])
     cbar.ax.tick_params(labelsize=tick_fontsize)
     if label:
         cbar.set_label(label, fontsize=label_fontsize)
@@ -692,7 +697,7 @@ def fmt(x, _):
     return cbar
 
 
-def plot_margins(*, fig=None, inches=1., centers=True, edges=True):
+def plot_margins(*, fig=None, inches=1.0, centers=True, edges=True):
     """Add lines onto a figure indicating the margins, centers, and edges.
 
     Useful for ensuring your figure design scripts work as intended, and for laying
@@ -972,12 +977,20 @@ def set_fig_labels(
     for ax in fig.axes:
         if ax.is_sideplot:
             continue
-        if row_start <= ax.rowNum <= row_stop and col_start <= ax.colNum <= col_stop:
-            if ax.colNum == col_start:
+        try:
+            # [row|col]span were introduced in matplotlib 3.2
+            # this try/except can be removed when supprot for mpl < 3.2 is dropped
+            rowNum = ax.get_subplotspec().rowspan.start
+            colNum = ax.get_subplotspec().colspan.start
+        except AttributeError:
+            rowNum = ax.rowNum
+            colNum = ax.colNum
+        if row_start <= rowNum <= row_stop and col_start <= colNum <= col_stop:
+            if colNum == col_start:
                 set_ax_labels(ax=ax, ylabel=ylabel, yticks=yticks, label_fontsize=label_fontsize)
             else:
                 set_ax_labels(ax=ax, ylabel="", yticks=False)
-            if ax.rowNum == row_stop:
+            if rowNum == row_stop:
                 set_ax_labels(ax=ax, xlabel=xlabel, xticks=xticks, label_fontsize=label_fontsize)
             else:
                 set_ax_labels(ax=ax, xlabel="", xticks=False)


Test patch: