olavolav / uniplot

Lightweight plotting to the terminal. 4x resolution via Unicode.
MIT License
370 stars 16 forks source link

Incorrect axis labels in rare cases #15

Closed olavolav closed 1 year ago

olavolav commented 1 year ago

See here, the correct labels are computed in terms of floating point numbers [-1.4 -0.9 -0.4] but then the string labels are "-0.4", "-0.9" and "-1". The last one is wrong, should of course be "-1.4" so it is cut off at the wrong digit.

See this example:

>>> from uniplot.axis_labels.extended_talbot_labels import extended_talbot_labels
>>> extended_talbot_labels(x_min=-1.846526999372103, x_max=-0.1651564799721942, available_space=17, vertical_direction=True, verbose=True).render()
DEBUG: x_min = -1.846526999372103
DEBUG: x_max = -0.1651564799721942
DEBUG: simplicity = 0.19999999999999996, coverage = 0.9940240106065467, density = -4.666666666666667, grid_alignment = 1 => New best score 😀 = -0.9014939973483634 with labels = [-1.8 -1.7 -1.6 -1.5 -1.4 -1.3 -1.2 -1.1 -1.  -0.9 -0.8 -0.7 -0.6 -0.5
 -0.4 -0.3 -0.2]
DEBUG: simplicity = 0.0, coverage = 0.549810354275108, density = 0.0, grid_alignment = 1 => New best score 😀 = 0.337452588568777 with labels = [-1.4 -0.9 -0.4]
['', '', '-0.4', '', '', '', '', '-0.9', '', '', '', '', '-1', '', '', '', '']