예제 #1
0
파일: lens.py 프로젝트: mph-/dsp-notebooks
    def draw(self, axes, color='blue', linestyle='-', zorder=1):

        origin = self.origin

        HH = self.H / 2
        
        theta1 = np.degrees(np.arctan(HH / self.f1))
        theta2 = np.degrees(np.arctan(HH / self.f2))

        r1 = np.sqrt(HH**2 + self.f1**2)
        r2 = np.sqrt(HH**2 + self.f2**2)        
        x1 = -self.f1
        x2 = self.f2
        
        origin1 = (origin[0] + x1, origin[1])
        origin2 = (origin[0] + x2, origin[1])        
                            
        e1 = Arc(origin1, width=2 * r1, height=2 * r1,
                 angle=0, theta1=-theta1, theta2=theta1, linewidth=2,
                 zorder=zorder, color=color, linestyle=linestyle)
        axes.add_patch(e1)

        e2 = Arc(origin2, width=2 * r2, height=2 * r2,
                 angle=0, theta1=180 - theta2, theta2=180 + theta2,
                 linewidth=2, zorder=zorder, color=color,
                 linestyle=linestyle)
        axes.add_patch(e2)        
예제 #2
0
def plot_action_sequence(action_storage):
    pitch()
    for action_no, action_sample in enumerate(action_storage):
        x, y = action_sample['observation'][0], action_sample['observation'][1]

        if action_sample['action'][0] < 0.5:
            plt.scatter(x * 100, y * 100, color='C0', zorder=8 + 4 * action_no)
            xt = 1
            yt = 0.5
        else:
            plt.scatter(x * 100, y * 100, color='C1', zorder=8 + 4 * action_no)
            r, a = action_sample['action'][1], action_sample['action'][2]
            xt = x + r * np.cos((a - 0.5) * 2 * np.pi)
            yt = y + r * np.sin((a - 0.5) * 2 * np.pi)

        x, y, xt, yt = x * 100, y * 100, xt * 100, yt * 100

        if xt - x == 0:
            if yt - y > 0:
                angle = 90
            else:
                angle = 270
        else:
            if xt - x > 0:
                angle = np.arctan((yt - y) / (xt - x)) * 360 / np.pi / 2
            else:
                angle = 180 + np.arctan((yt - y) / (xt - x)) * 360 / np.pi / 2
        distance = ((yt - y)**2 + ((xt - x))**2)**(1 / 2)

        all_patches = []
        all_patches.append(
            Wedge((x, y),
                  distance,
                  angle - 0.5,
                  angle + 0.5,
                  fc='#091442',
                  zorder=11 + 4 * action_no))
        all_patches.append(
            Arc((x, y),
                3,
                3 * horizontal_scalling,
                0,
                angle - 45,
                angle + 45,
                lw=7 * action_sample['success'],
                ec='#091442',
                zorder=10 + 4 * action_no))
        all_patches.append(
            Arc((x, y),
                3,
                3 * horizontal_scalling,
                0,
                angle - 45,
                angle + 45,
                lw=7,
                ec='#a2b3ff',
                zorder=9 + 4 * action_no))

        for patch in all_patches:
            plt.gcf().gca().add_artist(patch)
예제 #3
0
def plot_arcs(ax, v1, v2, offset1, offset2):
    theta1 = get_elbow_angle(v1, v2)
    theta2 = get_axillary_angle(v1, v2)

    if offset2 - offset1 > 180:
        e_offset = max(offset1, offset2)
    else:
        e_offset = min(offset1, offset2)

    if offset2 - offset1 < theta2:
        a_offset = max(offset1, offset2)
    else:
        a_offset = min(offset1, offset2)

    arc1 = Arc([0, 0],
               0.5,
               0.5,
               angle=0,
               theta1=e_offset,
               theta2=e_offset + theta1,
               color='g')
    arc2 = Arc([0, 0],
               0.75,
               0.75,
               angle=0,
               theta1=a_offset,
               theta2=a_offset + theta2,
               color='r')

    return arc1, arc2, theta1, theta2
예제 #4
0
 def graphic(self):
     plt.axis('equal')
     plt.gcf().set_size_inches(4, 4)
     #write down all the coordinates and write first one again, to form a closed loop,
     #separate the x's and y's into two lists as below.
     plt.plot([0, 1.7, 2, 0], [0, 2, 0, 1])
     r = 2
     angle = max(30,
                 self.a)  # dont want to draw too narrow. limit to 30 degree
     rad = (angle * math.pi) / 180.0
     plt.gca().add_patch(
         Arc([2, 0],
             0.2,
             0.2,
             angle=200,
             theta1=255,
             theta2=310,
             color="blue"))
     plt.gca().add_patch(
         Arc([0.6, 0.7],
             0.2,
             0.2,
             angle=300,
             theta1=220,
             theta2=290,
             color="blue"))
     plt.text(1.77, 0.15, str(self.a) + u"\u00b0")
     plt.text(0.27, 0.60, str(self.b) + u"\u00b0")
     plt.text(1.63, 1.75, "?")
     buf = BytesIO()
     plt.savefig(buf, format='PNG')
     return self.toBuffer(buf)
예제 #5
0
def draw_circle_harmony():
    ax = pylab.axes()
    ax.set_aspect('equal')
    pylab.xlim(-1, 1)
    pylab.ylim(-1, 1)
    pylab.axis('off')
    innerrad = 0.15
    #
    ##
    angles_deg = 18 + numpy.linspace(0, 360, 6)[:-1]
    angles = numpy.radians(18 + numpy.linspace(0, 360, 6)[:-1])
    theta = numpy.degrees(2 * math.asin(innerrad / 1.0))
    for angle in zip(angles):
        ax.add_patch(
            Circle((0.5 * numpy.cos(angle), 0.5 * numpy.sin(angle)),
                   radius=innerrad,
                   linewidth=4,
                   facecolor='white'))

    for angle_start, angle_end in zip(angles_deg[:-1], angles_deg[1:]):
        angle1 = angle_start + theta
        angle2 = angle_end - theta
        ax.add_patch(
            Arc((0, 0),
                width=1.0,
                height=1.0,
                angle=0.0,
                theta1=angle1,
                theta2=angle2,
                linestyle='dashed',
                linewidth=6))

    angle_end = angles_deg[0] + 360
    angle_start = angles_deg[-1]
    angle1 = angle_start + theta
    angle2 = angle_end - theta
    ax.add_patch(
        Arc((0, 0),
            width=1.0,
            height=1.0,
            angle=0.0,
            theta1=angle1,
            theta2=angle2,
            linestyle='dashed',
            linewidth=6))

    pylab.savefig('circle_harmony.svg', bbox_inches='tight', transparent=True)
    pylab.close()
    #
    ## now open file, remove all fill:#fffff to fill:none
    lines = [
        line.replace('\n', '') for line in open('circle_harmony.svg', 'r')
    ]
    for idx in xrange(len(lines)):
        line = lines[idx]
        line = line.replace('fill:#ffffff', 'fill:none')
        lines[idx] = line
    with open('circle_harmony.svg', 'w') as openfile:
        for line in lines:
            openfile.write('%s\n' % line)
