Пример #1
0
def fibers_2d_xy():
    '''
        Plot fibers in 2D section (plane XY)
    '''
    fig3 = figure(5)
    ax3 = Axes(fig3, [.1, .1, .8, .8])

    fig3.add_axes(ax3)
    for i in range(0, len(sx[0])):
        l = Line2D([sx[0][i] - fib.lf / 2. * cos(phi_x[0][i]), sx[0][i] + fib.lf / 2. * cos(phi_x[0][i])], \
                     [sy[0][i] - fib.lf / 2. * cos(phi_y[0][i]), sy[0][i] + fib.lf / 2. * cos(phi_y[0][i])], \
                      linewidth = .5, color = 'black')
        #print  i, sx[0][i], lf / 2. * cosphi_x[0][i], [sx[0][i] - lf / 2. * cosphi_x[0][i], sx[0][i] + lf / 2. * cosphi_x[0][i]], \
        #             [sy[0][i] - lf / 2. * cosphi_y[0][i], sy[0][i] + lf / 2. * cosphi_y[0][i]], \
        #              [sz[0][i] - lf / 2. * cosphi_z[0][i], sz[0][i] + lf / 2. * cosphi_z[0][i]]                    
        ax3.add_line(l)
    ax3.plot(sx, sy, 'ko', markersize = 3.0)
    ax3.plot([ -spec.l_x / 2., spec.l_x / 2. ], [spec.l_y / 2., spec.l_y / 2.], 'k-', linewidth = 2)
    ax3.plot([ -spec.l_x / 2., spec.l_x / 2. ], [-spec.l_y / 2., -spec.l_y / 2.], 'k-', linewidth = 2)
    ax3.plot([ spec.l_x / 2., spec.l_x / 2. ], [-spec.l_y / 2., spec.l_y / 2.], 'k-', linewidth = 2)
    ax3.plot([ -spec.l_x / 2., -spec.l_x / 2. ], [-spec.l_y / 2., spec.l_y / 2.], 'k-', linewidth = 2)
    ax3.set_axis_off()
    #ax3.set_xlim( -l_x / 2., l_x / 2. )
    #ax3.set_ylim( -l_y / 2., l_y / 2. )
    title('Fibers in 2D - xy')
    draw()
Пример #2
0
def visualize_detections_bev(ax: axes.Axes,
                             visualizer_frame: str,
                             targets: Target3DArray,
                             calib: TransformSet,
                             box_color=(0, 1, 0),
                             thickness=2,
                             tags=None):

    # change frame to the same
    if targets.frame != visualizer_frame:
        targets = calib.transform_objects(targets, frame_to=visualizer_frame)

    for target in targets.filter_tag(tags):
        # draw vehicle frames
        points = target.corners
        pairs = [(0, 1), (2, 3), (0, 2), (1, 3)]
        for i, j in pairs:
            ax.add_line(
                lines.Line2D((points[i, 0], points[j, 0]),
                             (points[i, 1], points[j, 1]),
                             c=box_color,
                             lw=thickness))

        # draw velocity
        if isinstance(target, TrackingTarget3D):
            pstart = target.position[:2]
            pend = target.position[:2] + target.velocity[:2]
            ax.add_line(
                lines.Line2D((pstart[0], pend[0]), (pstart[1], pend[1]),
                             c=box_color,
                             lw=thickness))
