sciapp / gr

GR framework: a graphics library for visualisation applications
Other
329 stars 54 forks source link

Plotting small numbers (all <1e-14) with pygr #57

Closed tv11 closed 5 years ago

tv11 commented 6 years ago

Plotting small numbers in pygr throws an exception File "./.local/lib/python3.5/site-packages/gr-1.0.3.post1-py3.5.egg/gr/pygr/init.py", line 1834, in drawGR xmin, xmax, ymin, ymax = window TypeError: 'NoneType' object is not iterable

The cause of window being None here seems to be in PlotAxes._adjustLogRange, where gr.validaterange(amin, amax) returns false for such small values, leaving _window on its default value None set in init.

lib/gr/gr.c says, that function gr_validaterange checks whether the given coordinate range does not lead to loss of precision. I wonder if the implemented check, which uses only the absolute difference between the two (world) coordinates is correct: if (amin < amax && fabs(amax - amin) * 0.0001 > DBL_EPSILON)

As far as I understand the transformation the critical quantity should be (amax-amin)/amin, as long as amin != 0, similar to the implementation of check_range in gks (but I may miss sth. here): return fabs((b - a) / d) * 0.000001 > DBL_EPSILON;

If I replace the code of the check in gr_validaterange with the code from check_range, I'm able to plot small numbers as expected, without visually noticible changes (at least for my data).

jheinen commented 6 years ago

You are right - I'll fix that. Thanks for the hint.

tv11 commented 6 years ago

in that case you may also take a look on PlotAxes.reset. The tests for math.fabs(xmax - xmin) there seem to be harmless, but superfluous?

tv11 commented 6 years ago

The following test does not need the divison by zero check: (amin < amax && (0.0001/DBL_EPSILON) > fabs(amin / (amax - amin)))

danielkaiser commented 5 years ago

We are closing this issue due to inactivity. Please reopen the issue and let us know if its cause still persists with the current version of GR.