예제 #6
0
def draw_pitch(ax):
    # focus on only half of the pitch
    #Pitch Outline & Centre Line
    Pitch = Rectangle([0,0], width = 120, height = 80, fill = False)
    #Left, Right Penalty Area and midline
    LeftPenalty = Rectangle([0,22.3], width = 14.6, height = 35.3, fill = False)
    RightPenalty = Rectangle([105.4,22.3], width = 14.6, height = 35.3, fill = False)
    midline = ConnectionPatch([60,0], [60,80], "data", "data")

    #Left, Right 6-yard Box
    LeftSixYard = Rectangle([0,32], width = 4.9, height = 16, fill = False)
    RightSixYard = Rectangle([115.1,32], width = 4.9, height = 16, fill = False)


    #Prepare Circles
    centreCircle = plt.Circle((60,40),8.1,color="black", fill = False)
    centreSpot = plt.Circle((60,40),0.71,color="black")
    #Penalty spots and Arcs around penalty boxes
    leftPenSpot = plt.Circle((9.7,40),0.71,color="black")
    rightPenSpot = plt.Circle((110.3,40),0.71,color="black")
    leftArc = Arc((9.7,40),height=16.2,width=16.2,angle=0,theta1=310,theta2=50,color="black")
    rightArc = Arc((110.3,40),height=16.2,width=16.2,angle=0,theta1=130,theta2=230,color="black")
    
    element = [Pitch, LeftPenalty, RightPenalty, midline, LeftSixYard, RightSixYard, centreCircle, 
               centreSpot, rightPenSpot, leftPenSpot, leftArc, rightArc]
    for i in element:
        ax.add_patch(i)
예제 #7
0
def on_move(event):
    # get the x and y pixel coords
    ax.patches.pop()
    if not ax.patches:
        ax.add_patch(unitCircle)
    m_x, m_y = event.x, event.y
    x2, y2 = ax.transData.inverted().transform([m_x, m_y])
    x1 = cur_x[0]
    y1 = cur_y[0]
    global tempCircle
    x, y, r = find_circle(x1, y1, x2, y2)
    tempCircle = Circle((x, y), r, facecolor='none',
                        edgecolor=(0.8, 0.8, 0), linewidth=3, alpha=0.5)
    theta1 = find_theta(x, y, x1, y1)
    theta2 = find_theta(x, y, x2, y2)
    ratio = find_arc_ratio(theta1, theta2)
    if x1 < 0 and x2 < 0 and np.rad2deg(theta1) > 180 and np.rad2deg(theta2) < 180:
        ratio = 0.1
    if ratio > 0:
        if ratio > 0.5:
            arc = Arc((x, y), r * 2, r * 2, 0, np.rad2deg(theta2), np.rad2deg(theta1))
        else:
            arc = Arc((x, y), r * 2, r * 2, 0, np.rad2deg(theta1), np.rad2deg(theta2))
    else:
        if ratio < 0.5:
            arc = Arc((x, y), r * 2, r * 2, 0, np.rad2deg(theta2), np.rad2deg(theta1))
        else:
            arc = Arc((x, y), r * 2, r * 2, 0, np.rad2deg(theta1), np.rad2deg(theta2))
    ax.add_patch(arc)
    canvas.draw()
예제 #8
0
def draw_track(radius, track_length, path):
    track_color = 'lightgrey'
    fig, ax = plt.subplots()
    center = (radius,radius)
    theta1, theta2 = 90, 90 + 180
    w1 = Arc(center, radius*2, radius*2, angle=0.0, theta1=theta1, theta2=theta2,color=track_color,lw=6)
    ax.add_patch(w1)
    x = [i for i in range(int(radius),int(radius+track_length))]
    y1 = [radius*2 for i in range(len(x))]
    y2 = [0 for i in range(len(x))]
    ax.plot(x,y1,c=track_color,lw=6)
    w2 = Arc((center[0]+track_length,radius), radius*2, radius*2, angle=0.0, theta1=theta2, theta2=theta1,color=track_color,lw=6)
    ax.add_patch(w2)
    lns1 = ax.plot(x,y2,c=track_color,lw=6, label='track')
    x = [a for a,b in path]
    y = [b for a,b in path]
    lns2 = ax.plot(x, y, 'k--', label='robot_path')
    lns = lns1+lns2
    labels = [l.get_label() for l in lns]
    ax.legend(lns,labels,loc=4)
    ax.grid()
    ax.set_xlabel("X")
    ax.set_ylabel("Y")
    ax.axis('equal')
    plt.gca().set_xlim(left=-10,right=radius*2+track_length+10)
    plt.title('PID Controller')
    plt.gca().set_ylim(top=max(y1)+1,bottom=min(y2)-1)
    plt.show()
예제 #9
0
 def _plot_free_throw_line(self):
     self.free_throw_circle_a = Arc(
         (19, 25),
         width=6 * 2,
         height=6 * 2,
         theta1=0,
         theta2=90,
         color=self.color,
         linewidth=self.lw,
         fill=False,
     )
     self.free_throw_circle_b = Arc(
         (19, 25),
         width=6 * 2,
         height=6 * 2,
         theta1=90,
         theta2=270,
         color=self.color,
         linewidth=self.lw,
         fill=False,
         linestyle="dashed",
     )
     self.free_throw_circle_c = Arc(
         (19, 25),
         width=6 * 2,
         height=6 * 2,
         theta1=270,
         theta2=0,
         color=self.color,
         linewidth=self.lw,
         fill=False,
     )
