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


Python Path.get_extents方法代码示例

本文整理汇总了Python中matplotlib.path.Path.get_extents方法的典型用法代码示例。如果您正苦于以下问题:Python Path.get_extents方法的具体用法?Python Path.get_extents怎么用?Python Path.get_extents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在matplotlib.path.Path的用法示例。


在下文中一共展示了Path.get_extents方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: distribute_pixels

# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import get_extents [as 别名]
 def distribute_pixels(self, edges, length, width):
     corners = self.get_corners()
     reg_path = Path(corners)
     # Get region boundaries.
     bounds = reg_path.get_extents().get_points()
     [[x_min_bound, y_min_bound], [x_max_bound, y_max_bound]] = bounds
     # For cases when the boundary pixels are not integers:
     x_min_bound = floor(x_min_bound)
     y_min_bound = floor(y_min_bound)
     x_max_bound = ceil(x_max_bound)
     y_max_bound = ceil(y_max_bound)
     pixels_in_bins = []
     for x in range(max(0, x_min_bound), min(x_max_bound+1, width)):
         for y in range(max(0, y_min_bound), min(y_max_bound+1, length)):
             if reg_path.contains_point((x, y)):
                 x_nonrotated, y_nonrotated = rotate_point(self.x0, self.y0,
                                                           x - self.x0,
                                                           y - self.y0,
                                                           -self.angle)
                 dist_from_box_bottom = self.height/2. - \
                                        (self.y0 - y_nonrotated)
                 for i, edge in enumerate(edges[1:]):
                     if edge > dist_from_box_bottom:
                         pixels_in_bins.append((y, x, i))
                         break
     return pixels_in_bins
开发者ID:gogrean,项目名称:PyXel,代码行数:28,代码来源:box.py

示例2: init

# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import get_extents [as 别名]
def init():
    """Initialization"""
    global config, first_names, last_names, aggregate_url, open_hds_connection, odk_connection
    global area_polygon, area_extent, locations_per_social_group, individuals_per_social_group
    global pop_size_baseline, site, min_age_head_of_social_group, proportion_females, birth_rate, death_rate
    global min_age_marriage
    with open(os.path.join(conf_dir, 'config.json')) as config_file:
        config = json.load(config_file)
    with open(os.path.join(conf_dir, 'site.json')) as site_file:
        site = json.load(site_file)
    open_hds_connection = MySQLdb.connect(host=config['open_hds_server']['db_host'],
                                          user=config['open_hds_server']['db_user'],
                                          passwd=config['open_hds_server']['db_password'],
                                          db=config['open_hds_server']['db_name'],
                                          cursorclass=MySQLdb.cursors.DictCursor)
    open_hds_connection.autocommit(True)
    odk_connection = MySQLdb.connect(host=config['odk_server']['db_host'],
                                     user=config['odk_server']['db_user'],
                                     passwd=config['odk_server']['db_password'],
                                     db=config['odk_server']['db_name'],
                                     cursorclass=MySQLdb.cursors.DictCursor)
    odk_connection.autocommit(True)
    aggregate_url = config['odk_server']['aggregate_url']
    with open(os.path.join(conf_dir, 'firstnames.csv')) as f:
        first_names = list(f.read().splitlines(False))
    with open(os.path.join(conf_dir, 'lastnames.csv')) as f:
        last_names = list(f.read().splitlines(False))
    area_outline_vertices = []
    for point in site['general']['area_polygon']:
        area_outline_vertices.append(point)
    area_polygon = Path(area_outline_vertices)
    area_extent = area_polygon.get_extents().get_points()
    pop_size_baseline = site['general']['pop_size_baseline']
    locations_per_social_group = site['socialgroup']['locations_per_social_group']
    individuals_per_social_group = site['socialgroup']['individuals_per_social_group']
    min_age_head_of_social_group = site['socialgroup']['min_age_head']
    min_age_marriage = site['relationship']['min_age_marriage']
    proportion_females = 1 / (1 + site['general']['sex_ratio'])
    birth_rate = site['general']['birth_rate']
    death_rate = site['general']['death_rate']

    if config['general']['clean_db_on_init']:
        clean_db()
        create_fws(site['fieldworker'])
        create_location_hierarchy(site['locationhierarchy'])