Пример #3
0
def fibers_2d_yz():
    '''
        Plot fibers in 2D section (plane YZ)
    '''
    fig2 = figure(1)
    ax2 = Axes(fig2, [.1, .1, .8, .8])

    fig2.add_axes(ax2)
    for i in range(0, len(sx[0])):
        l = Line2D([sy[0][i] - fib.lf / 2. * cos(phi_y[0][i]), sy[0][i] + fib.lf / 2. * cos(phi_y[0][i])], \
                      [sz[0][i] - fib.lf / 2. * cos(phi_z[0][i]), sz[0][i] + fib.lf / 2. * cos(phi_z[0][i])], \
                      linewidth = .5)
        #print  i, sx[0][i], lf / 2. * cosphi_x[0][i], [sx[0][i] - lf / 2. * cosphi_x[0][i], sx[0][i] + lf / 2. * cosphi_x[0][i]], \
        #             [sy[0][i] - lf / 2. * cosphi_y[0][i], sy[0][i] + lf / 2. * cosphi_y[0][i]], \
        #              [sz[0][i] - lf / 2. * cosphi_z[0][i], sz[0][i] + lf / 2. * cosphi_z[0][i]]                    
        ax2.add_line(l)
    ax2.plot(sy, sz, 'ro')
    ax2.plot([ -spec.l_y / 2., spec.l_y / 2. ], [spec.l_z / 2., spec.l_z / 2.], 'r-')
    ax2.plot([ -spec.l_y / 2., spec.l_y / 2. ], [-spec.l_z / 2., -spec.l_z / 2.], 'r-')
    ax2.plot([ spec.l_y / 2., spec.l_y / 2. ], [-spec.l_z / 2., spec.l_z / 2.], 'r-')
    ax2.plot([ -spec.l_y / 2., -spec.l_y / 2. ], [-spec.l_z / 2., spec.l_z / 2.], 'r-')
    #ax2.set_xlim( -l_y / 2., l_y / 2. )
    #ax2.set_ylim( -l_z / 2., l_z / 2. )
    title('Fibers in 2D - yz')
    draw()
    return 0
def draw_timeline(file_score_dict: dict, threshold: int, ax: Axes):
    runs = sorted(file_score_dict.keys())
    ax.plot(range(1, len(runs) + 1), [file_score_dict[x][1] for x in runs], '-o')
    ax.set_xlabel('Runs')
    ax.set_ylabel('MSE detection score')
    ax.set_title('MSE detection score over time')
    ax.add_line(lines.Line2D([0, len(runs)], [threshold, threshold]))
def display_top_down( arrX, arrY ):

    fig = plt.figure(1)
    ax = Axes(fig, [.1,.1,.8,.8]) 
    fig.add_axes(ax)                                           
    l = Line2D( arrX, arrY)                    
    ax.add_line(l)        

    plt.plot( arrX, arrY, 'ro' )
Пример #6
0
def drawG(fig, n, roundN, graphs):
    graphsId = difGraphsId(graphs)
    size = len(graphsId)
    print 'size ', size
    bgnX = 0.1
    bgnY = 0.1
    width = 0.8 / size
    height = 0.35

    for idx in range(size):
        ax = Axes(fig, [bgnX, bgnY, width * 0.9, height])
        ax.set_xticks(range(-1,3))
        ax.set_yticks(range(-1, n+1))
        ax.set_frame_on(False)

        gid = graphsId[idx]
        ax.set_title( 'Round ' + str(gid+1) )

        for i in range(-1, n + 1):
            ax.plot(0, i, marker = 'o')
            ax.plot(1, i, marker = 'o')

        for edge in graphs[gid]:
            nodes = [int(i) for i in edge.split('-')]
            nodes[1] -= n
            line = Line2D([0, 1], nodes)

            if gid == 0:
                line.set_color('b')
            else:
                color = 'r'
                for e in graphs[gid-1]:
                    if edge == e:
                        color = 'b'
                        break
                line.set_color(color)

            ax.add_line( line )

        preId = max(gid-1, 0)
        for edge in graphs[preId]:
            color = 'g'
            for e in graphs[gid]:
                if edge == e:
                    color = 'b'
                    break

            if color == 'g':
                nodes = [int(i) for i in edge.split('-')]
                nodes[1] -= n
                line = Line2D([0, 1], nodes, linestyle= '--')
                line.set_color(color)
                ax.add_line( line )

        fig.add_axes( ax )
        bgnX += width
Пример #7
0
    def draw(self, ax: Axes, col) -> None:
        pt = np.transpose(self.p)
        if self.close:
            pt = np.hstack([pt, pt[:, :1]])

        x, y = pt[:2, :]
        x /= pt[2, :]
        y /= pt[2, :]

        poly_line = m_lines.Line2D(x, y, color=col)
        ax.add_line(poly_line)
