-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
radius modification in contains_point function when linewidth is specified #19807
Description
Bug report
Bug summary
When specifyng linewidth in a patch object and then using the contains_point function the radius of this is set to linewidth and returns inconsistent results. This is somewhat documented here but I think this is an unwanted behaviour since linewidth is specified in points and not in data coordinates, while the contains_point function gonna search for those data points enclosed between the border of the path and half the linewidth.
Code for reproduction
import matplotlib.patches as mpatches
import matplotlib.pyplot as plt
circle_ec = mpatches.Circle((0,0), radius=1, ec='r', lw=1)
circle = mpatches.Circle((0,0), radius=1)
point = (0,1.5)
print(circle_ec.contains_point(point))
print(circle.contains_point(point))Actual outcome
True
False
Expected outcome
The expected output is False in both cases since the point (0, 1.5) is neither in the patch (Circle in this case) neither on the line of the edge. I propose to multiply _radius = self.get_linewidth() in the _process_radius function in the source code by a corrective factor.
Matplotlib version
- Operating system: Windows 10
- Matplotlib version: 3.3.4
- Matplotlib backend: TkAgg
- Python version:
- Jupyter version (if applicable): 3.9.0
- Other libraries:
Installation from pip