开发者ID:ramich,项目名称:openhds-sim,代码行数:47,代码来源:fieldwork_simulator.py

示例3: __str__

# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import get_extents [as 别名]
 def __str__(self):
     if self.shape in ['rectangle', 'ellipse']:
         x, y, wid, hgt = self.geometry
         text = '{0}: ({1:.4G}, {2:.4G}), {3:.4G}, {4:.4G}'
         text = text.format(self.shape.capitalize(), x, y, wid, hgt)
     elif self.shape == 'lasso':
         if not self.geometry:
             return ''
         path = Path(self.geometry)
         extents = path.get_extents()
         x, y = extents.p0
         text = 'Lasso: ({0:.4G}, {1:.4G}), {2:.4G}, {3:.4G}'
         text = text.format(x, y, extents.width, extents.height)
     elif self.shape == 'line' and not self.data is None:
         p1, p2 = self.geometry
         if p1[0] > p2[0]:
             p1, p2 = p2, p1
         dx = p2[0] - p1[0]
         dy = p1[1] - p2[1]
         dist = np.hypot(dx, dy)
         angle = np.arctan2(dy, dx) * 180. / np.pi
         text = 'Line: {0:.4G}, {1} deg, ({2:.4G}, {3:.4G})'
         text = text.format(dist, int(angle), p1[0], p1[1])
     elif self.shape == 'point':
         x, y = self.geometry
         if not self.data is None:
             text = 'Point: {0:.4G} @ ({1:.4G}, {2:.4G})'
             try:
                 text = text.format(self.data[5, 5], x, y)
             except (ValueError, IndexError):
                 pass
         else:
             text = 'Point: ({0:.4G}, {1:.4G})'.format(x, y)
     else:
         text = object.__str__(self)
     return text
开发者ID:blink1073,项目名称:image_inspector,代码行数:38,代码来源:roi.py

示例4: TextPath

# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import get_extents [as 别名]
plot_dims = np.r_[np.diff(ax.get_xbound()), np.diff(ax.get_ybound())]

# create MNE clipping mask
mne_path = TextPath((0, 0), 'MNE')
dims = mne_path.vertices.max(0) - mne_path.vertices.min(0)
vert = mne_path.vertices - dims / 2.
mult = (plot_dims / dims).min()
mult = [mult, -mult]  # y axis is inverted (origin at top left)
offset = plot_dims / 2. - center_fudge
mne_clip = Path(offset + vert * mult, mne_path.codes)
# apply clipping mask to field gradient and lines
im.set_clip_path(mne_clip, transform=im.get_transform())
for coll in cs.collections:
    coll.set_clip_path(mne_clip, transform=im.get_transform())
# get final position of clipping mask
mne_corners = mne_clip.get_extents().corners()

# add tagline
rcParams.update({'font.sans-serif': ['Cooper Hewitt'], 'font.weight': 'light'})
tag_path = TextPath((0, 0), 'MEG + EEG  ANALYSIS & VISUALIZATION')
dims = tag_path.vertices.max(0) - tag_path.vertices.min(0)
vert = tag_path.vertices - dims / 2.
mult = tagline_scale_fudge * (plot_dims / dims).min()
mult = [mult, -mult]  # y axis is inverted
offset = mne_corners[-1] - np.array([mne_clip.get_extents().size[0] / 2.,
                                     -dims[1]]) - tagline_offset_fudge
