Repository: gammapy/gammapy

Issue:
Mismatched argument list in Background2d.plot_at_energy
`Background2d.plot_at_energy()` fails due to the mismatched argument list between

https://github.com/gammapy/gammapy/blob/109931f0148386b80796a13f263955dfd1ae95ab/gammapy/irf/background.py#L156

and https://github.com/gammapy/gammapy/blob/109931f0148386b80796a13f263955dfd1ae95ab/gammapy/irf/background.py#L259


Discussion:

Resolving patch:
diff --git a/gammapy/irf/background.py b/gammapy/irf/background.py
--- a/gammapy/irf/background.py
+++ b/gammapy/irf/background.py
@@ -122,7 +122,7 @@ class Background3D(BackgroundIRF):
 
     tag = "bkg_3d"
     required_axes = ["energy", "fov_lon", "fov_lat"]
-    default_unit = u.s**-1 * u.MeV**-1 * u.sr**-1
+    default_unit = u.s ** -1 * u.MeV ** -1 * u.sr ** -1
 
     def to_2d(self):
         """Convert to `Background2D`.
@@ -161,12 +161,12 @@ def plot_at_energy(
         ----------
         energy : `~astropy.units.Quantity`
             list of Energy
-        ax: `~matplotlib.axes.Axes`, optional
-            Axis
         add_cbar : bool
             Add color bar?
         ncols : int
             Number of columns to plot
+        figsize : tuple
+            Figure size
         **kwargs : dict
             Keyword arguments passed to `~matplotlib.pyplot.pcolormesh`.
         """
@@ -230,7 +230,7 @@ class Background2D(BackgroundIRF):
 
     tag = "bkg_2d"
     required_axes = ["energy", "offset"]
-    default_unit = u.s**-1 * u.MeV**-1 * u.sr**-1
+    default_unit = u.s ** -1 * u.MeV ** -1 * u.sr ** -1
     default_interp_kwargs = dict(bounds_error=False, fill_value=0.0)
     """Default Interpolation kwargs."""
 
@@ -256,24 +256,28 @@ def to_3d(self):
             data=data,
         )
 
-    def plot_at_energy(self, energy=None, ax=None, add_cbar=True, ncols=3, **kwargs):
+    def plot_at_energy(
+        self, energy=None, add_cbar=True, ncols=3, figsize=None, **kwargs
+    ):
         """Plot the background rate in Field of view coordinates at a given energy.
 
         Parameters
         ----------
         energy : `~astropy.units.Quantity`
             list of Energy
-        ax: `~matplotlib.axes.Axes`, optional
-            Axis
         add_cbar : bool
             Add color bar?
         ncols : int
             Number of columns to plot
+        figsize : tuple
+            Figure size
         **kwargs : dict
             Keyword arguments passed to `~matplotlib.pyplot.pcolormesh`.
         """
         bkg_3d = self.to_3d()
-        bkg_3d.plot_at_energy(energy, ax, add_cbar, ncols, **kwargs)
+        bkg_3d.plot_at_energy(
+            energy=energy, add_cbar=add_cbar, ncols=ncols, figsize=figsize, **kwargs
+        )
 
     def plot(self, ax=None, add_cbar=True, **kwargs):
         """Plot energy offset dependence of the background model."""


Test patch:
diff --git a/gammapy/irf/tests/test_background.py b/gammapy/irf/tests/test_background.py
--- a/gammapy/irf/tests/test_background.py
+++ b/gammapy/irf/tests/test_background.py
@@ -233,7 +233,7 @@ def test_bkg_3d_wrong_units():
     fov_lat = [0, 1, 2, 3] * u.deg
     fov_lat_axis = MapAxis.from_edges(fov_lat, name="fov_lat")
 
-    wrong_unit = u.cm**2 * u.s
+    wrong_unit = u.cm ** 2 * u.s
     data = np.ones((2, 3, 3)) * wrong_unit
     with pytest.raises(ValueError) as error:
         Background3D(axes=[energy_axis, fov_lon_axis, fov_lat_axis], data=data)
@@ -248,7 +248,7 @@ def test_bkg_2d_wrong_units():
 
     offset_axis = MapAxis.from_edges([0, 1, 2], unit="deg", name="offset")
 
-    wrong_unit = u.cm**2 * u.s
+    wrong_unit = u.cm ** 2 * u.s
     data = np.ones((energy_axis.nbin, offset_axis.nbin)) * wrong_unit
     bkg2d_test = Background2D(axes=[energy_axis, offset_axis])
     with pytest.raises(ValueError) as error:
@@ -391,6 +391,9 @@ def test_plot(bkg_2d):
     with mpl_plot_check():
         bkg_2d.peek()
 
+    with mpl_plot_check():
+        bkg_2d.plot_at_energy(energy=[1.0, 5.0] * u.TeV)
+
 
 def test_eq(bkg_2d):
     bkg1 = deepcopy(bkg_2d)