예제 #10
0
def create_gen_symbol_collection(net, size=1., infofunc=None, **kwargs):
    lines = []
    polys = []
    infos = []
    off = 1.7
    for i, gen in net.gen.iterrows():
        p1 = net.bus_geodata[["x", "y"]].loc[gen.bus]
        p2 = p1 - np.array([0, size * off])
        polys.append(Circle(p2, size))
        polys.append(
            Arc(p2 + np.array([-size / 6.2, -size / 2.6]),
                size / 2,
                size,
                theta1=45,
                theta2=135))
        polys.append(
            Arc(p2 + np.array([size / 6.2, size / 2.6]),
                size / 2,
                size,
                theta1=225,
                theta2=315))
        lines.append((p1, p2 + np.array([0, size])))
        if infofunc is not None:
            infos.append(infofunc(i))
    gen1 = PatchCollection(polys, facecolor="w", edgecolor="k", **kwargs)
    gen2 = LineCollection(lines, color="k", **kwargs)
    gen1.info = infos
    gen2.info = infos
    return gen1, gen2
예제 #11
0
    def show_on(self, ax):
        import matplotlib.pyplot as plt
        x_vals = []
        y_vals = []
        try:
            _rad_1_displacement = pow(
                self._radius_1**2 - (self._height / 2.)**2, 0.5)
            _rad_2_displacement = pow(
                self._radius_2**2 - (self._height / 2.)**2, 0.5)

            assert not isinstance(_rad_1_displacement,
                                  complex) or not isinstance(
                                      _rad_2_displacement, complex)
        except:
            raise Exception(
                "PYOPTICAL_LENS: Radius/Refractive Index choice leads to Complex Number coordinates, cannot perform plotting"
            )

        from matplotlib.patches import Arc

        _lens_half_1 = Arc((self._position[0], self._position[1]),
                           self._radius_1 - _rad_1_displacement,
                           self._height,
                           theta1=90,
                           theta2=270)
        _lens_half_2 = Arc((self._position[0], self._position[1]),
                           self._radius_2 - _rad_2_displacement,
                           self._height,
                           theta1=270,
                           theta2=90)

        ax.add_patch(_lens_half_1)
        ax.add_patch(_lens_half_2)
예제 #12
0
def plot(plot_datas, ax=None):
    if ax is None:
        fig, ax = plt.subplots()
        ax.set_aspect('equal')
    else:
        fig = None
        
    for plot_data in plot_datas:
        if plot_data['type'] == 'line':
            style = ''
            if plot_data['dash']:
                style += '--'
            else:
                style += '-'
            style += color[plot_data['color']]
            p1, p2 = plot_data['data'][0: 2], plot_data['data'][2:] 
            if plot_data['arrow']:
                ax.plot([p1[0], p2[0]], [p1[1], p2[1]], style)
                length = ((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2)**0.5
                if width is None:
                    width = length / 1000.
                    head_length = length/20.
                    head_width = head_length/2.
                else:
                    head_width = 2*width
                    head_length = head_width
                ax.arrow(p1[0], p1[1], (p2[0] - p1[0])/length*(length - head_length),
                         (p2[1] - p1[1])/length*(length - head_length),
                         head_width = head_width, fc = 'b', linewidth = 0,
                         head_length = head_length, width = width, alpha = 0.3)
            else:
                ax.plot([p1[0], p2[0]], [p1[1], p2[1]], style, linewidth=plot_data['size'])
                
        elif plot_data['type'] == 'point':
            p1 = plot_data['data']
            style = ''
            style += color[plot_data['color']]
            style += plot_data['marker']
            ax.plot(p1[0], p1[1], style, linewidth=plot_data['size'])
            
        elif plot_data['type'] == 'contour':
            plot(plot_data['plot_data'], ax)
            
        elif plot_data['type'] == 'arc':
            pc = vm.Point2D(( plot_data['cx'],  plot_data['cy']))
            ax.add_patch(Arc(pc, 2*plot_data['r'], 2*plot_data['r'], angle=0,
                        theta1=plot_data['angle1']*0.5/math.pi*360,
                        theta2=plot_data['angle2']*0.5/math.pi*360,
                        color=color[plot_data['color']], linewidth=plot_data['size']))
            
        elif plot_data['type'] == 'circle':
            pc = vm.Point2D(( plot_data['cx'],  plot_data['cy']))
            ax.add_patch(Arc(pc, 2*plot_data['r'], 2*plot_data['r'], angle=0,
                        theta1=0,
                        theta2=360,
                        color=color[plot_data['color']], linewidth=plot_data['size']))
    return fig, ax

    
예제 #13
0
def plot_nonlinearity_summary(data, w, pi, ax=None, color='k', label=""):
    """Plot a data summary after inverting it through the psychometric function

    :Example:
    >>> import monkey
    >>> d = pl.array ( zip ( [-2.,-1.,0.,1.,2.],[1,4,10,16,20],[20]*5 ) )
    >>> w = [1.,2.]
    >>> pi = [.07,.05,.85]
    >>> plot_nonlinearity_summary ( d, w, pi )
    >>> pl.savefig ( 'test/plot_nonlinearity_summary.png' )
    """
    def invert(p):
        if p < pi[0] or p > 1 - pi[1]:
            return None
        f = (p - pi[0]) / pi[2]
        e = np.log(f / (1 - f))
        return (e - w[0]) / w[1]

    if ax is None:
        ax = pl.gca()
    ax = prepare_axes(ax)

    x = data[:, 0]
    width = 0.008 * x.ptp()
    set_label = True

    for s, k, n in data:
        p = invert(float(k) / n)
        center = (s, p)
        B = stats.beta(1 + k, 1 + n - k)
        u = invert(B.ppf(.975))
        l = invert(B.ppf(.025))
        if p is None:
            continue
        if not u is None:
            a = Arc(center,
                    width,
                    u - p,
                    theta1=0,
                    theta2=180,
                    facecolor=color,
                    edgecolor=color)
            ax.add_patch(a)
        if not l is None:
            b = Arc(center,
                    width,
                    l - p,
                    theta1=0,
                    theta2=180,
                    facecolor=color,
                    edgecolor=color)
            ax.add_patch(b)
        if set_label and not label == "":
            ax.plot([s - 0.5 * width, s + 0.5 * width], [p] * 2,
                    color=color,
                    label=label)
            set_label = False
        else:
            ax.plot([s - 0.5 * width, s + 0.5 * width], [p] * 2, color=color)
def draw_actions_for_set(agent_set, action_no):
    action_set = []
    success_count = 0
    for agent in agent_set:
        if action_no < len(agent.actions):
            action_set.append(agent.actions[action_no])

            if agent.actions[action_no].description == 'Shot':
                success_count += agent.actions[action_no].xg
            elif agent.actions[action_no].success:
                success_count += 1

    action_sample = action_set[0]
    x, xt, y, yt = action_sample.x * 100, action_sample.xt * 100, action_sample.y * 100, action_sample.yt * 100
    if xt - x == 0:
        if yt - y > 0:
            angle = 90
        else:
            angle = 270
    else:
        if xt - x > 0:
            angle = np.arctan((yt - y) / (xt - x)) * 360 / np.pi / 2
        else:
            angle = 180 + np.arctan((yt - y) / (xt - x)) * 360 / np.pi / 2
    distance = ((yt - y)**2 + ((xt - x))**2)**(1 / 2)

    plt.scatter(x, y, color=action_sample.color, zorder=8 + 4 * action_no)

    all_patches = []
    all_patches.append(
        Wedge((x, y),
              distance,
              angle - 0.5,
              angle + 0.5,
              fc='white',
              zorder=11 + 4 * action_no))
    all_patches.append(
        Arc((x, y),
            3,
            3 * horizontal_scalling,
            0,
            angle - 45,
            angle + 45,
            lw=7 * success_count / len(action_set),
            ec='#611a6a',
            zorder=10 + 4 * action_no))
    all_patches.append(
        Arc((x, y),
            3,
            3 * horizontal_scalling,
            0,
            angle - 45,
            angle + 45,
            lw=7,
            ec='white',
            zorder=9 + 4 * action_no))

    for patch in all_patches:
        plt.gcf().gca().add_artist(patch)
예제 #15
0
파일: plots.py 프로젝트: sdonoso23/ws
def createPitch():
    # Create figure
    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1)

    # Pitch Outline & Centre Line
    plt.plot([0, 0], [0, 90], color="black")
    plt.plot([0, 130], [90, 90], color="black")
    plt.plot([130, 130], [90, 0], color="black")
    plt.plot([130, 0], [0, 0], color="black")
    plt.plot([65, 65], [0, 90], color="black")

    # Left Penalty Area
    plt.plot([16.5, 16.5], [65, 25], color="black")
    plt.plot([0, 16.5], [65, 65], color="black")
    plt.plot([16.5, 0], [25, 25], color="black")

    # Right Penalty Area
    plt.plot([130, 113.5], [65, 65], color="black")
    plt.plot([113.5, 113.5], [65, 25], color="black")
    plt.plot([113.5, 130], [25, 25], color="black")

    # Left 6-yard Box
    plt.plot([0, 5.5], [54, 54], color="black")
    plt.plot([5.5, 5.5], [54, 36], color="black")
    plt.plot([5.5, 0.5], [36, 36], color="black")

    # Right 6-yard Box
    plt.plot([130, 124.5], [54, 54], color="black")
    plt.plot([124.5, 124.5], [54, 36], color="black")
    plt.plot([124.5, 130], [36, 36], color="black")

    # Prepare Circles
    centreCircle = plt.Circle((65, 45), 9.15, color="black", fill=False)
    # centreSpot = plt.Circle((65,45),0.8,color="black")
    # leftPenSpot = plt.Circle((11,45),0.8,color="black")
    # rightPenSpot = plt.Circle((119,45),0.8,color="black")

    # Draw Circles
    ax.add_patch(centreCircle)
    # ax.add_patch(centreSpot)
    # ax.add_patch(leftPenSpot)
    # ax.add_patch(rightPenSpot)

    # Prepare Arcs
    leftArc = Arc((11, 45), height=18.3, width=18.3, angle=0, theta1=310, theta2=50, color="black")
    rightArc = Arc((119, 45), height=18.3, width=18.3, angle=0, theta1=130, theta2=230, color="black")

    # Draw Arcs
    ax.add_patch(leftArc)
    ax.add_patch(rightArc)

    # Tidy Axes
    plt.axis('off')

    # Display Pitch
    # plt.show()
    return ax
