本文整理汇总了Python中matplotlib.patches.Rectangle.contains_point方法的典型用法代码示例。如果您正苦于以下问题:Python Rectangle.contains_point方法的具体用法?Python Rectangle.contains_point怎么用?Python Rectangle.contains_point使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.patches.Rectangle
的用法示例。
在下文中一共展示了Rectangle.contains_point方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_emptiest_area
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import contains_point [as 别名]
def _get_emptiest_area(ax, factor, target_x, areas_to_avoid=[]):
"""
Get's the emptiest area of size (1/factor x 1/factor) compared to the overall size of the plot area.
ax - the axes of the plot
factor - 1 / the fraction of the size the area should be
target_x - the ideal x-value for the area to be centred on
areas_to_avoid - a list of figure-space Rectangles which must be avoided
returns a Rectangle in figure-space which
"""
lines = ax.get_lines()
min_points = np.inf
min_rect = None
x_range = ax.get_xlim()
coord_width = x_range[1] - x_range[0]
plot_width = coord_width / factor
y_range = ax.get_ylim()
coord_height = y_range[1] - y_range[0]
plot_height = coord_height / factor
# Change the target x so that the centre will be at the target x
target_x -= plot_width / 2
if target_x < x_range[0]:
target_x = x_range[0]
# Start from the target x as an ideal position, then go right, then left
for i in np.concatenate([np.linspace(target_x, x_range[1] - plot_width, 10), np.linspace(target_x, x_range[0], 10)]):
# Start from the TOP of the plot as ideal, then downwards
for j in np.linspace(y_range[1] - plot_height, y_range[0], 10):
rect = Rectangle([i, j], plot_width, plot_height)
overlap = False
# Check that this rectangle will not overlap any of the explicitly-banned areas
rect_bbox = _coord_space_rect_to_figure_space_rect(rect, ax).get_bbox()
for area in areas_to_avoid:
if rect_bbox.overlaps(area.get_bbox()):
overlap = True
break
if overlap:
continue
points = 0
for line in lines:
for point in line.get_xydata():
if rect.contains_point(point, radius=0.0):
points += 1
if points < min_points:
min_points = points
min_rect = rect
if min_points == 0:
break
if min_points == 0:
break
return _coord_space_rect_to_figure_space_rect(min_rect, ax)