def draw_vector(ax: Axes,
                start_point: MsPoint,
                end_point: MsPoint,
                color='red',
                linewidth=1):
    line1 = [start_point, end_point]
    # zip是拿来做什么的?将两个点生成序列?
    (line1_xs, line1_ys) = zip(*line1)
    # 不能再绘制极坐标之后绘制,会破坏笛卡尔坐标
    ax.add_line(
        plt.Line2D(line1_xs, line1_ys, color=color, linewidth=linewidth))
Пример #9
0
def candlestick_chart(
    ax: Axes,
    df: DataFrame,
    *,
    heikin_ashi: bool = False,
    colorup: str = 'forestgreen',
    colordown: str = 'orangered',
    width: float = .6,
    alpha: float = 1.,
) -> None:
    # The area between the open and the close prices is called the body,
    # price excursions above and below the body are shadows (also called
    # wicks). Wicks illustrate the highest and lowest traded prices of an
    # asset during the time interval represented. The body illustrates the
    # opening and closing trades. This entire structure is called a candle.
    offset = width / 2.
    prev = None
    for t, row in df.iterrows():
        t = date2num(t)
        o0, h0, l0, c0 = row['Open'], row['High'], row['Low'], row['Close']
        if heikin_ashi:
            # pylint: disable=W8201
            if prev is None:
                oP, hP, lP, cP = o0, h0, l0, c0
            else:
                oP, hP, lP, cP = prev
            c = (o0 + h0 + l0 + c0) / 4.
            o = (oP + cP) / 2.
            h = max(h0, o, c)
            l = min(l0, o, c)
            prev = o, h, l, c
        else:
            o, h, l, c = o0, h0, l0, c0  # pylint: disable=W8201
        if c >= o:
            color = colorup
            lower = o
            upper = c
        else:
            color = colordown
            lower = c
            upper = o
        height = upper - lower
        ax.add_line(
            Line2D(xdata=(t, t), ydata=(lower, l), color=color, alpha=alpha))
        ax.add_line(
            Line2D(xdata=(t, t), ydata=(upper, h), color=color, alpha=alpha))
        ax.add_patch(
            Rectangle(xy=(t - offset, lower),
                      width=width,
                      height=height,
                      facecolor=color,
                      edgecolor=color,
                      alpha=alpha))
Пример #10
0
def visualize_detections(ax: axes.Axes,
                         image_frame: str,
                         targets: Target3DArray,
                         calib: TransformSet,
                         box_color=(0, 1, 0),
                         thickness=2,
                         tags=None):
    '''
    Draw detected object on matplotlib canvas
    '''
    for target in targets.filter_tag(tags):
        # add points for direction indicator
        points = target.corners
        indicator = np.array(
            [[0, 0, -target.dimension[2] / 2],
             [target.dimension[0] / 2, 0,
              -target.dimension[2] / 2]]).dot(target.orientation.as_matrix().T)
        points = np.vstack([points, target.position + indicator])

        # project points
        uv, mask, dmask = calib.project_points_to_camera(
            points,
            frame_to=image_frame,
            frame_from=targets.frame,
            remove_outlier=False,
            return_dmask=True)
        if len(uv[mask]) < 1:
            continue  # ignore boxes that is outside the image
        uv = uv.astype(int)

        # draw box
        pairs = [(0, 1), (2, 3), (4, 5), (6, 7), (0, 4), (1, 5), (2, 6),
                 (3, 7), (0, 2), (1, 3), (4, 6), (5, 7)]
        inlier = [i in mask for i in range(len(uv))]
        for i, j in pairs:
            if not inlier[i] and not inlier[j]:
                continue
            if i not in dmask or j not in dmask:
                continue  # only calculate for points ahead
            ax.add_line(
                lines.Line2D((uv[i, 0], uv[j, 0]), (uv[i, 1], uv[j, 1]),
                             c=box_color,
                             lw=thickness))
        # draw direction
        ax.add_line(
            lines.Line2D((uv[-2, 0], uv[-1, 0]), (uv[-2, 1], uv[-1, 1]),
                         c=box_color,
                         lw=thickness))
