Skip to content

Commit

Permalink
Factor out magic value
Browse files Browse the repository at this point in the history
  • Loading branch information
caiw committed Nov 10, 2023
1 parent 08bf297 commit 5b86c42
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions kymata/plot/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
from kymata.entities.expression import ExpressionSet


# 10 ** -this will be the ytick interval and also the resolution to which the ylims will be rounded
_OOM_SIZE = 50


def expression_plot(
expression_set: ExpressionSet,
show_only: Optional[str | Sequence[str]] = None,
Expand Down Expand Up @@ -158,18 +162,18 @@ def _get_best_xlims(xlims, data_x_min, data_x_max):


def _get_best_ylim(ylim: float | None, data_y_min):
default_y_min = 10 ** -50
default_y_min = 10 ** (-1 * _OOM_SIZE)
if ylim is not None:
return ylim
ylim = min(default_y_min, data_y_min)
# Round to nearest order of magnitude
order_of_magnitude = np.floor(np.log10(ylim) / 50) * 50
order_of_magnitude = np.floor(np.log10(ylim) / _OOM_SIZE) * _OOM_SIZE
ylim = 10 ** order_of_magnitude
return ylim


def _get_yticks(ylim_oom):
order_of_magnitude = int(np.floor(np.log10(ylim_oom) / 50)) * -1
order_of_magnitude = int(np.floor(np.log10(ylim_oom) / _OOM_SIZE)) * -1
return np.geomspace(start=1, stop=ylim_oom, num=order_of_magnitude + 1)


Expand Down

0 comments on commit 5b86c42

Please sign in to comment.