Skip to content

Commit

Permalink
Refactored plotting
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsch420 committed Jun 5, 2024
1 parent f639d34 commit d581fbf
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SCALING_FACTOR_FOR_EXPECTATION_IN_PLOT = 1.05
9 changes: 6 additions & 3 deletions src/probabilistic_model/distributions/distributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]:
Expand Down Expand Up @@ -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]

4 changes: 0 additions & 4 deletions src/probabilistic_model/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit d581fbf

Please sign in to comment.