diff --git a/src/constants.py b/src/constants.py new file mode 100644 index 0000000..bfe8dd5 --- /dev/null +++ b/src/constants.py @@ -0,0 +1 @@ +SCALING_FACTOR_FOR_EXPECTATION_IN_PLOT = 1.05 diff --git a/src/probabilistic_model/distributions/distributions.py b/src/probabilistic_model/distributions/distributions.py index 0c0c75b..5d54691 100644 --- a/src/probabilistic_model/distributions/distributions.py +++ b/src/probabilistic_model/distributions/distributions.py @@ -10,6 +10,7 @@ from random_events.interval import * from typing_extensions import Union, Iterable, Any, Self, Dict, List, Tuple, DefaultDict import plotly.graph_objects as go +from ...constants import SCALING_FACTOR_FOR_EXPECTATION_IN_PLOT from ..probabilistic_model import ProbabilisticModel, OrderType, MomentType, CenterType, FullEvidenceType @@ -397,7 +398,7 @@ def moment(self, order: OrderType, center: CenterType) -> MomentType: def plot_expectation(self) -> List: expectation = self.expectation([self.variable])[self.variable] - height = max(self.probabilities.values()) * 1.1 + height = max(self.probabilities.values()) * SCALING_FACTOR_FOR_EXPECTATION_IN_PLOT return [go.Scatter(x=[expectation, expectation], y=[0, height], mode="lines+markers", name="Expectation")] def plot(self) -> List[go.Bar]: @@ -514,9 +515,11 @@ def plot(self) -> List: y=[0, 0, self.density_cap, 0, 0], mode="lines", name="PDF") cdf_trace = go.Scatter(x=[lower_border, self.location, self.location, upper_border], y=[0, 0, 1, 1], mode="lines", name="CDF") - expectation_trace = go.Scatter(x=[self.location, self.location], y=[0, self.density_cap * 1.05], + expectation_trace = go.Scatter(x=[self.location, self.location], y=[0, self.density_cap * + SCALING_FACTOR_FOR_EXPECTATION_IN_PLOT], mode="lines+markers", name="Expectation") - mode_trace = go.Scatter(x=[self.location, self.location], y=[0, self.density_cap * 1.05], + mode_trace = go.Scatter(x=[self.location, self.location], y=[0, self.density_cap * + SCALING_FACTOR_FOR_EXPECTATION_IN_PLOT], mode="lines+markers", name="Mode") return [pdf_trace, cdf_trace, expectation_trace, mode_trace] diff --git a/src/probabilistic_model/utils.py b/src/probabilistic_model/utils.py index d58cd29..da68713 100644 --- a/src/probabilistic_model/utils.py +++ b/src/probabilistic_model/utils.py @@ -3,10 +3,6 @@ import types -if TYPE_CHECKING: - from .distributions.distributions import UnivariateDistribution - - def type_converter(abstract_type: Type, package: types.ModuleType): """ Convert a type to a different type from a target sub-package that inherits from this type.