Example #1
0
def draw_xarrows_xy(lines, axes):
    """Creates an XY arrow collection and adds it to the axis.

    Parameters
    ----------
    lines : list of dict
        List of dictionaries containing the arrow line properties.
        The following properties of an arrow can be specified in the dict.

        * start (list): XY(Z) coordinates of the starting point.
        * end (list): XY(Z) coordinates of the end point.
        * text (str, optional): The text of the label. Default is ``None``.
        * textcolor (rgb tuple or hex string, optional): Color of the label text. Default is black.
        * fontsize (int, optional): The size of the font of the label text. Default is ```6``.
        * color (rgb tuple or hex string, optional): Color of the arrow. Default is black.
        * width (float): Width of the arrow. Default is ``1.0``.

    axes : object
        Matplotlib axes.

    """
    arrowprops = {
        'arrowstyle': '-|>,head_length=0.4,head_width=0.2',
        'connectionstyle': 'arc3,rad=0.0',
        'linewidth': 1.0,
        'color': '#000000',
        'shrinkB': 0.05,
    }
    for line in lines:
        sp = line['start']
        ep = line['end']
        text = line.get('text', None)
        textcolor = line.get('textcolor') or '#000000'
        fontsize = line.get('fontsize') or 6
        arrowprops['color'] = color_to_rgb(line.get('color', '#000000'),
                                           normalize=True)
        arrowprops['linewidth'] = line.get('width', 1.0)
        axes.annotate(
            '',
            xy=ep[0:2],
            xytext=sp[0:2],
            arrowprops=arrowprops,
            zorder=ZORDER_LINES,
        )
        if text:
            x, y, z = midpoint_line_xy((sp, ep))
            t = axes.text(x,
                          y,
                          text,
                          fontsize=fontsize,
                          zorder=ZORDER_LABELS,
                          ha='center',
                          va='center',
                          color=color_to_rgb(textcolor, normalize=True))
            t.set_bbox({
                'color': '#ffffff',
                'alpha': 1.0,
                'edgecolor': '#ffffff'
            })
