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


Python patches.RegularPolygon方法代码示例

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


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

示例1: construct_ball_trajectory

# 需要导入模块: from matplotlib import patches [as 别名]
# 或者: from matplotlib.patches import RegularPolygon [as 别名]
def construct_ball_trajectory(var, r=1., cmap='Blues', start_color=0.4, shape='c'):
    # https://matplotlib.org/examples/color/colormaps_reference.html
    patches = []
    for pos in var:
        if shape == 'c':
            patches.append(mpatches.Circle(pos, r))
        elif shape == 'r':
            patches.append(mpatches.RegularPolygon(pos, 4, r))
        elif shape == 's':
            patches.append(mpatches.RegularPolygon(pos, 6, r))

    colors = np.linspace(start_color, .9, len(patches))
    collection = PatchCollection(patches, cmap=cm.get_cmap(cmap), alpha=1.)
    collection.set_array(np.array(colors))
    collection.set_clim(0, 1)
    return collection 
开发者ID:simonkamronn,项目名称:kvae,代码行数:18,代码来源:plotting.py

示例2: test_HexElectrode

# 需要导入模块: from matplotlib import patches [as 别名]
# 或者: from matplotlib.patches import RegularPolygon [as 别名]
def test_HexElectrode():
    with pytest.raises(TypeError):
        HexElectrode(0, 0, 0, [1, 2])
    with pytest.raises(TypeError):
        HexElectrode(0, np.array([0, 1]), 0, 1)
    # Invalid radius:
    with pytest.raises(ValueError):
        HexElectrode(0, 0, 0, -5)
    # Check params:
    electrode = HexElectrode(0, 1, 2, 100)
    npt.assert_almost_equal(electrode.x, 0)
    npt.assert_almost_equal(electrode.y, 1)
    npt.assert_almost_equal(electrode.z, 2)
    npt.assert_almost_equal(electrode.a, 100)
    # Slots:
    npt.assert_equal(hasattr(electrode, '__slots__'), True)
    npt.assert_equal(hasattr(electrode, '__dict__'), False)
    # Plots:
    ax = electrode.plot()
    npt.assert_equal(len(ax.texts), 0)
    npt.assert_equal(len(ax.patches), 1)
    npt.assert_equal(isinstance(ax.patches[0], RegularPolygon), True) 
开发者ID:pulse2percept,项目名称:pulse2percept,代码行数:24,代码来源:test_electrodes.py

示例3: test_PhotovoltaicPixel

# 需要导入模块: from matplotlib import patches [as 别名]
# 或者: from matplotlib.patches import RegularPolygon [as 别名]
def test_PhotovoltaicPixel():
    electrode = PhotovoltaicPixel(0, 1, 2, 3, 4)
    npt.assert_almost_equal(electrode.x, 0)
    npt.assert_almost_equal(electrode.y, 1)
    npt.assert_almost_equal(electrode.z, 2)
    npt.assert_almost_equal(electrode.r, 3)
    npt.assert_almost_equal(electrode.a, 4)
    # Slots:
    npt.assert_equal(hasattr(electrode, '__slots__'), True)
    npt.assert_equal(hasattr(electrode, '__dict__'), False)
    # Plots:
    ax = electrode.plot()
    npt.assert_equal(len(ax.texts), 0)
    npt.assert_equal(len(ax.patches), 2)
    npt.assert_equal(isinstance(ax.patches[0], RegularPolygon), True)
    npt.assert_equal(isinstance(ax.patches[1], Circle), True)
    PhotovoltaicPixel(0, 1, 2, 3, 4) 
开发者ID:pulse2percept,项目名称:pulse2percept,代码行数:19,代码来源:test_prima.py

示例4: __rotating_spring_support_patch

# 需要导入模块: from matplotlib import patches [as 别名]
# 或者: from matplotlib.patches import RegularPolygon [as 别名]
def __rotating_spring_support_patch(self, max_val):
        """
        :param max_val: max scale of the plot
        """
        radius = PATCH_SIZE * max_val

        for node, _ in self.system.supports_spring_y:
            r = np.arange(0, radius, 0.001)
            theta = 25 * np.pi * r / (0.2 * max_val)
            x = np.cos(theta) * r + node.vertex.x
            y = np.sin(theta) * r - radius + node.vertex.y
            self.one_fig.plot(x, y, color="r", zorder=9)

            # Triangle
            support_patch = mpatches.RegularPolygon(
                (node.vertex.x, node.vertex.y - radius * 3),
                numVertices=3,
                radius=radius * 0.9,
                color="r",
                zorder=9,
            )
            self.one_fig.add_patch(support_patch) 
开发者ID:ritchie46,项目名称:anaStruct,代码行数:24,代码来源:mpl.py

示例5: __init__

# 需要导入模块: from matplotlib import patches [as 别名]
# 或者: from matplotlib.patches import RegularPolygon [as 别名]
def __init__(self, x, y, z, r, a):
        super(PhotovoltaicPixel, self).__init__(x, y, z, a)
        if isinstance(r, (Sequence, np.ndarray)):
            raise TypeError("Radius of the active electrode must be a scalar.")
        if r <= 0:
            raise ValueError("Radius of the active electrode must be > 0, not "
                             "%f." % r)
        self.r = r
        # Plot two objects: hex honeycomb and circular active electrode
        self.plot_patch = [RegularPolygon, Circle]
        self.plot_kwargs = [{'radius': a, 'numVertices': 6, 'alpha': 0.2,
                             'orientation': np.radians(30), 'fc': 'k',
                             'ec': 'k'},
                            {'radius': r, 'linewidth': 0, 'color': 'k',
                             'alpha': 0.5}] 
