diff --git a/src/ert/gui/tools/plot/plottery/plots/histogram.py b/src/ert/gui/tools/plot/plottery/plots/histogram.py index 0eaa504c69f..1c250ffdfca 100644 --- a/src/ert/gui/tools/plot/plottery/plots/histogram.py +++ b/src/ert/gui/tools/plot/plottery/plots/histogram.py @@ -133,6 +133,9 @@ def plotHistogram( ), ) else: + if minimum is not None and maximum is not None and minimum == maximum: + minimum -= 0.1 + maximum += 0.1 config.addLegendItem( ensemble.name, _plotHistogram( diff --git a/tests/ert/unit_tests/gui/plottery/test_histogram.py b/tests/ert/unit_tests/gui/plottery/test_histogram.py index 8cc7c6615f2..ab0a71b9460 100644 --- a/tests/ert/unit_tests/gui/plottery/test_histogram.py +++ b/tests/ert/unit_tests/gui/plottery/test_histogram.py @@ -1,9 +1,10 @@ -from unittest.mock import Mock +from unittest.mock import ANY, Mock import pandas as pd import pytest from matplotlib.figure import Figure +import ert from ert.gui.tools.plot.plot_api import EnsembleObject from ert.gui.tools.plot.plottery import PlotConfig, PlotContext from ert.gui.tools.plot.plottery.plots import HistogramPlot @@ -70,3 +71,44 @@ def test_histogram(plot_context: PlotContext, ensemble_to_data_map): {}, ) return figure + + +def test_histogram_plot_for_constant_distribution(monkeypatch): + # test that the histogram plot is called with the correct min and max values + # when all the parameter values are the same + context = Mock(spec=PlotContext) + context.log_scale = False + context.ensembles.return_value = [ + EnsembleObject("ensemble_1", "id", False, "experiment_1") + ] + title = "Histogram with same values" + context.plotConfig.return_value = PlotConfig(title=title) + value = 0 + data_map = dict.fromkeys( + context.ensembles(), pd.DataFrame([[0], [0], [0], [0], [0]]) + ) + min_value = value - 0.1 + max_value = value + 0.1 + figure = Figure() + mock_plot_histogram = Mock() + monkeypatch.setattr( + ert.gui.tools.plot.plottery.plots.histogram, + "_plotHistogram", + mock_plot_histogram, + ) + HistogramPlot().plot( + figure, + context, + data_map, + pd.DataFrame(), + {}, + ) + mock_plot_histogram.assert_called_once_with( + ANY, + ANY, + ANY, + ANY, + ANY, + min_value, + max_value, + )