Skip to content

Commit

Permalink
Fix of DistribtuionModel plotting, removing of logging from __init__,…
Browse files Browse the repository at this point in the history
… change tested python version to 3.9, 3.10, 3.11, 3.12
  • Loading branch information
sibange committed Sep 25, 2024
1 parent 1c5fe13 commit c8605a2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.7, 3.8, 3.9]
python-version: [3.9, 3.10, 3.11, 3.12]

steps:
- uses: actions/checkout@v2
Expand Down
4 changes: 0 additions & 4 deletions mms_msg/sampling/pattern/meeting/state_based/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,3 @@
from . import sampler
from . import transition_model
from . import weighted_meeting_sampler

import logging
import sys
logging.basicConfig(level=logging.INFO, stream=sys.stdout)
14 changes: 5 additions & 9 deletions mms_msg/sampling/utils/distribution_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,34 +224,30 @@ def __repr__(self):
ret += " Variance:" + str(self.variance)
return ret

def plot(self, show: bool = False, fig=None, ax=None):
def plot(self, show: bool = False, ax=None):
"""
Creates a plot of the distribution model using matplotlib and
returns a figure and axes with the corresponding plot.
Args:
show: (optional) When set to True the figure is directly shown
fig: (optional) Figure on which a new axes with the plot is created.
Will be overwritten when ax is given.
When not given and also ax is not provided the function creates a new figure
with one axes and uses this for the plot.
ax: (optional) axes on which the plot is created, when not provided
the function creates a new axes on the figure, when also the figure is not provided
then the function creates a new figure with one axes and uses this for the plot.
Returns: Figure and axes with the plot of the distribution.
When an axis but no figure is given as input then the tuple (None,ax) is returned.
When an axis is given as input then the tuple (None,ax) is returned.
"""

import matplotlib.pyplot as plt

if self.n == 0:
raise AssertionError("No samples has been added to the model. Plot is empty.")

if fig is None and ax is None:
fig = None

if ax is None:
fig, ax = plt.subplots()
elif fig is not None:
ax = fig.add_axes()

ax.hist(list(map(lambda x: x[0], self.distribution_prob)),
bins=int((self.max_value - self.min_value)/self.bin_size),
Expand Down

0 comments on commit c8605a2

Please sign in to comment.