Skip to content

Commit 09216f3

Browse files
committed
fix two edge cases in ticking
1 parent f786827 commit 09216f3

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

marslab/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.9.21"
1+
__version__ = "0.9.22"

marslab/imgops/render.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ def _tformat(number: float, order: int, precision: int):
364364
formatted = ("{:." + str(precision) + "e}").format(number)
365365
# remove pointless leading 0 in exponent
366366
return "".join([formatted[:-2], formatted[-1]])
367-
if order + precision < 0:
367+
if order + precision == 0:
368368
return str(round(number))
369369
return str(number)
370370

@@ -377,7 +377,7 @@ def _trylabel(
377377
Attempts to find label positions that maximize coverage while minimizing
378378
required decimal places.
379379
"""
380-
# 100 is arbitrary, basically the resolution of the solver
380+
# 100 is arbitrary -- basically the resolution of the solver
381381
grid = np.linspace(bounds[0], bounds[1], n_ticks * 100)
382382
labels = sorted(
383383
{_tformat(round(n, order + precision), order, precision) for n in grid}
@@ -387,11 +387,12 @@ def _trylabel(
387387
inbounds = (positions <= grid.max()) & (positions >= grid.min())
388388
labels, positions = labels[inbounds], positions[inbounds]
389389
labels, positions = labels[np.argsort(positions)], np.sort(positions)
390-
# NOTE: 20% range cutoff here is totally arbitrary
390+
# NOTE: 15% range cutoff here is totally arbitrary
391+
extent = (grid.max() - grid.min())
391392
if (
392393
positions.size < n_ticks
393-
or abs((positions.max() - grid.max()) / grid.max()) > 0.2
394-
or abs((positions.min() - grid.min()) / grid.min()) > 0.2
394+
or abs((positions.max() - grid.max()) / extent) > 0.15
395+
or abs((positions.min() - grid.min()) / extent) > 0.15
395396
):
396397
# noinspection PyTypeChecker
397398
return labels, False

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
setup(
1111
name="marslab",
12-
version="0.9.21",
12+
version="0.9.22",
1313
url="https://github.com/millionconcepts/marslab.git",
1414
author="Million Concepts",
1515
author_email="[email protected]",

0 commit comments

Comments
 (0)