Example #1
0
def ellipse_patches(node_coords, width, height, angle=0, color=None, **kwargs):
    """
    Function to create a list of ellipse patches from node coordinates.

    :param node_coords: coordinates of the nodes to draw
    :type node_coords: iterable
    :param width: width of the ellipse (described by an exterior rectangle)
    :type width: float
    :param height: height of the ellipse (described by an exterior rectangle)
    :type height: float
    :param angle: angle by which to rotate the ellipse
    :type angle: float
    :param color: color or colors of the patches
    :type color: iterable, float
    :param kwargs: additional keyword arguments to pass to the Ellipse initialization
    :type kwargs: dict
    :return: patches - list of ellipse patches for the nodes
    """
    if not MATPLOTLIB_INSTALLED:
        soft_dependency_error(
            str(sys._getframe().f_code.co_name) + "()", "matplotlib")
    patches = list()
    angles = get_angle_list(angle, len(node_coords))
    if color is not None:
        colors = get_color_list(color, len(node_coords))
        for (x, y), col, ang in zip(node_coords, colors, angles):
            patches.append(
                Ellipse((x, y), width, height, angle=ang, color=col, **kwargs))
    else:
        for (x, y), ang in zip(node_coords, angles):
            patches.append(Ellipse((x, y), width, height, angle=ang, **kwargs))
    return patches
Example #2
0
def source_patches(node_coords, size, angles, **kwargs):
    """
    Creation function of patches for sources.

    :param node_coords: coordinates of the nodes that the sources belong to.
    :type node_coords: iterable
    :param size: size of the patch
    :type size: float
    :param angles: angles by which to rotate the patches (in radians)
    :type angles: iterable(float), float
    :param kwargs: additional keyword arguments (might contain parameter "offset")
    :type kwargs:
    :return: Return values are: \
        - lines (list) - list of coordinates for lines leading to source patches and diagonals\
        - polys (list of RegularPolygon) - list containing the load patches\
        - keywords (set) - set of keywords removed from kwargs
    """
    offset = kwargs.get("offset", size * 2)
    all_angles = get_angle_list(angles, len(node_coords))
    facecolor = kwargs.get("patch_faceolor", "w")
    edgecolor = kwargs.get("patch_edgecolor", "k")
    facecolors = get_color_list(facecolor, len(node_coords))
    edgecolors = get_color_list(edgecolor, len(node_coords))
    polys, lines = list(), list()
    for i, node_geo in enumerate(node_coords):
        p2 = node_geo + _rotate_dim2(np.array([0, offset]), all_angles[i])
        p_edge_left = p2 + _rotate_dim2(np.array([size, size]), all_angles[i])
        p_edge_right = p2 + _rotate_dim2(np.array([- size, size]), all_angles[i])
        p_ll = p2 + _rotate_dim2(np.array([-size, 0]), all_angles[i])
        polys.append(Rectangle(p_ll, 2 * size, 2 * size, angle=(- all_angles[i] / np.pi * 180),
                               fc=facecolors[i], ec=edgecolors[i]))
        lines.append((node_geo, p2))
        lines.append((p2, p_edge_left))
        lines.append((p2, p_edge_right))
    return lines, polys, {"offset"}
Example #3
0
def load_patches(node_coords, size, angles, **kwargs):
    """
    Creation function of patches for loads.

    :param node_coords: coordinates of the nodes that the loads belong to.
    :type node_coords: iterable
    :param size: size of the patch
    :type size: float
    :param angles: angles by which to rotate the patches (in radians)
    :type angles: iterable(float), float
    :param kwargs: additional keyword arguments (might contain parameters "offset",\
        "patch_edgecolor" and "patch_facecolor")
    :type kwargs:
    :return: Return values are: \
        - lines (list) - list of coordinates for lines leading to load patches\
        - polys (list of RegularPolygon) - list containing the load patches\
        - keywords (set) - set of keywords removed from kwargs
    """
    offset = kwargs.get("offset", 1.2 * size)
    all_angles = get_angle_list(angles, len(node_coords))
    edgecolor = kwargs.get("patch_edgecolor", "w")
    facecolor = kwargs.get("patch_facecolor", "w")
    edgecolors = get_color_list(edgecolor, len(node_coords))
    facecolors = get_color_list(facecolor, len(node_coords))
    polys, lines = list(), list()
    for i, node_geo in enumerate(node_coords):
        p2 = node_geo + _rotate_dim2(np.array([0, offset + size]), all_angles[i])
        p3 = node_geo + _rotate_dim2(np.array([0, offset + size / 2]), all_angles[i])
        polys.append(RegularPolygon(p2, numVertices=3, radius=size, orientation=-all_angles[i],
                                    fc=facecolors[i], ec=edgecolors[i]))
        lines.append((node_geo, p3))
    return lines, polys, {"offset", "patch_edgecolor", "patch_facecolor"}