def draw_pitch(ax):
    '''
    Source: https://fcpython.com/visualisation/drawing-pitchmap-adding-lines-circles-matplotlib
    '''
    # size of the pitch is 120, 80
    # Create figure

    # Pitch Outline & Centre Line
    plt.plot([0, 0], [0, 80], color="black")
    plt.plot([0, 120], [80, 80], color="black")
    plt.plot([120, 120], [80, 0], color="black")
    plt.plot([120, 0], [0, 0], color="black")
    plt.plot([60, 60], [0, 80], color="black")

    # Left Penalty Area
    plt.plot([14.6, 14.6], [57.8, 22.2], color="black")
    plt.plot([0, 14.6], [57.8, 57.8], color="black")
    plt.plot([0, 14.6], [22.2, 22.2], color="black")

    # Right Penalty Area
    plt.plot([120, 105.4], [57.8, 57.8], color="black")
    plt.plot([105.4, 105.4], [57.8, 22.5], color="black")
    plt.plot([120, 105.4], [22.5, 22.5], color="black")

    # Left 6-yard Box
    plt.plot([0, 4.9], [48, 48], color="black")
    plt.plot([4.9, 4.9], [48, 32], color="black")
    plt.plot([0, 4.9], [32, 32], color="black")

    # Right 6-yard Box
    plt.plot([120, 115.1], [48, 48], color="black")
    plt.plot([115.1, 115.1], [48, 32], color="black")
    plt.plot([120, 115.1], [32, 32], color="black")

    # Prepare Circles
    centreCircle = plt.Circle((60, 40), 8.1, color="black", fill=False)
    centreSpot = plt.Circle((60, 40), 0.71, color="black")
    leftPenSpot = plt.Circle((9.7, 40), 0.71, color="black")
    rightPenSpot = plt.Circle((110.3, 40), 0.71, color="black")

    # Draw Circles
    ax.add_patch(centreCircle)
    ax.add_patch(centreSpot)
    ax.add_patch(leftPenSpot)
    ax.add_patch(rightPenSpot)

    # Prepare Arcs
    # arguments for arc
    # x, y coordinate of centerpoint of arc
    # width, height as arc might not be circle, but oval
    # angle: degree of rotation of the shape, anti-clockwise
    # theta1, theta2, start and end location of arc in degree
    leftArc = Arc((9.7, 40), height=16.2, width=16.2, angle=0, theta1=310, theta2=50, color="black")
    rightArc = Arc((110.3, 40), height=16.2, width=16.2, angle=0, theta1=130, theta2=230, color="black")

    # Draw Arcs
    ax.add_patch(leftArc)
    ax.add_patch(rightArc)
