Skip to content

Commit

Permalink
rename probability_plot to "plot"
Browse files Browse the repository at this point in the history
  • Loading branch information
MAfarrag committed Aug 17, 2024
1 parent b70deff commit 58fb316
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 20 deletions.
35 changes: 24 additions & 11 deletions statista/distributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ def confidence_interval(
"""
pass

def probability_plot(
def plot(
self,
fig1size: tuple = (10, 5),
xlabel: str = "Actual data",
Expand Down Expand Up @@ -1243,7 +1243,7 @@ def confidence_interval(
else:
return q_upper, q_lower

def probability_plot(
def plot(
self,
fig1_size: Tuple[float, float] = (10, 5),
xlabel: str = "Actual data",
Expand Down Expand Up @@ -1279,13 +1279,26 @@ def probability_plot(
Returns
-------
Qth: [list]
theoretical-generated values based on the theoretical cdf calculated from
weibul or the distribution parameters.
q_upper: [list]
upper-bound coresponding to the confidence interval.
q_lower: [list]
lower-bound coresponding to the confidence interval.
Figure:
matplotlib figure object
Tuple[Axes, Axes]:
matplotlib plot axes
Examples
--------
- Instantiate the Gumbel class with the data and the parameters.
>>> import matplotlib.pyplot as plt
>>> data = np.loadtxt("examples/data/time_series2.txt")
>>> parameters = {"loc": 463.8040, "scale": 220.0724}
>>> gumbel_dist = Gumbel(data, parameters)
- to calculate the confidence interval, we need to provide the confidence level (`alpha`).
>>> fig, ax = gumbel_dist.plot()
.. image:: /_images/gumbel-confidence-interval.png
:align: center
"""
# if no parameters are provided, take the parameters provided in the class initialization.
if parameters is None:
Expand Down Expand Up @@ -2040,7 +2053,7 @@ def confidence_interval(
else:
return q_upper, q_lower

def probability_plot(
def plot(
self,
fig1_size=(10, 5),
xlabel="Actual data",
Expand Down Expand Up @@ -3251,7 +3264,7 @@ def __init__(

def __getattr__(self, name: str):
"""Delegate method calls to the subclass"""
# Retrieve the attribute or method from the animal object
# Retrieve the attribute or method from the distribution object
try:
# Retrieve the attribute or method from the subclasses
attribute = getattr(self.distribution, name)
Expand Down
4 changes: 2 additions & 2 deletions statista/eva.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,11 @@ def ams_analysis(
# get the Discharge coresponding to the return periods
q_rp = dist.inverse_cdf(non_exceed_prop, param_dist)

# Gumbel.probability_plot method calculates the theoretical values
# Gumbel.plot method calculates the theoretical values
# based on the Gumbel distribution
# parameters, theoretical cdf (or weibul), and calculate the confidence interval
if save_plots:
fig, _ = dist.probability_plot()
fig, _ = dist.plot()
_, _, fig2, _ = dist.confidence_interval(
method=method, plot_figure=True, alpha=significance_level
)
Expand Down
14 changes: 7 additions & 7 deletions tests/test_distributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import matplotlib

matplotlib.use("Agg")
matplotlib.use("TkAgg")
from typing import List, Dict

import numpy as np
Expand Down Expand Up @@ -223,7 +223,7 @@ def test_confidence_interval(
assert isinstance(fig, Figure)
assert isinstance(ax, Axes)

def test_probability_plot(
def test_plot(
self,
time_series2: list,
dist_estimation_parameters_ks: str,
Expand All @@ -233,13 +233,13 @@ def test_probability_plot(
param = gum_dist_parameters[dist_estimation_parameters_ks]
dist = Gumbel(time_series2, param)
# test default parameters.
fig, ax = dist.probability_plot()
fig, ax = dist.plot()
assert isinstance(fig, Figure)
assert isinstance(ax[0], Axes)
assert isinstance(ax[1], Axes)
# test with the cdf parameter
cdf_weibul = PlottingPosition.weibul(time_series2)
fig, ax = dist.probability_plot(cdf=cdf_weibul)
fig, ax = dist.plot(cdf=cdf_weibul)
assert isinstance(fig, Figure)
assert isinstance(ax[0], Axes)
assert isinstance(ax[1], Axes)
Expand Down Expand Up @@ -386,7 +386,7 @@ def test_gev_confidence_interval(
assert isinstance(fig, Figure)
assert isinstance(ax, Axes)

def test_gev_probability_plot(
def test_gev_plot(
self,
time_series1: list,
dist_estimation_parameters_ks: str,
Expand All @@ -396,13 +396,13 @@ def test_gev_probability_plot(
param = gev_dist_parameters[dist_estimation_parameters_ks]
dist = GEV(time_series1, param)
# test default parameters.
fig, ax = dist.probability_plot()
fig, ax = dist.plot()
assert isinstance(fig, Figure)
assert isinstance(ax[0], Axes)
assert isinstance(ax[1], Axes)
# test with the cdf parameter
cdf_weibul = PlottingPosition.weibul(time_series1)
fig, ax = dist.probability_plot(cdf=cdf_weibul)
fig, ax = dist.plot(cdf=cdf_weibul)
assert isinstance(fig, Figure)
assert isinstance(ax[0], Axes)
assert isinstance(ax[1], Axes)
Expand Down

0 comments on commit 58fb316

Please sign in to comment.