Пример #11
0
def bar_chart(ax: Axes,
              df: DataFrame,
              *,
              color: str = 'black',
              width: float = .6,
              alpha: float = 1.) -> None:
    # The vertical line represents the high and low for the period, while
    # the line to the left marks the open price and the line to the right
    # marks the closing price. This entire structure is called a bar.
    offset = width / 2.
    for t, row in df.iterrows():
        t = date2num(t)
        o, h, l, c = row['Open'], row['High'], row['Low'], row['Close']
        ax.add_line(
            Line2D(xdata=(t, t),
                   ydata=(l, h),
                   color=color,
                   alpha=alpha,
                   zorder=0))
        ax.add_line(
            Line2D(xdata=(t - offset, t),
                   ydata=(o, o),
                   color=color,
                   alpha=alpha,
                   zorder=0))
        ax.add_line(
            Line2D(xdata=(t, t + offset),
                   ydata=(c, c),
                   color=color,
                   alpha=alpha,
                   zorder=0))
Пример #12
0
    def _plot(self, ax: Axes, position_kwargs: dict, heading_kwargs: dict):
        """ adds a representation of this critter to matplotlib axis object

        position_kwargs should likely have keys [radius, zorder, facecolor, edgecolor]
        heading_kwargs should likely have keys [color, linewidth, zorder]
        """

        # position
        p0 = self.location.position
        patch = CirclePolygon(p0, **position_kwargs)
        ax.add_artist(patch)

        # heading indicator
        if "hlen" not in heading_kwargs.keys():
            hlen = 0.08
        else:
            hlen = heading_kwargs["hlen"]

        p1 = (cos(self.location.heading) * hlen + p0[0],
              sin(self.location.heading) * hlen + p0[1])
        line = Line2D(p0, p1, **heading_kwargs)
        ax.add_line(line)
        return ax
Пример #13
0
#sec = rand( 1, n_sec ) * l_x
sec = linspace( 0, l_x, n_sec )
for i in range( 0, n_sec ):
    vec_cut = func( sx, lx, sec[i] )
    v.append( sum( vec_cut ) )
    

    

# plot specimen with fibers
fig = Figure()  #figsize=[4, 4]
ax = Axes( fig, [.1, .1, .8, .8] )                              
fig.add_axes( ax )                
for i in range( 0, len( sx[0] ) ):                        
    l = Line2D( [sx[0][i] - lf / 2. * cosO[0][i], sx[0][i] + lf / 2. * cosO[0][i]], [sy[0][i], sy[0][i]] )#- lf / 2. * sin( arccos( cosO[0][i] ) )                          
    ax.add_line( l ) 
ax.set_xlim( 0, 500 )
ax.set_ylim( 0, 100 )
                                            
canvas = FigureCanvasAgg( fig )    
         
canvas.print_figure( "specimen.png" )   

# plot histogram
pdf, bins, patches = hist( v, 1000, normed=0 ) #, facecolor='green', alpha=1
#plot( sx, sy, 'rx' )   # centroids
#print sum( pdf * diff( bins ) )
show()


def newline(ax: Axes, p1: List[float], p2: List[float]):
    l = mlines.Line2D([p1[0], p2[0]], [p1[1], p2[1]])
    ax.add_line(l)
    return l
Пример #15
0
f.close()
print("AERMOD receptor definition written to %s" % outputFile)

print("Plot roads and grid points")

fig = Figure(figsize=[14, 14])
ax = Axes(fig, [.1, .1, .8, .8])

# Add coordinates as lines to the plot
for i in range(len(knew)):
    #for i in range(10):
    (line1_xs, line1_ys) = zip(*knew[i])
    #(line1_xs, line1_ys) = knew[i]

    fig.add_axes(ax)
    ax.add_line(Line2D(line1_xs, line1_ys, linewidth=2, color='k'))
    ax.set_xlim(temp_xmin, temp_xmax)
    ax.set_ylim(temp_ymin, temp_ymax)