예제 #17
0
    def _plot_football_pitch(scale, lcolour='white', pcolour='grey', fcolour='#444444'):
        #Create figure
        fig=plt.figure(figsize=[scale*6,scale*4])
        ax=fig.add_subplot(1,1,1)
        
        # Set colours
        fig.set_facecolor(fcolour)
        ax.patch.set_facecolor(pcolour)

        #Pitch Outline & Centre Line
        plt.plot([0,0],[0,90], color=lcolour)
        plt.plot([0,130],[90,90], color=lcolour)
        plt.plot([130,130],[90,0], color=lcolour)
        plt.plot([130,0],[0,0], color=lcolour)
        plt.plot([65,65],[0,90], color=lcolour)

        #Left Penalty Area
        plt.plot([16.5,16.5],[65,25],color=lcolour)
        plt.plot([0,16.5],[65,65],color=lcolour)
        plt.plot([16.5,0],[25,25],color=lcolour)

        #Right Penalty Area
        plt.plot([130,113.5],[65,65],color=lcolour)
        plt.plot([113.5,113.5],[65,25],color=lcolour)
        plt.plot([113.5,130],[25,25],color=lcolour)

        #Left 6-yard Box
        plt.plot([0,5.5],[54,54],color=lcolour)
        plt.plot([5.5,5.5],[54,36],color=lcolour)
        plt.plot([5.5,0.5],[36,36],color=lcolour)

        #Right 6-yard Box
        plt.plot([130,124.5],[54,54],color=lcolour)
        plt.plot([124.5,124.5],[54,36],color=lcolour)
        plt.plot([124.5,130],[36,36],color=lcolour)

        #Prepare Circles
        centreCircle = plt.Circle((65,45),9.15,color=lcolour,fill=False)
        centreSpot = plt.Circle((65,45),0.8,color=lcolour)
        leftPenSpot = plt.Circle((11,45),0.8,color=lcolour)
        rightPenSpot = plt.Circle((119,45),0.8,color=lcolour)

        #Draw Circles
        ax.add_patch(centreCircle)
        ax.add_patch(centreSpot)
        ax.add_patch(leftPenSpot)
        ax.add_patch(rightPenSpot)

        #Prepare Arcs
        leftArc = Arc((11,45),height=18.3,width=18.3,angle=0,theta1=310,theta2=50,color=lcolour)
        rightArc = Arc((119,45),height=18.3,width=18.3,angle=0,theta1=130,theta2=230,color=lcolour)

        #Draw Arcs
        ax.add_patch(leftArc)
        ax.add_patch(rightArc)

        #Tidy Axes
        plt.axis('off')
예제 #18
0
def createPitchOld():
    #Taken from FC Python        
    #Create figure
    fig=plt.figure()
    ax=fig.add_subplot(1,1,1)
    linecolor="grey"
    #Pitch Outline & Centre Line
    plt.plot([0,0],[0,90], color=linecolor)
    plt.plot([0,130],[90,90], color=linecolor)
    plt.plot([130,130],[90,0], color=linecolor)
    plt.plot([130,0],[0,0], color=linecolor)
    plt.plot([65,65],[0,90], color=linecolor)
    
    #Left Penalty Area
    plt.plot([16.5,16.5],[65,25],color=linecolor)
    plt.plot([0,16.5],[65,65],color=linecolor)
    plt.plot([16.5,0],[25,25],color=linecolor)
    
    #Right Penalty Area
    plt.plot([130,113.5],[65,65],color=linecolor)
    plt.plot([113.5,113.5],[65,25],color=linecolor)
    plt.plot([113.5,130],[25,25],color=linecolor)
    
    #Left 6-yard Box
    plt.plot([0,5.5],[54,54],color=linecolor)
    plt.plot([5.5,5.5],[54,36],color=linecolor)
    plt.plot([5.5,0.5],[36,36],color=linecolor)
    
    #Right 6-yard Box
    plt.plot([130,124.5],[54,54],color=linecolor)
    plt.plot([124.5,124.5],[54,36],color=linecolor)
    plt.plot([124.5,130],[36,36],color=linecolor)
    
    #Prepare Circles
    centreCircle = plt.Circle((65,45),9.15,color=linecolor,fill=False)
    centreSpot = plt.Circle((65,45),0.8,color=linecolor)
    leftPenSpot = plt.Circle((11,45),0.8,color=linecolor)
    rightPenSpot = plt.Circle((119,45),0.8,color=linecolor)
    
    #Draw Circles
    ax.add_patch(centreCircle)
    ax.add_patch(centreSpot)
    ax.add_patch(leftPenSpot)
    ax.add_patch(rightPenSpot)
    
    #Prepare Arcs
    leftArc = Arc((11,45),height=18.3,width=18.3,angle=0,theta1=310,theta2=50,color=linecolor)
    rightArc = Arc((119,45),height=18.3,width=18.3,angle=0,theta1=130,theta2=230,color=linecolor)

    #Draw Arcs
    ax.add_patch(leftArc)
    ax.add_patch(rightArc)
    
    #Tidy Axes
    plt.axis('off')
    
    return fig,ax