Example #4
0
def gen_patches(node_coords, size, angles, **kwargs):
    """
    Creation function of patches for generators.

    :param node_coords: coordinates of the nodes that the generators belong to.
    :type node_coords: iterable
    :param size: size of the patch
    :type size: float
    :param angles: angles by which to rotate the patches (in radians)
    :type angles: iterable(float), float
    :param kwargs: additional keyword arguments (might contain parameters "offset",\
        "patch_edgecolor" and "patch_facecolor")
    :type kwargs:
    :return: Return values are: \
        - lines (list) - list of coordinates for lines leading to generator patches\
        - polys (list of RegularPolygon) - list containing the generator patches\
        - keywords (set) - set of keywords removed from kwargs
    """
    if not MATPLOTLIB_INSTALLED:
        soft_dependency_error(
            str(sys._getframe().f_code.co_name) + "()", "matplotlib")
    polys, lines = list(), list()
    offset = kwargs.get("offset", 2. * size)
    all_angles = get_angle_list(angles, len(node_coords))
    edgecolor = kwargs.get("patch_edgecolor", "k")
    facecolor = kwargs.get("patch_facecolor", (1, 0, 0, 0))
    edgecolors = get_color_list(edgecolor, len(node_coords))
    facecolors = get_color_list(facecolor, len(node_coords))
    for i, node_geo in enumerate(node_coords):
        p2 = node_geo + _rotate_dim2(np.array([0, size + offset]),
                                     all_angles[i])
        polys.append(Circle(p2, size, fc=facecolors[i], ec=edgecolors[i]))
        polys.append(
            Arc(p2 + np.array([-size / 6.2, -size / 2.6]),
                size / 2,
                size,
                theta1=65,
                theta2=120,
                ec=edgecolors[i]))
        polys.append(
            Arc(p2 + np.array([size / 6.2, size / 2.6]),
                size / 2,
                size,
                theta1=245,
                theta2=300,
                ec=edgecolors[i]))
        lines.append(
            (node_geo, p2 + _rotate_dim2(np.array([0, size]), -all_angles[i])))
    return lines, polys, {"offset", "patch_edgecolor", "patch_facecolor"}
Example #5
0
def ext_grid_patches(node_coords, size, angles, **kwargs):
    """
    Creation function of patches for external grids.

    :param node_coords: coordinates of the nodes that the external grids belong to.
    :type node_coords: iterable
    :param size: size of the patch
    :type size: float
    :param angles: angles by which to rotate the patches (in radians)
    :type angles: iterable(float), float
    :param kwargs: additional keyword arguments (might contain parameters "offset",\
        "patch_edgecolor" and "patch_facecolor")
    :type kwargs:
    :return: Return values are: \
        - lines (list) - list of coordinates for lines leading to external grid patches\
        - polys (list of RegularPolygon) - list containing the external grid patches\
        - keywords (set) - set of keywords removed from kwargs (empty
    """
    if not MATPLOTLIB_INSTALLED:
        soft_dependency_error(
            str(sys._getframe().f_code.co_name) + "()", "matplotlib")
    offset = kwargs.get("offset", 2 * size)
    all_angles = get_angle_list(angles, len(node_coords))
    edgecolor = kwargs.get("patch_edgecolor", "w")
    facecolor = kwargs.get("patch_facecolor", "w")
    edgecolors = get_color_list(edgecolor, len(node_coords))
    facecolors = get_color_list(facecolor, len(node_coords))
    polys, lines = list(), list()
    for i, node_geo in enumerate(node_coords):
        p2 = node_geo + _rotate_dim2(np.array([0, offset]), all_angles[i])
        p_ll = p2 + _rotate_dim2(np.array([-size, 0]), all_angles[i])
        polys.append(
            Rectangle(p_ll,
                      2 * size,
                      2 * size,
                      angle=(-all_angles[i] / np.pi * 180),
                      fc=facecolors[i],
                      ec=edgecolors[i],
                      hatch="XXX"))
        lines.append((node_geo, p2))
    return lines, polys, {"offset", "patch_edgecolor", "patch_facecolor"}