# Plot road following points in red
ax.scatter(road_x, road_y, color='red', s=3)

# Plot background points in green
ax.scatter(bg_x, bg_y, color='green', s=3)

ax.set_xlim(temp_xmin, temp_xmax)
ax.set_ylim(temp_ymin, temp_ymax)
ax.set_aspect('equal')
canvas = FigureCanvasAgg(fig)
canvas.print_figure("/nobackup/users/patel/Segments/final_grid.png")
Пример #16
0
def plot_kline_candlestick(ax: Axes,
                           df: pandas.DataFrame,
                           colordown: str = 'r',
                           colorup: str = 'g',
                           alpha: float = 1.0) -> Axes:
    """
    Plot the time, open, high, low, close as a vertical line ranging
    from low to high.  Use a rectangular bar to represent the
    open-close span.  If close >= open, use colorup to color the bar,
    otherwise use colordown
    """

    figure: Figure = ax.figure
    f_width = figure.get_figwidth()

    bar_take_axes_size_percentage = 0.04

    bar_width = f_width * bar_take_axes_size_percentage / len(df) / ax.numCols
    offset = bar_width / 2.0

    lines = []
    patches = []
    for row in df.iterrows():
        t = date2num(row[0])
        data = row[1]
        close = data.close
        open = data.open
        high = data.high
        low = data.low
        if close >= open:
            color = colorup
            lower = open
            height = close - open
        else:
            color = colordown
            lower = close
            height = open - close

        vline = Line2D(
            xdata=(t, t),
            ydata=(low, high),
            color=color,
            linewidth=0.5,
            antialiased=True,
        )

        rect = Rectangle(
            xy=(t - offset, lower),
            width=bar_width,
            height=height,
            facecolor=color,
            edgecolor=color,
        )
        rect.set_alpha(alpha)

        lines.append(vline)
        patches.append(rect)
        ax.add_line(vline)
        ax.add_patch(rect)

    return _adjust_axe_timeaxis_view(ax)
Пример #17
0
#ax.set_zlabel( 'Z' )



fig2 = figure( 1 )
ax2 = Axes( fig2, [.1, .1, .8, .8] ) 

fig2.add_axes( ax2 )          
for i in range( 0, len( sx[0] ) ):                        
    l = Line2D( [sy[0][i] - lf / 2. * cosphi_y[0][i], sy[0][i] + lf / 2. * cosphi_y[0][i]], \
                  [sz[0][i] - lf / 2. * cosphi_z[0][i], sz[0][i] + lf / 2. * cosphi_z[0][i]], \
                  linewidth=.5 )     
    #print  i, sx[0][i], lf / 2. * cosphi_x[0][i], [sx[0][i] - lf / 2. * cosphi_x[0][i], sx[0][i] + lf / 2. * cosphi_x[0][i]], \
    #             [sy[0][i] - lf / 2. * cosphi_y[0][i], sy[0][i] + lf / 2. * cosphi_y[0][i]], \
    #              [sz[0][i] - lf / 2. * cosphi_z[0][i], sz[0][i] + lf / 2. * cosphi_z[0][i]]                    
    ax2.add_line( l ) 
ax2.plot( sy, sz, 'ro' )
ax2.set_xlim( -6, 6. )
ax2.set_ylim( -6., 6. )
ax2.plot( [ -l_x / 2., l_x / 2. ], [l_y / 2., l_y / 2.], 'r-' )
ax2.plot( [ -l_x / 2., l_x / 2. ], [-l_y / 2., -l_y / 2.], 'r-' )
ax2.plot( [ l_x / 2., l_x / 2. ], [-l_y / 2., l_y / 2.], 'r-' )
ax2.plot( [ -l_x / 2., -l_x / 2. ], [-l_y / 2., l_y / 2.], 'r-' )


                                         
#canvas = FigureCanvasAgg( fig )    
         
#canvas.print_figure( "specimen3D.png" )