Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor #16

Merged
merged 1 commit into from
Sep 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions pliffy/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,19 @@
from pliffy.plot import plot_abd


def _gen_data(data_specs):
class DataSpecs(NamedTuple):
"""Helper namedtuple used to set parameters of data to be mocked"""
sample_size_a: int = 30
sample_size_b: int = 30
mean_a: float = 100
mean_b: float = 95
sd_a: float = 5
sd_b: float = 5
design: Union["paired", "unpaired"] = "paired"


def _gen_data(data_specs: DataSpecs) -> Union[list, list]:
"""Create mock data based on data_specs"""
data_a = np.random.default_rng().normal(
data_specs.mean_a, data_specs.sd_a, data_specs.sample_size_a
)
Expand All @@ -25,16 +37,6 @@ def _gen_data(data_specs):
return data_a, data_b


class DataSpecs(NamedTuple):
sample_size_a: int = 30
sample_size_b: int = 30
mean_a: float = 100
mean_b: float = 95
sd_a: float = 5
sd_b: float = 5
design: Union["paired", "unpaired"] = "paired"


def _example1():
data_specs = DataSpecs()
data_a, data_b = _gen_data(data_specs)
Expand Down Expand Up @@ -136,21 +138,24 @@ def _example5():
last_subplot = len(axes) - 1
for i, ax in enumerate(axes):
data_specs = DataSpecs(
sample_size_a=(i+1)*10,
sample_size_b=(i+1)*10,
sample_size_a=(i + 1) * 10,
sample_size_b=(i + 1) * 10,
mean_a=100,
mean_b=120,
sd_a=30,
sd_b=30,
design="unpaired",
)
data_a, data_b = _gen_data(data_specs)
show = i == last_subplot
info = PliffyInfoABD(data_a=data_a, data_b=data_b, show=show, fontsize=12)
if i != last_subplot:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you reverse this?

info = PliffyInfoABD(data_a=data_a, data_b=data_b, show=False, fontsize=12)
else:
info = PliffyInfoABD(data_a=data_a, data_b=data_b, fontsize=12)
plot_abd(info, ax)


def demo():
"""Generate five different demo plots"""
_example1()
_example2()
_example3()
Expand Down
1 change: 0 additions & 1 deletion pliffy/estimate.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,4 @@ def _calc_paired_diffs(info: "utils.PliffyInfoABD"):

class UnequalLength(Exception):
"""Custom exception for paired analysis when data_a/data_b not same length"""

pass
14 changes: 9 additions & 5 deletions pliffy/figure/diff_axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class DiffAxCreator:
-----
diff axis is create by specifying x, y, width, height.
- x, y: coordinates of the bottom-left corner of the diff axis
- width, height: Of the diff axis, where the origin is x, y
- width, height: Size of diff axis, where the origin is x, y

Because we create the diff axis in data coordinates of the main ab_axis,
(transform=self.ax_ab.transData), `x, y, width, height` must all be specified
Expand Down Expand Up @@ -55,8 +55,10 @@ def __init__(
def _min_diff(self) -> float:
"""Determine lowest value on diff plot

This value could come from the lowest single raw value difference if raw
differences are plotted, or it could come from the lower value of the CI """
This value could be the lowest single raw value difference if raw
differences are plotted, or the lowest value of the CI

"""

if self._true_false_plot_raw_diff():
return min(self.diff_fig_info.raw_diff.data)
Expand All @@ -66,8 +68,10 @@ def _min_diff(self) -> float:
def _max_diff(self) -> float:
"""Determine highest value on diff plot

This value could come from the highest single raw value difference if raw
differences are plotted, or it could come from the higher value of the CI """
This value could be the highest single raw value difference if raw
differences are plotted, or the highest value of the CI

"""

if self._true_false_plot_raw_diff():
return max(self.diff_fig_info.raw_diff.data)
Expand Down
1 change: 0 additions & 1 deletion pliffy/figure/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def _set_xticks(self, xticks: "Xticks"):
self.ax.set_xticks(xticks.vals)
self.ax.set_xticklabels(xticks.labels)


def _set_yticks(self, yticks: Tuple[float]):
self.ax.set_yticks(yticks)

Expand Down
2 changes: 1 addition & 1 deletion pliffy/figure/figure_ab.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __init__(self, info: "parser.FigureInfoAB", ax: Subplot = None):

def _make_figure_axis(self) -> Subplot:
width_height_in_inches = WIDTH_HEIGHT_IN_INCHES
_, ax = plt.subplots(figsize=width_height_in_inches)
ax = plt.subplots(figsize=width_height_in_inches)[1]
return ax

def _min_raw_data(self) -> float:
Expand Down
4 changes: 2 additions & 2 deletions pliffy/figure/figure_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ def _plot_diff_mean_ci(self):
self._plot_mean_ci(self.info.mean_diff, self.info.ci_diff)

def _plot_diff_raw_data(self):
if self._plot_raw_diff():
if self._plot_raw_diff_true():
self._plot_raw_data(self.info.raw_diff)

def _plot_raw_diff(self):
def _plot_raw_diff_true(self):
return (self.info.raw_diff.data is not None) and self.info.plot_raw_diff

def _plot_zero_line(self):
Expand Down