예제 #19
0
    def plot_scale(self):
        axes = self.plotaxes
        axes.cla()
        axes.set_axis_off()
        from_, to_, interval = self.from_to()

        if self.settings.rose_check_settings["outer"]:
            if interval:
                circ = Wedge((0,0), 1.,
                    theta2=90-from_, theta1=90-to_,
                    ec=self.settings.rose_settings["outerc"],
                    lw=self.settings.rose_settings["outerwidth"],
                    fill=False,\
                    zorder=0)
            else:
                circ = Arc((0, 0),
                           2.,
                           2.,
                           theta2=360.,
                           theta1=0.,
                           ec=self.settings.rose_settings["outerc"],
                           lw=self.settings.rose_settings["outerwidth"],
                           zorder=0)
            axes.add_patch(circ)
        if self.settings.rose_check_settings["scaletxt"]:
            scaleaz = radians(self.settings.rose_settings["scaleaz"] % 360.)
            axes.text(1.05*sin(scaleaz), 1.05*cos(scaleaz),\
                "{}%".format(100./self.scale),\
                family='sans-serif',\
                size=self.settings.general_settings['fontsize'],\
                verticalalignment='center',\
                horizontalalignment='left' if scaleaz <= pi else 'right')
        if self.settings.rose_check_settings["rings"]:
            rings_interval = self.scale * self.settings.rose_settings[
                "ringsperc"] / 100.
            for i in np.arange(rings_interval, 1.0, rings_interval):
                ring = Arc((0,0), 2*i, 2*i, theta2=90.-from_, theta1=90.-to_,\
                    ec=self.settings.rose_settings["ringsc"],\
                    lw=self.settings.rose_settings["ringswidth"],\
                    zorder=0)
                axes.add_patch(ring)

        #http://stackoverflow.com/a/22659261/1457481
        if self.settings.rose_check_settings["diagonals"]:
            offset = self.settings.rose_settings["diagonalsoff"]
            for i in np.arange(0 + offset, 360 + offset,\
                    self.settings.rose_settings["diagonalsang"]):
                if not interval or in_interval(from_, to_, i):
                    diag = Line2D((0, sin(radians(i))), \
                        (0,cos(radians(i))),\
                        c=self.settings.rose_settings["diagonalsc"],\
                        lw=self.settings.rose_settings["diagonalswidth"],\
                        zorder=0)
                    axes.add_line(diag)
        self.plotaxes.set_xlim(-1.3, 1.3)
        self.plotaxes.set_ylim(-1.15, 1.15)
def plotfigure():
    #canvas=Canvas(page6,width=800,height=480,bg='white')
    #canvas.grid(row=0,column=0)

    f = Figure(figsize=(8,6), dpi=100)
    a = f.add_subplot(111,aspect=1)

    h=c1m.get()
    a.axis('off')
    a.plot([10,10],[10,h+10])
    a.text(-55,10+h/2,"C1m=\n%s"%round(c1m.get(),2))
    a.add_patch(Arc((10,10),80,80,angle=0,theta1=90-b1s.get(),theta2=90))
    a.text(30,10+h/3,"%s"%(round(b1s.get(),2))+u"\u00B0")
    a.plot([10,u1s.get()+10],[h+10,h+10])
    a.plot([10,u1s.get()+10],[10,h+10])
    a.text(u1s.get()/2-10,-30+h/2,'W1s= %s'%round(w1s.get(),2))

    a.plot([40+u1s.get(),40+u1s.get()],[10,h+10])
    a.plot([40+u1s.get(),u1rms.get()+40+u1s.get()],[h+10,h+10])
    a.plot([40+u1s.get(),u1rms.get()+40+u1s.get()],[10,h+10])
    a.text(u1rms.get()/2+30+u1s.get()-15,-30+h/2,'W1rms= %s'%round(w1rms.get(),2))
    a.add_patch(Arc((40+u1s.get(),10),80,80,angle=0,theta1=90-b1rms.get(),theta2=90))
    a.text(50+u1s.get(),10+h/3,"%s"%(round(b1rms.get(),2))+u"\u00B0")

    a.plot([u1s.get()+u1rms.get()+80,u1s.get()+u1rms.get()+80],[10,h+10])
    a.plot([u1s.get()+u1rms.get()+80,u1h.get()+u1s.get()+u1rms.get()+80],[h+10,h+10])
    a.plot([u1s.get()+u1rms.get()+80,u1h.get()+u1s.get()+u1rms.get()+80],[10,h+10])
    a.text(u1h.get()/2+u1s.get()+u1rms.get()+100,10+h/2,'W1h= %s'%round(w1h.get(),2))
    a.add_patch(Arc((u1s.get()+u1rms.get()+80,10),80,80,angle=0,theta1=90-b1h.get()
    ,theta2=90))
    a.text(u1s.get()+u1rms.get()+85,15+h/3,"%s"%(round(b1h.get(),2))+u"\u00B0",size='small')

    global canvas
    canvas = FigureCanvasTkAgg(f,page6)
    canvas.draw()
    canvas.get_tk_widget().grid(row=0,column=0)

    base=h+100
    h2=c2m.get()

    a.plot([10,u2.get()+10],[h2+base,h2+base])
    a.text(u2.get()/2+10,h2+base+10,'U2= %s'%round(u2.get(),2))
    a.plot([10,c2u.get()+10],[h2+base,h2+base])
    a.plot([10,c2u.get()+10],[h2+base,base])
    a.text(c2u.get()/2-30,base+h2/2-30,'C2=\n%s'%round(c2.get(),2))
    a.plot([c2u.get()+10,u2.get()+10],[base,h2+base])
    a.text(c2u.get()+10+(u2.get()-c2u.get())/2+10,base+h2/2-10,'W2= %s'%round(w2.get(),2))
    a.plot([c2u.get()+10,c2u.get()+10],[base,base+h2])
    a.text(c2u.get()-50,base+h2/2+10,'C2m=\n%s'%round(c2m.get(),2))
    a.add_patch(Arc((c2u.get()+10,base),50,50,angle=0,theta1=90,theta2=90+alpha2.get()))
    a.text(c2u.get()-50,base+h/4,"%s"%(round(alpha2.get(),2))+u"\u00B0")
    a.add_patch(Arc((c2u.get()+10,base),70,70,angle=0,theta2=90,theta1=90-beta2.get()))
    a.text(c2u.get()+20,base+h/4,"%s"%(round(beta2.get(),2))+u"\u00B0",size='small')

    a.text(550,base+h2+100,'*All units in m/s')
