Line2D._path obeys drawstyle.#6497
Conversation
For stepping drawstyles, `Line2D.draw` used to recompute a path at drawing time, because its `_path` attribute always assumed a linear drawstyle. Instead, directly compute the correct path. Also fixes matplotlib#6447 (`Line2D.contains` did not take drawstyle into account) because that code relied on proximity of the mouse event with the underlying path.
lib/matplotlib/lines.py
Outdated
|
|
||
| _drawstyle_conv = { | ||
| 'default': lambda x, y: (x, y), | ||
| 'steps': pts_to_prestep, |
There was a problem hiding this comment.
Can you just add these two to STEP_LOOKUP_MAP and correct the spelling of step-pre and friends to steps-*? I suspect I meant to do the refactor you are doing now as part of the work where the fill_between feature got added, but ran out of steam (it was one of the last things to get merged before 1.5.0 iirc).
|
What the input to I would keep the |
|
Like in this version? |
lib/matplotlib/cbook.py
Outdated
| 'step-pre': pts_to_prestep, | ||
| 'step-post': pts_to_poststep, | ||
| 'step-mid': pts_to_midstep} | ||
| 'step-mid': pts_to_midstep, |
There was a problem hiding this comment.
I would remove the step-* entries. They are not documented and this is the only place those strings appear in the code base. I am 98% sure the lack of 's' here was my mistake.
db60992 to
b8fe72c
Compare
|
👍 Will merge once CI finishes. |
matplotlib#6497 set the `_path` attribute of Line2D to the actually drawn path even if the drawstyle is `steps-*`; however containment tests and the subslice optimization for very long paths were not updated accordingly (see matplotlib#6615). This patch fixes the issues. Note that `contains` returns, for events in a horizontal segment of a "steps-mid" drawstyle plot, the index of the point in the segment, regardless of whether the event occured to the left or the right of that point.
For stepping drawstyles,
Line2D.drawused to recompute a path at drawing time, because its_pathattribute always assumed a linear drawstyle. Instead, directly compute the correct path.Also fixes #6447 (
Line2D.containsdid not take drawstyle into account) because that code relied on proximity of the mouse event with the underlying path.Note that unfortunately, the drawstyle names remain inconsistent with those accepted by
fill_betweenandfill_betweenx, which (seem to be the only functions to) rely oncbook.STEP_LOOKUP_MAP. It may be a good opportunity to fix the discrepancy too...