Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions src/machinevisiontoolbox/ImageWholeFeatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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:

Expand Down Expand Up @@ -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

Expand Down
15 changes: 15 additions & 0 deletions tests/test_image_whole_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Loading