Factor out & improve accuracy of derivatives calculations in axisartist. #24509
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
grid_helper_curvelinear and floating_axes, which can both draw axes that are neither horizontal nor vertical, need to compute the derivatives of the data-coords-to-screen-coords transform (actually, of data-coords-to-data-coords-of-intermediate-horizontal/vertical-axes) to get the angles at which to draw the axes labels, ticks and ticklabels.
Factor out this calculation into a _value_and_jacobian helper. Instead of selecting the step size as some fraction of
lat_factor/lon_factor/delta_extremes, use the square root of machine precision epsilon, which is standard and (approximately) optimal for non-centered numerical differentiation (see e.g.
scipy.optimize.approx_fprime, or the Wikipedia article on numerical differentiation) -- and also happens to avoid introducing an extra paremeter into _value_and_jacobian.
Also lift some calculations out of get_tick_iterators (it doesn't really matter whether they are done inside or outside of get_tick_iterators, but dedenting the block is always nice).
The increases in tolerances arise because the calculations of the derivatives actually become more precise; for example, printing the angle returned by get_axislabel_pos_angle and running test_polar_box shows that previously the axes labels were drawn at angles of (45+1e-11) and 45.135 degrees, whereas they are now drawn at exactly 45 degrees. These tolerances (0.27/0.12) are actually still very small; e.g. removing the text.kerning_factor backcompat setting would require bumping the tolerance to more than 5.
PR Summary
PR Checklist
Documentation and Tests
pytest
passes)Release Notes
.. versionadded::
directive in the docstring and documented indoc/users/next_whats_new/
.. versionchanged::
directive in the docstring and documented indoc/api/next_api_changes/
next_whats_new/README.rst
ornext_api_changes/README.rst