diff --git a/src/machinevisiontoolbox/ImageWholeFeatures.py b/src/machinevisiontoolbox/ImageWholeFeatures.py index ff3a9b9f..7fa2a061 100644 --- a/src/machinevisiontoolbox/ImageWholeFeatures.py +++ b/src/machinevisiontoolbox/ImageWholeFeatures.py @@ -1210,7 +1210,9 @@ def ncdf(self) -> np.ndarray: def plot( self, - type: str = "frequency", + type: Literal[ + "frequency", "pdf", "probability", "cf", "cumulative", "cdf", "normalized", "ncdf" + ] = "frequency", block: bool = False, filled: bool | None = None, stats: bool = True, @@ -1227,8 +1229,9 @@ def plot( """ Plot histogram - :param type: histogram type, one of: 'frequency' [default], 'cdf', 'ncdf' - :type type: str, optional + :param type: histogram type, one of: 'frequency' [default], 'pdf'/'probability', + 'cf'/'cumulative', 'cdf'/'normalized'; 'ncdf' is accepted as a deprecated + alias for 'cdf' :param block: hold plot, defaults to False :type block: bool, optional :param filled: use a filled stairs plot, defaults to True for frequency plot, False for @@ -1258,7 +1261,9 @@ def plot( Plots the histogram using Matplotlib. For a color image, the histograms of each plane are plotted separately. The ``type`` option selects the type of histogram - to plot: ``frequency``, ``cdf`` or ``ncdf`` (normalized cumulative in the range 0 to 1). + to plot: ``frequency``, ``pdf``/``probability``, ``cf``/``cumulative``, or + ``cdf``/``normalized`` (normalized cumulative, range 0 to 1). ``ncdf`` is + accepted as a deprecated alias for ``cdf``. The ``style`` option selects the style for plotting multiple planes: @@ -1342,6 +1347,14 @@ def plot( if filled is None: filled = bar + if type == "ncdf": + warnings.warn( + "Deprecated in 2.0.0: use type='cdf' instead of type='ncdf'.", + DeprecationWarning, + stacklevel=2, + ) + type = "cdf" + if type not in ("frequency", "pdf"): stats = False # only show stats for frequency and pdf plot diff --git a/tests/test_image_whole_features.py b/tests/test_image_whole_features.py index e943634b..4c739542 100644 --- a/tests/test_image_whole_features.py +++ b/tests/test_image_whole_features.py @@ -509,6 +509,21 @@ def test_histogram_ncdf_deprecated(self): ncdf = h.ncdf nt.assert_array_equal(ncdf, h.cdf) + def test_plot_type_ncdf_deprecated_alias(self): + """Histogram.plot(type='ncdf') is a deprecated alias for + type='cdf' -- regression test: 'ncdf' was documented in plot()'s + own docstring but never actually implemented in the dispatch + logic, so it always raised ValueError('unknown type').""" + im = Image.Random(size=(50, 50), dtype="uint8") + h = im.hist() + with self.assertWarns(DeprecationWarning): + h.plot(type="ncdf") + plt.close("all") + + # equivalent, current spelling -- must not warn + h.plot(type="cdf") + plt.close("all") + if __name__ == "__main__": unittest.main()