FIX: do not simplify path in LineCollection.get_segments #20584
Merged
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.
PR Summary
Internally all Collection flavors boil down to calling
renderer.draw_path_collection and the sub-classes primarily provide nicer
user-facing APIs to fabricate the paths that will be passed down to the
renderer.
In LineCollection rather than tracking both the user supplied data and the
internal Path objects, we just keep the Path objects and re-extract segments on
demand.
To do this we use Path.iter_segments with defaults to asking the path if it
should simplify the path (that is drop points that do not matter which is in
turn defined by if the deflection away from "straight" is greater than some
threshold). The Path objects we are holding have values in data-space, but the
default value of "what is the threshold for 'not mattering'" is tuned to make
sense in to pixel space (1/9). By passing
simplify=False
toiter_segments
we over-ride the Path object's notion of if it should be simplified (which by
default is controlled by the simplify
threshold (rcParams['path.simplify_threshold']), rcParams['path.simplify'] ,
how long the path is, and if there are any quadratic or Bézier codes in the
path) to never simplify.
In this application we never want to simplify because we do not know enough of
the context when this is called to know what the "right" simplification
threshold is and because we expect
set_segments
andget_segments
toround-trip.
closes #20551
PR Checklist
pytest
passes).flake8
on changed files to check).flake8-docstrings
and runflake8 --docstring-convention=all
).doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).