Thanks to visit codestin.com
Credit goes to github.com

Skip to content

FIX: do not simplify path in LineCollection.get_segments #20584

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

tacaswell
Copy link
Member

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 to iter_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 and get_segments to
round-trip.

closes #20551

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).

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` to `iter_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` and `get_segments` to
round-trip.

closes matplotlib#20551
@tacaswell tacaswell added this to the v3.4.3 milestone Jul 6, 2021
@anntzer anntzer merged commit e996212 into matplotlib:master Jul 6, 2021
@lumberbot-app
Copy link

lumberbot-app bot commented Jul 6, 2021

Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

  1. Checkout backport branch and update it.
$ git checkout v3.4.x
$ git pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
$ git cherry-pick -m1 e9962125786dae3e55ca58b87aa0044c283cd1a6
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
$ git commit -am 'Backport PR #20584: FIX: do not simplify path in LineCollection.get_segments'
  1. Push to a named branch :
git push YOURFORK v3.4.x:auto-backport-of-pr-20584-on-v3.4.x
  1. Create a PR against branch v3.4.x, I would have named this PR:

"Backport PR #20584 on branch v3.4.x"

And apply the correct labels and milestones.

Congratulation you did some good work ! Hopefully your backport PR will be tested by the continuous integration and merged soon!

If these instruction are inaccurate, feel free to suggest an improvement.

@tacaswell tacaswell deleted the fix_linecollection_simplified_segments branch July 6, 2021 22:22
tacaswell pushed a commit to tacaswell/matplotlib that referenced this pull request Jul 6, 2021
…_simplified_segments

FIX: do not simplify path in LineCollection.get_segments
Conflicts:
	lib/matplotlib/tests/test_collections.py
         - only backport the new test
tacaswell pushed a commit to tacaswell/matplotlib that referenced this pull request Jul 6, 2021
…tion.get_segments

Merge pull request matplotlib#20584 from tacaswell/fix_linecollection_simplified_segments

FIX: do not simplify path in LineCollection.get_segments
Conflicts:
	lib/matplotlib/tests/test_collections.py
         - only backport the new test
jklymak added a commit that referenced this pull request Jul 6, 2021
…-v3.4.x

Backport PR #20584: FIX: do not simplify path in LineCollection.get_s…
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

set_segments(get_segments()) makes lines coarse
3 participants