예제 #21
0
def on_click(event):
    global placing
    global onmove
    global cur_x
    global cur_y
    m_x, m_y = event.x, event.y
    x, y = ax.transData.inverted().transform([m_x, m_y])
    x_pts.append(x)
    y_pts.append(y)
    cur_x.append(x)
    cur_y.append(y)
    #pt_plot.set_xdata(x_pts)
    #pt_plot.set_ydata(y_pts)
    if placing:
        placing = False
        plt.disconnect(onmove)
        x, y, r = find_circle(cur_x[0], cur_y[0], cur_x[1], cur_y[1])
        theta1 = find_theta(x, y, cur_x[0], cur_y[0])
        theta2 = find_theta(x, y, cur_x[1], cur_y[1])
        ratio = find_arc_ratio(theta1, theta2)
        if cur_x[0] < 0 and cur_x[1] < 0:
            t1 = np.rad2deg(theta1)
            t2 = np.rad2deg(theta2)
            if t1 > 180 and t2 < 180:
                ratio = 0.1
        if ratio > 0:
            if ratio > 0.5:
                # the commented out lines are
                # used if you want to print out your arcs
                # so you can copy them into a text file for drawing

                # a = (x, y, r * 2, np.rad2deg(theta2), np.rad2deg(theta1))
                # arcs.append(a)
                arc = Arc((x, y), r * 2, r * 2, 0, np.rad2deg(theta2), np.rad2deg(theta1))
            else:
                # a = (x, y, r * 2, np.rad2deg(theta1), np.rad2deg(theta2))
                # arcs.append(a)
                arc = Arc((x, y), r * 2, r * 2, 0, np.rad2deg(theta1), np.rad2deg(theta2))
        else:
            if ratio < 0.5:
                # a = (x, y, r * 2, np.rad2deg(theta2), np.rad2deg(theta1))
                # arcs.append(a)
                arc = Arc((x, y), r * 2, r * 2, 0, np.rad2deg(theta2), np.rad2deg(theta1))
            else:
                # a = (x, y, r * 2, np.rad2deg(theta1), np.rad2deg(theta2))
                # arcs.append(a)
                arc = Arc((x, y), r * 2, r * 2, 0, np.rad2deg(theta1), np.rad2deg(theta2))
        ax.add_patch(arc)
        # print(arcs)
        cur_x = []
        cur_y = []
    else:
        onmove = plt.connect('motion_notify_event', on_move)
        placing = True
    canvas.draw()
예제 #22
0
def draw_court(ax=None, color='black', lw=2, outer_lines=False):
    # If an axes object isn't provided to plot onto, just get current one
    if ax is None:
        ax = plt.gca()

    outer_box = Rectangle((-470, -80),
                          190,
                          160,
                          linewidth=lw,
                          color=color,
                          fill=False)

    # Restricted Zone, it is an arc with 4ft radius from center of the hoop
    restricted = Arc((-417.5, 0),
                     80,
                     80,
                     theta1=270,
                     theta2=90,
                     linewidth=lw,
                     color=color)

    # Three point line
    # Create the side 3pt lines, they are 14ft long before they begin to arc
    corner_three_a = Rectangle((-470, 220), 140, 0, linewidth=lw, color=color)
    corner_three_b = Rectangle((-470, -220), 140, 0, linewidth=lw, color=color)
    # 3pt arc - center of arc will be the hoop, arc is 23'9" away from hoop
    # I just played around with the theta values until they lined up with the threes
    three_arc = Arc((-417.5, 0),
                    475,
                    475,
                    theta1=292,
                    theta2=68,
                    linewidth=lw,
                    color=color)

    # List of the court elements to be plotted onto the axes
    court_elements = [
        outer_box, restricted, corner_three_a, corner_three_b, three_arc
    ]

    if outer_lines:
        # Draw the half court line, baseline and side out bound lines
        outer_lines = Rectangle((-250, -47.5),
                                500,
                                470,
                                linewidth=lw,
                                color=color,
                                fill=False)
        court_elements.append(outer_lines)

    # Add the court elements onto the axes
    for element in court_elements:
        ax.add_patch(element)

    return ax
def draw_infinite(state1=0, state2=1, text=0.1):
    radius = 0.5
    x1 = state1 * delta + radius
    diff_state = abs(state2 - state1)
    x2 = delta * diff_state - 2 * radius
    y = 0
    ellipse = Arc([x1 + x2 / 2, y],
                  x2,
                  almost_zero,
                  angle=0,
                  theta1=0,
                  theta2=180.0,
                  color='k',
                  linewidth='1',
                  ls='dotted')
    arrow2 = FancyArrow(x1 + x2 / 2 - 0.01,
                        0,
                        0.01,
                        0,
                        width=arrow_width,
                        length_includes_head=False,
                        head_width=None,
                        head_length=None,
                        shape='full',
                        overhang=0,
                        head_starts_at_zero=False,
                        color='k')
    plt.gca().add_patch(ellipse)
    plt.gca().add_patch(arrow2)

    y = 0
    ellipse = Arc([1, y],
                  x2,
                  almost_zero,
                  angle=0,
                  theta1=0,
                  theta2=180.0,
                  color='k',
                  linewidth='1',
                  ls='dotted')
    plt.gca().add_patch(ellipse)
    arrow2 = FancyArrow(1 - 0.01,
                        0,
                        0.01,
                        0,
                        width=arrow_width,
                        length_includes_head=False,
                        head_width=None,
                        head_length=None,
                        shape='full',
                        overhang=0,
                        head_starts_at_zero=False,
                        color='k')
    plt.gca().add_patch(arrow2)
예제 #24
0
def addSemi(old, new):
    global ax
    global dire
    r = abs(old-new)
    if(dire > 0):
        ax.add_patch(Arc((old + (new-old)/2, 0), r, r,
                         theta1=0, theta2=180, edgecolor='k'))
        dire *= -1
    else:
        ax.add_patch(Arc((old + (new-old)/2, 0), r, r,
                         theta1=180, theta2=360, edgecolor='k'))
        dire *= -1
예제 #25
0
    def plot_contour(self, w=0.0):
        """
      Plot contour with poles of Green's function in the self-energy 
      SelfEnergy(w) = G(w+w')W(w')
      with respect to w' = Re(w')+Im(w')
      Poles of G(w+w') are located: w+w'-(E_n-Fermi)+i*eps sign(E_n-Fermi)==0 ==> 
      w'= (E_n-Fermi) - w -i eps sign(E_n-Fermi)
    """
        try:
            import matplotlib.pyplot as plt
            from matplotlib.patches import Arc, Arrow
        except:
            print('no matplotlib?')
            return

        fig, ax = plt.subplots()
        fe = self.fermi_energy
        ee = self.mo_energy
        iee = 0.5 - np.array(ee > fe)
        eew = ee - fe - w
        ax.plot(eew, iee, 'r.', ms=10.0)
        pp = list()
        pp.append(
            Arc((0, 0),
                4,
                4,
                angle=0,
                linewidth=2,
                theta1=0,
                theta2=90,
                zorder=2,
                color='b'))
        pp.append(
            Arc((0, 0),
                4,
                4,
                angle=0,
                linewidth=2,
                theta1=180,
                theta2=270,
                zorder=2,
                color='b'))
        pp.append(Arrow(0, 2, 0, -4, width=0.2, color='b', hatch='o'))
        pp.append(Arrow(-2, 0, 4, 0, width=0.2, color='b', hatch='o'))
        for p in pp:
            ax.add_patch(p)
        ax.set_aspect('equal')
        ax.grid(True, which='both')
        ax.axhline(y=0, color='k')
        ax.axvline(x=0, color='k')
        plt.ylim(-3.0, 3.0)
        plt.show()