Example #2
0
def draw_xpolylines_xy(polylines, axes):
    patches = []
    paths = []

    widths = []
    colors = []

    for polyline in polylines:
        points = polyline['points']
        codes = [Path.MOVETO] + [Path.LINETO] * (len(points) - 1)

        width = polyline.get('width', 1.0)
        color = polyline.get('color', '#000000')
        text = polyline.get('text', None)
        textcolor = polyline.get('textcolor') or '#000000'
        fontsize = polyline.get('fontsize') or 6

        path = [point[0:2] for point in points]
        paths.append(path)

        widths.append(width)
        colors.append(color_to_rgb(color, normalize=True))

        if text:
            p = len(points)

            if p % 2 == 0:
                a = points[p // 2]
                b = points[p // 2 + 1]
                x, y, z = midpoint_line_xy((a, b))
            else:
                x, y = points[p // 2 + 1]

            t = axes.text(x,
                          y,
                          text,
                          fontsize=fontsize,
                          zorder=ZORDER_LABELS,
                          ha='center',
                          va='center',
                          color=color_to_rgb(textcolor, normalize=True))

            t.set_bbox({
                'color': '#ffffff',
                'alpha': 1.0,
                'edgecolor': '#ffffff'
            })

    coll = PolyCollection(paths,
                          closed=False,
                          linewidths=widths,
                          edgecolors=colors,
                          facecolors='none',
                          zorder=ZORDER_LINES)

    axes.add_collection(coll)

    return coll
Example #3
0
def draw_xlines_xy(lines, axes, alpha=1.0, linestyle='solid'):
    """Creates an XY line collection and adds it to the axis.

    Parameters:
        lines (list): List of dictionaries containing the line properties.
        axes (object): Matplotlib axes.
        alpha (float, list): 0.0 for transparent through 1.0  for opaque.
        linestyle (str, list): Matplotlib line style strings.


    Returns:
        object: The matplotlib line collection object.
    """
    fromto = []
    widths = []
    colors = []
    for line in lines:
        sp = line['start']
        ep = line['end']
        width = line.get('width', 1.0)
        color = line.get('color', '#000000')
        text = line.get('text', None)
        textcolor = line.get('textcolor') or '#000000'
        fontsize = line.get('fontsize') or 24
        fromto.append((sp, ep))
        widths.append(width)
        colors.append(color_to_rgb(color, normalize=True))
        if text:
            x, y, z = midpoint_line_xy((sp, ep))
            t = axes.text(x,
                          y,
                          text,
                          fontsize=fontsize,
                          zorder=ZORDER_LABELS,
                          ha='center',
                          va='center',
                          color=color_to_rgb(textcolor, normalize=True))
            t.set_bbox({
                'color': '#ffffff',
                'alpha': 1.0,
                'edgecolor': '#ffffff'
            })
    coll = LineCollection(fromto,
                          linewidths=widths,
                          colors=colors,
                          linestyle=linestyle,
                          alpha=alpha,
                          zorder=ZORDER_LINES)
    axes.add_collection(coll)
    return coll
Example #4
0
def draw_xarrows_xy(lines, axes):
    """Creates an XY arrow collection and adds it to the axis.

    Parameters:
        lines (list): List of dictionaries containing the arrow line properties.
        axes (object): Matplotlib axes.

    """
    arrowprops = {
        'arrowstyle': '-|>,head_length=0.4,head_width=0.2',
        'connectionstyle': 'arc3,rad=0.0',
        'linewidth': 1.0,
        'color': '#000000',
        'shrinkB': 0.05,
    }
    for line in lines:
        sp = line['start']
        ep = line['end']
        text = line.get('text', None)
        textcolor = line.get('textcolor') or '#000000'
        fontsize = line.get('fontsize') or 6
        arrowprops['color'] = color_to_rgb(line.get('color', '#000000'),
                                           normalize=True)
        arrowprops['linewidth'] = line.get('width', 1.0)
        axes.annotate(
            '',
            xy=ep,
            xytext=sp,
            arrowprops=arrowprops,
            zorder=ZORDER_LINES,
        )
        if text:
            x, y, z = midpoint_line_xy((sp, ep))
            t = axes.text(x,
                          y,
                          text,
                          fontsize=fontsize,
                          zorder=ZORDER_LABELS,
                          ha='center',
                          va='center',
                          color=color_to_rgb(textcolor, normalize=True))
            t.set_bbox({
                'color': '#ffffff',
                'alpha': 1.0,
                'edgecolor': '#ffffff'
            })
Example #5
0
def draw_xarrows_xy(lines, axes):
    arrowprops = {
        'arrowstyle': '-|>,head_length=0.4,head_width=0.2',
        'connectionstyle': 'arc3,rad=0.0',
        'linewidth': 1.0,
        'color': '#000000',
        'shrinkB': 0.05,
    }
    for line in lines:
        sp = line['start']
        ep = line['end']
        text = line.get('text', None)
        textcolor = line.get('textcolor') or '#000000'
        fontsize = line.get('fontsize') or 6
        arrowprops['color'] = line.get('color', '#000000')
        arrowprops['linewidth'] = line.get('width', 1.0)
        axes.annotate(
            '',
            xy=ep,
            xytext=sp,
            arrowprops=arrowprops,
            zorder=ZORDER_LINES,
        )
        if text:
            x, y, z = midpoint_line_xy((sp, ep))
            t = axes.text(x,
                          y,
                          text,
                          fontsize=fontsize,
                          zorder=ZORDER_LABELS,
                          ha='center',
                          va='center',
                          color=textcolor)
            t.set_bbox({
                'color': '#ffffff',
                'alpha': 1.0,
                'edgecolor': '#ffffff'
            })
Example #6
0
def draw_xlines_xy(lines, axes, alpha=1.0, linestyle='solid'):
    fromto = []
    widths = []
    colors = []
    for line in lines:
        sp = line['start']
        ep = line['end']
        width = line.get('width', 1.0)
        color = line.get('color', '#000000')
        text = line.get('text', None)
        textcolor = line.get('textcolor') or '#000000'
        fontsize = line.get('fontsize') or 24
        fromto.append((sp, ep))
        widths.append(width)
        colors.append(color)
        if text:
            x, y, z = midpoint_line_xy((sp, ep))
            t = axes.text(x,
                          y,
                          text,
                          fontsize=fontsize,
                          zorder=ZORDER_LABELS,
                          ha='center',
                          va='center',
                          color=textcolor)
            t.set_bbox({
                'color': '#ffffff',
                'alpha': 1.0,
                'edgecolor': '#ffffff'
            })
    coll = LineCollection(fromto,
                          linewidths=widths,
                          colors=colors,
                          linestyle=linestyle,
                          alpha=alpha,
                          zorder=ZORDER_LINES)
    axes.add_collection(coll)
    return coll
Example #7
0
def draw_xlines_xy(lines, axes, alpha=1.0, linestyle='solid'):
    """Creates an XY line collection and adds it to the axis.

    Parameters
    ----------
    lines : list
        List of dictionaries containing the line properties.
        The following properties of a line can be specified in the dict.

        * start (list): XY(Z) coordinates of the start point.
        * end (list): XY(Z) coordinatesof the end point.
        * width (float, optional): The width of the line. Default is ``1.0``.
        * color (rgb tuple or hex string, optional): The color of the line. Default is black.
        * text (str, optional): The text of the label. Default is ``None``.
        * textcolor (rgb tuple or hex string, optional): Color of the label text. Default is black.
        * fontsize (int, optional): The size of the font of the label text. Default is ```12``.

    axes : object
        Matplotlib axes.
    alpha : float, optional
        Opacity of the lines.
        Default is ``1.0``.
    linestyle : str, optional
        Matplotlib line style strings.
        Default is ``'solid'``.

    Returns
    -------
    object
        The matplotlib line collection object.

    """
    fromto = []
    widths = []
    colors = []
    for line in lines:
        sp = line['start']
        ep = line['end']
        width = line.get('width', 1.0)
        color = line.get('color', '#000000')
        text = line.get('text', None)
        textcolor = line.get('textcolor') or '#000000'
        fontsize = line.get('fontsize') or 6
        fromto.append((sp[0:2], ep[0:2]))
        widths.append(width)
        colors.append(color_to_rgb(color, normalize=True))
        if text:
            x, y, z = midpoint_line_xy((sp, ep))
            t = axes.text(x,
                          y,
                          text,
                          fontsize=fontsize,
                          zorder=ZORDER_LABELS,
                          ha='center',
                          va='center',
                          color=color_to_rgb(textcolor, normalize=True))
            t.set_bbox({'color': '#ffffff', 'alpha': 1.0})
    coll = LineCollection(fromto,
                          linewidths=widths,
                          colors=colors,
                          linestyle=linestyle,
                          alpha=alpha,
                          zorder=ZORDER_LINES)
    axes.add_collection(coll)
    return coll