tag_clip = Path(offset + vert * mult, tag_path.codes)
tag_patch = PathPatch(tag_clip, facecolor='k', edgecolor='none', zorder=10)
ax.add_patch(tag_patch)
yl = ax.get_ylim()
yy = np.max([tag_clip.vertices.max(0)[-1],
开发者ID:EmanuelaLiaci,项目名称:mne-python,代码行数:33,代码来源:generate_mne_logos.py

示例5: cleaned_textpath

# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import get_extents [as 别名]
def cleaned_textpath(text_path):
    """Prepare a matplotlib.textpath.TextPath for intersection checking

    There's a rather nasty little bug hidden in matplotlib's TextPath code
    which causes path intersections to fail.  This works around it by cleaning
    up (and simplifying) the paths.  It is not perfect, as you would see if
    you were to try displaying the resulting paths.

    The basic problem is that vertices associated with a CLOSEPOLY path code
    are supposed to be ignored.  They are in the case of rendering the path
    (which is what made this bug so horrible to track down) but not when
    you are doing other operations, like path intersection or simplifying.
    Since TextPath (for whatever reason) associates gibberish vertices with
    CLOSEPOLY codes, path intersection checks will behave strangely.

    This code splits compound paths into separate paths, and moves the vertex
    for a CLOSEPOLY to the first vertex in the path.

    This eliminates holes in letters such as `e' or `O' but that's a price we
    have to pay.

    Args:
        text_path: A matplotlib.textpath.TextPath

    Returns:
        A list of cleaned up paths.
    """

    paths = list()
    verts = list()
    codes = list()

    for v,c in text_path.iter_segments(curves=False, simplify=False):
        if c == Path.CLOSEPOLY:
            vert = verts[0]
        else:
            vert = v

        if c == Path.MOVETO and len(verts) > 0:
            # We've started a new path.
            newpath = Path(verts, codes)
            newbox = newpath.get_extents()
            
            if len(paths) == 0:
                # If there are no paths we definitely add this one.\
                paths.append(newpath)
            else:
                lastbox = paths[-1].get_extents()
                if bbox_covers(newbox, lastbox):
                    # If this path covers the last one, replace it.
                    paths[-1] = newpath
                elif not bbox_covers(lastbox, newbox):
                    # If the last path doesn't cover this one, throw it out.
                    paths.append(newpath)

            verts = [vert]
            codes = [c]
        else:
            verts.append(vert)
            codes.append(c)

    # Finally, deal with the last path, which may not be explicitly closed.
    if len(verts) > 0:
        newpath = Path(verts, codes)
        newbox = newpath.get_extents()
        if len(paths) == 0:
            paths.append(newpath)
        else:
            lastbox = paths[-1].get_extents()
            if bbox_covers(newbox, lastbox):
                paths[-1] = newpath
            elif not bbox_covers(lastbox, newbox):
                paths.append(newpath)
    
    return paths
开发者ID:pangolinfc,项目名称:WordClouds,代码行数:77,代码来源:BoxifyWord.py

示例6: Path

# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import get_extents [as 别名]
for (vertex, code) in path.iter_segments(simplify = True):
    vertices.append(vertex.tolist())
    codes.append(code)

# <codecell>

cleanpath = Path(vertices, codes)
len(cleanpath)

# <codecell>

codes[-1] = Path.CLOSEPOLY

# <codecell>

bbox = cleanpath.get_extents()
print bbox

# <codecell>

bbox.bounds

# <codecell>

hemi_masked = path.contains_points( hemi_kp )
hemi_kp_masked = hemi_kp[ np.where(hemi_masked) ]

# <codecell>

fig, axs = plt.subplots(1, 2, figsize = (15, 15))
开发者ID:,项目名称:,代码行数:32,代码来源:

示例7: check_api_error

# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import get_extents [as 别名]
            response = pbclient.update_app(app)
            check_api_error(response)
        except:
            format_error("pbclient.update_app", response)

    if args.create_tasks:
        response = pbclient.find_app(short_name='RuralGeolocator')
        app = response[0]
        app_id = app.id
        #polygon around area to be tasked, as list of (lat, long) lists
        rusingaOutlineData = json.load(open('data/area.json'))
        rusingaOutlineVertices = []
        for point in rusingaOutlineData:
            rusingaOutlineVertices.append(point)
        islandPolygon = Path(rusingaOutlineVertices)
        points = islandPolygon.get_extents().get_points()
        #The northern, southern, western, and eastern bounds of the area to work on.
        nb = points[1][0]
        wb = points[0][1]
        sb = points[0][0]
        eb = points[1][1]
        print (nb, wb, sb, eb)
        #Size of the tasks, into how many rows and columns should the area be divided.
        task_cols = 40
        task_rows = 30
        ns_step = (sb - nb) / task_cols
        we_step = (eb - wb) / task_rows
        task_counter = 0
        for row in range(task_rows):
            wbr = wb + row * we_step
            ebr = wb + (row + 1) * we_step
开发者ID:teleyinex,项目名称:app-rural-geolocator,代码行数:33,代码来源:createTasks.py


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