当前位置: 首页>>代码示例>>Python>>正文


Python Rectangle.contains_point方法代码示例

本文整理汇总了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)    
开发者ID:guygriffiths,项目名称:cci-visualisations,代码行数:59,代码来源:cci_timeseries.py


注:本文中的matplotlib.patches.Rectangle.contains_point方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。