You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
set_segments(get_segments()) makes lines coarse #20551
After plotting with contourf, I would like to retrieve the lines and manipulate them. Unfortunately, I noticed that the result is much coarser than without manipulation. In fact, a simple lc.set_segments(lc.get_segments()) has this effect. I would have expected this does nothing at all.
Interesting between 3.4.2 and the default branch this has changed from a LineCollection to a PathCollection which notable does not even have a get_segments.
@nschloe You identified a different bug which is why does lc.get_segments() aggressively simplify the curve ?!
Internally all Collection flavors boil down to calling renderer.draw_path_collection and all of 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 "should simplify" and "what is the threshold for 'not mattering'" are both set so that they make sense once the path has been converted to pixel space (True and 1/9). In LineCollection.get_segments we are not passing anything special so we are cleaning the path to only include points that make the path deviate by ~0.1111 (which eye-balling looks about right). I think the fix here is to pass simplify=False in LineColleciton.get_segments().
Activity
nschloe commentedon Jun 30, 2021
Aha: There is
which can be manipulated instead.
dmatos2012 commentedon Jun 30, 2021
Hi @nschloe, has your problem been resolved?
tacaswell commentedon Jun 30, 2021
Interesting between 3.4.2 and the default branch this has changed from a
LineCollectionto aPathCollectionwhich notable does not even have aget_segments.nschloe commentedon Jun 30, 2021
get_segments()was wrong apparently, so problem solved for me.tacaswell commentedon Jun 30, 2021
@nschloe You identified a different bug which is why does
lc.get_segments()aggressively simplify the curve ?!Internally all
Collectionflavors boil down to callingrenderer.draw_path_collectionand all of the sub-classes primarily provide nicer user-facing APIs to fabricate the paths that will be passed down to the renderer. InLineCollectionrather than tracking both the user supplied data and the internalPathobjects, we just keep thePathobjects and re-extract segments on demand. To do this we usePath.iter_segmentswith 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). ThePathobjects we are holding have values in data-space, but the default value of "should simplify" and "what is the threshold for 'not mattering'" are both set so that they make sense once the path has been converted to pixel space (Trueand1/9). InLineCollection.get_segmentswe are not passing anything special so we are cleaning the path to only include points that make the path deviate by ~0.1111 (which eye-balling looks about right). I think the fix here is to passsimplify=FalseinLineColleciton.get_segments().tacaswell commentedon Jun 30, 2021
And the change from LineCollection -> PathCollection was 04f4bb6 and is justified.
FIX: do not simplify path in LineCollection.get_segments