예제 #26
0
def show_apx(points):
    from matplotlib import pyplot as plt
    from matplotlib.patches import Arc
    (x1, y1), r1 = apx_circle_org(points)
    (x2, y2), r2 = circle_apx(points)
    (x3, y3), r3 = circle_apx_nl(points)
    fig, ax = plt.subplots()
    ax.add_patch(Arc((x1, y1), 2 * r1, 2 * r1, color='g'))
    ax.add_patch(Arc((x2, y2), 2 * r2, 2 * r2, color='r'))
    ax.add_patch(Arc((x3, y3), 2 * r3, 2 * r3, color='b'))
    ax.scatter(*zip(*points))
    plt.axis('equal')
    plt.show()
예제 #27
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"}
예제 #28
0
def draw_pitch(ax):
    # size of the pitch is 120, 80
    #Create figure

    #Pitch Outline & Centre Line
    plt.plot([0,0],[0,80], color="grey")
    plt.plot([0,120],[80,80], color="grey")
    plt.plot([120,120],[80,0], color="grey")
    plt.plot([120,0],[0,0], color="grey")
    plt.plot([60,60],[0,80], color="grey")

    #Left Penalty Area
    plt.plot([14.6,14.6],[57.8,22.2],color="grey")
    plt.plot([0,14.6],[57.8,57.8],color="grey")
    plt.plot([0,14.6],[22.2,22.2],color="grey")

    #Right Penalty Area
    plt.plot([120,105.4],[57.8,57.8],color="grey")
    plt.plot([105.4,105.4],[57.8,22.5],color="grey")
    plt.plot([120, 105.4],[22.5,22.5],color="grey")

    #Left 6-yard Box
    plt.plot([0,4.9],[48,48],color="grey")
    plt.plot([4.9,4.9],[48,32],color="grey")
    plt.plot([0,4.9],[32,32],color="grey")

    #Right 6-yard Box
    plt.plot([120,115.1],[48,48],color="grey")
    plt.plot([115.1,115.1],[48,32],color="grey")
    plt.plot([120,115.1],[32,32],color="grey")

    #Prepare Circles
    centreCircle = plt.Circle((60,40),8.1,color="grey",fill=False)
    centreSpot = plt.Circle((60,40),0.71,color="grey")
    leftPenSpot = plt.Circle((9.7,40),0.71,color="grey")
    rightPenSpot = plt.Circle((110.3,40),0.71,color="grey")

    #Draw Circles
    ax.add_patch(centreCircle)
    ax.add_patch(centreSpot)
    ax.add_patch(leftPenSpot)
    ax.add_patch(rightPenSpot)
    
    leftArc = Arc((9.7,40),height=16.2,width=16.2,angle=0,theta1=310,theta2=50,color="grey")
    rightArc = Arc((110.3,40),height=16.2,width=16.2,angle=0,theta1=130,theta2=230,color="grey")

    #Draw Arcs
    ax.add_patch(leftArc)
    ax.add_patch(rightArc)
def draw_actions(agent, action_no):
    action_sample = agent.actions[action_no]
    x, xt, y, yt = action_sample.x * 100, action_sample.xt * 100, action_sample.y * 100, action_sample.yt * 100
    if xt - x == 0:
        if yt - y > 0:
            angle = 90
        else:
            angle = 270
    else:
        if xt - x > 0:
            angle = np.arctan((yt - y) / (xt - x)) * 360 / np.pi / 2
        else:
            angle = 180 + np.arctan((yt - y) / (xt - x)) * 360 / np.pi / 2
    distance = ((yt - y)**2 + ((xt - x))**2)**(1 / 2)

    plt.scatter(x, y, color=action_sample.color, zorder=8 + 4 * action_no)

    all_patches = []
    all_patches.append(
        Wedge((x, y),
              distance,
              angle - 0.5,
              angle + 0.5,
              fc='white',
              zorder=11 + 4 * action_no))
    all_patches.append(
        Arc((x, y),
            3,
            3 * horizontal_scalling,
            0,
            angle - 45,
            angle + 45,
            lw=7 * action_sample.success,
            ec='#611a6a',
            zorder=10 + 4 * action_no))
    all_patches.append(
        Arc((x, y),
            3,
            3 * horizontal_scalling,
            0,
            angle - 45,
            angle + 45,
            lw=7,
            ec='white',
            zorder=9 + 4 * action_no))

    for patch in all_patches:
        plt.gcf().gca().add_artist(patch)
예제 #30
0
def plot(X: np.ndarray, mixture: GaussianMixture, post: np.ndarray,
         title: str):
    """Plots the mixture model for 2D data"""
    _, K = post.shape

    percent = post / post.sum(axis=1).reshape(-1, 1)
    fig, ax = plt.subplots()
    ax.title.set_text(title)
    ax.set_xlim((-20, 20))
    ax.set_ylim((-20, 20))
    r = 0.25
    color = ["r", "b", "k", "y", "m", "c"]
    for i, point in enumerate(X):
        theta = 0
        for j in range(K):
            offset = percent[i, j] * 360
            arc = Arc(point,
                      r,
                      r,
                      0,
                      theta,
                      theta + offset,
                      edgecolor=color[j])
            ax.add_patch(arc)
            theta += offset
    for j in range(K):
        mu = mixture.mu[j]
        sigma = np.sqrt(mixture.var[j])
        circle = Circle(mu, sigma, color=color[j], fill=False)
        ax.add_patch(circle)
        legend = "mu = ({:0.2f}, {:0.2f})\n stdv = {:0.2f}".format(
            mu[0], mu[1], sigma)
        ax.text(mu[0], mu[1], legend)
    plt.axis('equal')
    plt.show()