Improve less_simple_linear_interpolation.#9859
Improve less_simple_linear_interpolation.#9859anntzer wants to merge 1 commit intomatplotlib:masterfrom
Conversation
- Rewrite less_simple_linear_interpolation to use np.interp and np.polyfit (for the extrapolation part), document it properly and note the differences with np.interp. - Deprecate extrapolation-less mode (which is well covered by np.interp). - Simplify its usage in contour: only one place needs extrapolation, so the others can use np.interp; -1 is a perfectly reasonable marker for out of bounds which avoids having to dance with the errstate.
| yi[ii] = y[0] | ||
| elif xx > x[-1]: | ||
| if extrap: | ||
| yi[ii] = y[-1] |
There was a problem hiding this comment.
The original is using the same extrapolation method as np.interp uses by default: setting the past-the-end values to the end values of the input array. Are you changing the behavior because what mpl actually needs is linear extrapolation?
There was a problem hiding this comment.
Wow, I actually missed that point because my understanding of the contour code is that it indeed needs extrapolation (but I need to look at it again and run some examples). If we don't actually need extrapolation then we can definitely get rid of this function in favor of using interp.
There was a problem hiding this comment.
I convinced myself that linear extrapolation was not needed because the call to calc_label_rot_and_inline is protected by print_label which is explicitly there to check that the contour line is long enough to host the label text, so we don't expect overflow anyways (so flat extrapolation is as good as anything).
Rewriting in terms of np.interp...
|
Obsoleted by #9865. |
Rewrite less_simple_linear_interpolation to use np.interp and
np.polyfit (for the extrapolation part), document it properly and note
the differences with np.interp.
Deprecate extrapolation-less mode (which is well covered by
np.interp).
Simplify its usage in contour: only one place needs extrapolation, so
the others can use np.interp; -1 is a perfectly reasonable marker for
out of bounds which avoids having to dance with the errstate.
Conflicts with #9151 but the rebase should be easy in either direction, I'm fine with letting #9151 go in first.
Edit: Likely obsoleted by #9865.
PR Summary
PR Checklist