Skip to content

Commit

Permalink
Merge pull request spotify#57 from x4base/fix_axis_format_precision
Browse files Browse the repository at this point in the history
Fix the axis precision when the max value equals to the min value
  • Loading branch information
cphalpert authored Dec 11, 2018
2 parents 7264a79 + 679c2db commit 9e5dd9e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion chartify/_core/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def __init__(self, chart):
@staticmethod
def _axis_format_precision(max_value, min_value):
difference = abs(max_value - min_value)
precision = abs(int(np.floor(np.log10(difference)))) + 1
precision = abs(int(np.floor(
np.log10(difference if difference else 1)))) + 1
zeros = ''.join(['0']*precision)
return "0,0.[{}]".format(zeros)

Expand Down
1 change: 1 addition & 0 deletions tests/test_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ class TestAxisFormatPrecision:

def setup(self):
self.tests = {
(0, 0): "0,0.[0]",
(0, 0.004): "0,0.[0000]",
(0, 0.04): "0,0.[000]",
(0, 0.4): "0,0.[00]",
Expand Down

0 comments on commit 9e5dd9e

Please sign in to comment.