开发者ID:pulse2percept,项目名称:pulse2percept,代码行数:17,代码来源:prima.py

示例6: add_structure

# 需要导入模块: from matplotlib import patches [as 别名]
# 或者: from matplotlib.patches import RegularPolygon [as 别名]
def add_structure(ax, patches, position, spacegroup, energy):
    """
    Add one polygon to the patches list

    :param ax:
    :param patches:
    :param position:
    :param spacegroup:
    :param energy:
    :return:
    """
    polygon = mpatches.RegularPolygon(position, spacegroup2poly(spacegroup), 0.5, clip_on=True)
    patches.append(polygon)
    label(ax, position, spacegroup, energy) 
开发者ID:MaterialsDiscovery,项目名称:PyChemia,代码行数:16,代码来源:searcher.py

示例7: __hinged_support_patch

# 需要导入模块: from matplotlib import patches [as 别名]
# 或者: from matplotlib.patches import RegularPolygon [as 别名]
def __hinged_support_patch(self, max_val):
        """
        :param max_val: max scale of the plot
        """
        radius = PATCH_SIZE * max_val
        for node in self.system.supports_hinged:
            support_patch = mpatches.RegularPolygon(
                (node.vertex.x, node.vertex.y - radius),
                numVertices=3,
                radius=radius,
                color="r",
                zorder=9,
            )
            self.one_fig.add_patch(support_patch) 
开发者ID:ritchie46,项目名称:anaStruct,代码行数:16,代码来源:mpl.py

示例8: __roll_support_patch

# 需要导入模块: from matplotlib import patches [as 别名]
# 或者: from matplotlib.patches import RegularPolygon [as 别名]
def __roll_support_patch(self, max_val):
        """
        :param max_val: max scale of the plot
        """
        radius = PATCH_SIZE * max_val
        count = 0
        for node in self.system.supports_roll:
            direction = self.system.supports_roll_direction[count]
            x1 = np.cos(np.pi) * radius + node.vertex.x + radius
            z1 = np.sin(np.pi) * radius + node.vertex.y
            x2 = np.cos(np.radians(90)) * radius + node.vertex.x + radius
            z2 = np.sin(np.radians(90)) * radius + node.vertex.y
            x3 = np.cos(np.radians(270)) * radius + node.vertex.x + radius
            z3 = np.sin(np.radians(270)) * radius + node.vertex.y

            triangle = np.array([[x1, z1], [x2, z2], [x3, z3]])

            if node.id in self.system.inclined_roll:
                angle = self.system.inclined_roll[node.id]
                triangle = rotate_xy(triangle, angle + np.pi * 0.5)
                support_patch = plt.Polygon(triangle, color="r", zorder=9)
                self.one_fig.add_patch(support_patch)
                self.one_fig.plot(
                    triangle[1:, 0] - 0.5 * radius * np.sin(angle),
                    triangle[1:, 1] - 0.5 * radius * np.cos(angle),
                    color="r",
                )

            elif direction == 2:  # horizontal roll
                support_patch = mpatches.RegularPolygon(
                    (node.vertex.x, node.vertex.y - radius),
                    numVertices=3,
                    radius=radius,
                    color="r",
                    zorder=9,
                )
                self.one_fig.add_patch(support_patch)
                y = -node.vertex.z - 2 * radius
                self.one_fig.plot(
                    [node.vertex.x - radius, node.vertex.x + radius], [y, y], color="r"
                )
            elif direction == 1:  # vertical roll
                # translate the support to the node

                support_patch = mpatches.Polygon(triangle, color="r", zorder=9)
                self.one_fig.add_patch(support_patch)

                y = node.vertex.y - radius
                self.one_fig.plot(
                    [node.vertex.x + radius * 1.5, node.vertex.x + radius * 1.5],
                    [y, y + 2 * radius],
                    color="r",
                )
            count += 1 
开发者ID:ritchie46,项目名称:anaStruct,代码行数:56,代码来源:mpl.py

示例9: __spring_support_patch

# 需要导入模块: from matplotlib import patches [as 别名]
# 或者: from matplotlib.patches import RegularPolygon [as 别名]
def __spring_support_patch(self, max_val):
        """
        :param max_val: max scale of the plot
        """
        h = PATCH_SIZE * max_val
        left = -0.5 * h
        right = 0.5 * h
        dh = 0.2 * h

        for node, _ in self.system.supports_spring_z:
            yval = np.arange(0, -9, -1) * dh + node.vertex.y
            xval = (
                np.array([0, 0, left, right, left, right, left, 0, 0]) + node.vertex.x
            )

            self.one_fig.plot(xval, yval, color="r", zorder=10)

            # Triangle
            support_patch = mpatches.RegularPolygon(
                (node.vertex.x, -node.vertex.z - h * 2.6),
                numVertices=3,
                radius=h * 0.9,
                color="r",
                zorder=10,
            )
            self.one_fig.add_patch(support_patch)

        for node, _ in self.system.supports_spring_x:
            xval = np.arange(0, 9, 1) * dh + node.vertex.x
            yval = (
                np.array([0, 0, left, right, left, right, left, 0, 0]) + node.vertex.y
            )

            self.one_fig.plot(xval, yval, color="r", zorder=10)

            # Triangle
            support_patch = mpatches.RegularPolygon(
                (node.vertex.x + h * 1.7, -node.vertex.z - h),
                numVertices=3,
                radius=h * 0.9,
                color="r",
                zorder=10,
            )
            self.one_fig.add_patch(support_patch) 
开发者ID:ritchie46,项目名称:anaStruct,代码行数:46,代码来源:mpl.py


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