Python matplotlib.patches.Wedge() Examples

The following are code examples for showing how to use matplotlib.patches.Wedge(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: Blackjack-Tracker   Author: martinabeleda   File: test_patches.py    MIT License 6 votes vote down vote up
def test_patch_str():
    """
    Check that patches have nice and working `str` representation.

    Note that the logic is that `__str__` is defined such that:
    str(eval(str(p))) == str(p)
    """
    p = mpatches.Circle(xy=(1, 2), radius=3)
    assert str(p) == 'Circle(xy=(1, 2), radius=3)'

    p = mpatches.Ellipse(xy=(1, 2), width=3, height=4, angle=5)
    assert str(p) == 'Ellipse(xy=(1, 2), width=3, height=4, angle=5)'

    p = mpatches.Rectangle(xy=(1, 2), width=3, height=4, angle=5)
    assert str(p) == 'Rectangle(xy=(1, 2), width=3, height=4, angle=5)'

    p = mpatches.Wedge(center=(1, 2), r=3, theta1=4, theta2=5, width=6)
    assert str(p) == 'Wedge(center=(1, 2), r=3, theta1=4, theta2=5, width=6)'

    p = mpatches.Arc(xy=(1, 2), width=3, height=4, angle=5, theta1=6, theta2=7)
    expected = 'Arc(xy=(1, 2), width=3, height=4, angle=5, theta1=6, theta2=7)'
    assert str(p) == expected 
Example 2
Project: FX-RER-Value-Extraction   Author: tsKenneth   File: polar.py    MIT License 5 votes vote down vote up
def _is_full_circle_deg(thetamin, thetamax):
    """
    Determine if a wedge (in degrees) spans the full circle.

    The condition is derived from :class:`~matplotlib.patches.Wedge`.
    """
    return abs(abs(thetamax - thetamin) - 360.0) < 1e-12 
Example 3
Project: FX-RER-Value-Extraction   Author: tsKenneth   File: polar.py    MIT License 5 votes vote down vote up
def _is_full_circle_rad(thetamin, thetamax):
    """
    Determine if a wedge (in radians) spans the full circle.

    The condition is derived from :class:`~matplotlib.patches.Wedge`.
    """
    return abs(abs(thetamax - thetamin) - 2 * np.pi) < 1.74e-14 
Example 4
Project: FX-RER-Value-Extraction   Author: tsKenneth   File: polar.py    MIT License 5 votes vote down vote up
def get_points(self):
        # docstring inherited
        if self._invalid:
            points = self._viewLim.get_points().copy()
            # Scale angular limits to work with Wedge.
            points[:, 0] *= 180 / np.pi
            if points[0, 0] > points[1, 0]:
                points[:, 0] = points[::-1, 0]

            # Scale radial limits based on origin radius.
            points[:, 1] -= self._originLim.y0

            # Scale radial limits to match axes limits.
            rscale = 0.5 / points[1, 1]
            points[:, 1] *= rscale
            width = min(points[1, 1] - points[0, 1], 0.5)

            # Generate bounding box for wedge.
            wedge = mpatches.Wedge(self._center, points[1, 1],
                                   points[0, 0], points[1, 0],
                                   width=width)
            self.update_from_path(wedge.get_path())

            # Ensure equal aspect ratio.
            w, h = self._points[1] - self._points[0]
            deltah = max(w - h, 0) / 2
            deltaw = max(h - w, 0) / 2
            self._points += np.array([[-deltaw, -deltah], [deltaw, deltah]])

            self._invalid = 0

        return self._points 
Example 5
Project: FX-RER-Value-Extraction   Author: tsKenneth   File: polar.py    MIT License 5 votes vote down vote up
def _gen_axes_patch(self):
        return mpatches.Wedge((0.5, 0.5), 0.5, 0.0, 360.0) 
Example 6
Project: ble5-nrf52-mac   Author: tomasero   File: polar.py    MIT License 5 votes vote down vote up
def _is_full_circle_deg(thetamin, thetamax):
    """
    Determine if a wedge (in degrees) spans the full circle.

    The condition is derived from :class:`~matplotlib.patches.Wedge`.
    """
    return abs(abs(thetamax - thetamin) - 360.0) < 1e-12 
Example 7
Project: ble5-nrf52-mac   Author: tomasero   File: polar.py    MIT License 5 votes vote down vote up
def _is_full_circle_rad(thetamin, thetamax):
    """
    Determine if a wedge (in radians) spans the full circle.

    The condition is derived from :class:`~matplotlib.patches.Wedge`.
    """
    return abs(abs(thetamax - thetamin) - 2 * np.pi) < 1.74e-14 
Example 8
Project: ble5-nrf52-mac   Author: tomasero   File: polar.py    MIT License 5 votes vote down vote up
def get_points(self):
        if self._invalid:
            points = self._viewLim.get_points().copy()

            # Scale angular limits to work with Wedge.
            points[:, 0] *= 180 / np.pi
            if points[0, 0] > points[1, 0]:
                points[:, 0] = points[::-1, 0]

            # Scale radial limits based on origin radius.
            points[:, 1] -= self._originLim.y0

            # Scale radial limits to match axes limits.
            rscale = 0.5 / points[1, 1]
            points[:, 1] *= rscale
            width = min(points[1, 1] - points[0, 1], 0.5)

            # Generate bounding box for wedge.
            wedge = mpatches.Wedge(self._center, points[1, 1],
                                   points[0, 0], points[1, 0],
                                   width=width)
            self.update_from_path(wedge.get_path())

            # Ensure equal aspect ratio.
            w, h = self._points[1] - self._points[0]
            if h < w:
                deltah = (w - h) / 2.0
                deltaw = 0.0
            elif w < h:
                deltah = 0.0
                deltaw = (h - w) / 2.0
            else:
                deltah = 0.0
                deltaw = 0.0
            self._points += np.array([[-deltaw, -deltah], [deltaw, deltah]])

            self._invalid = 0

        return self._points 
Example 9
Project: ble5-nrf52-mac   Author: tomasero   File: polar.py    MIT License 5 votes vote down vote up
def _gen_axes_patch(self):
        return mpatches.Wedge((0.5, 0.5), 0.5, 0.0, 360.0) 
Example 10
Project: neural-network-animation   Author: miloharper   File: test_patches.py    MIT License 5 votes vote down vote up
def test_wedge_movement():
    param_dict = {'center': ((0, 0), (1, 1), 'set_center'),
                  'r': (5, 8, 'set_radius'),
                  'width': (2, 3, 'set_width'),
                  'theta1': (0, 30, 'set_theta1'),
                  'theta2': (45, 50, 'set_theta2')}

    init_args = dict((k, v[0]) for (k, v) in six.iteritems(param_dict))

    w = mpatches.Wedge(**init_args)
    for attr, (old_v, new_v, func) in six.iteritems(param_dict):
        assert_equal(getattr(w, attr), old_v)
        getattr(w, func)(new_v)
        assert_equal(getattr(w, attr), new_v) 
Example 11
Project: neural-network-animation   Author: miloharper   File: test_patches.py    MIT License 5 votes vote down vote up
def test_wedge_range():
    ax = plt.axes()

    t1 = 2.313869244286224

    args = [[52.31386924, 232.31386924],
            [52.313869244286224, 232.31386924428622],
            [t1, t1 + 180.0],
            [0, 360],
            [90, 90 + 360],
            [-180, 180],
            [0, 380],
            [45, 46],
            [46, 45]]

    for i, (theta1, theta2) in enumerate(args):
        x = i % 3
        y = i // 3

        wedge = mpatches.Wedge((x * 3, y * 3), 1, theta1, theta2,
                               facecolor='none', edgecolor='k', lw=3)

        ax.add_artist(wedge)

    ax.set_xlim([-2, 8])
    ax.set_ylim([-2, 9]) 
Example 12
Project: GraphicDesignPatternByPython   Author: Relph1119   File: polar.py    MIT License 5 votes vote down vote up
def _is_full_circle_deg(thetamin, thetamax):
    """
    Determine if a wedge (in degrees) spans the full circle.

    The condition is derived from :class:`~matplotlib.patches.Wedge`.
    """
    return abs(abs(thetamax - thetamin) - 360.0) < 1e-12 
Example 13
Project: GraphicDesignPatternByPython   Author: Relph1119   File: polar.py    MIT License 5 votes vote down vote up
def _is_full_circle_rad(thetamin, thetamax):
    """
    Determine if a wedge (in radians) spans the full circle.

    The condition is derived from :class:`~matplotlib.patches.Wedge`.
    """
    return abs(abs(thetamax - thetamin) - 2 * np.pi) < 1.74e-14 
Example 14
Project: GraphicDesignPatternByPython   Author: Relph1119   File: polar.py    MIT License 5 votes vote down vote up
def get_points(self):
        if self._invalid:
            points = self._viewLim.get_points().copy()

            # Scale angular limits to work with Wedge.
            points[:, 0] *= 180 / np.pi
            if points[0, 0] > points[1, 0]:
                points[:, 0] = points[::-1, 0]

            # Scale radial limits based on origin radius.
            points[:, 1] -= self._originLim.y0

            # Scale radial limits to match axes limits.
            rscale = 0.5 / points[1, 1]
            points[:, 1] *= rscale
            width = min(points[1, 1] - points[0, 1], 0.5)

            # Generate bounding box for wedge.
            wedge = mpatches.Wedge(self._center, points[1, 1],
                                   points[0, 0], points[1, 0],
                                   width=width)
            self.update_from_path(wedge.get_path())

            # Ensure equal aspect ratio.
            w, h = self._points[1] - self._points[0]
            if h < w:
                deltah = (w - h) / 2.0
                deltaw = 0.0
            elif w < h:
                deltah = 0.0
                deltaw = (h - w) / 2.0
            else:
                deltah = 0.0
                deltaw = 0.0
            self._points += np.array([[-deltaw, -deltah], [deltaw, deltah]])

            self._invalid = 0

        return self._points 
Example 15
Project: GraphicDesignPatternByPython   Author: Relph1119   File: polar.py    MIT License 5 votes vote down vote up
def _gen_axes_patch(self):
        return mpatches.Wedge((0.5, 0.5), 0.5, 0.0, 360.0) 
Example 16
Project: ShallowDecoder   Author: erichson   File: utils.py    GNU General Public License v3.0 5 votes vote down vote up
def plot_flow_cyliner_2(img_epoch, m, n, epoch, Xmean):
    import cmocean

    x2 = np.arange(0, 384, 1)
    y2 = np.arange(0, 199, 1)
    mX, mY = np.meshgrid(x2, y2)

    
    img_epoch += Xmean.reshape(m,n)

    minmax = np.max(np.abs(img_epoch)) * 0.65
    plt.figure(facecolor="white",  edgecolor='k', figsize=(7.9,4.7))
    im = plt.imshow(img_epoch.T, cmap=cmocean.cm.balance, interpolation='none', vmin=-minmax, vmax=minmax)
    plt.contourf(mX, mY, img_epoch.T, 80, cmap=cmocean.cm.balance, alpha=1, vmin=-minmax, vmax=minmax)
    
    
    wedge = mpatches.Wedge((0,99), 33, 270, 90, ec="#636363", color='#636363',lw = 5)
    im.axes.add_patch(p=wedge)    
        
    #plt.title('Epoch number ' + str(epoch), fontsize = 16 )
    plt.axis('off')
    plt.title('Reconstructed flow filed using the shallow decoder')          
    plt.tight_layout()
    #plt.show()
    plt.savefig('results/reconstruction_via_shallow_decoder.png', dpi=300)          
    plt.close() 
Example 17
Project: ShallowDecoder   Author: erichson   File: utils.py    GNU General Public License v3.0 5 votes vote down vote up
def plot_flow_cyliner_pod(Xsmall, sensors, Xmean, sensor_locations, m, n):
    import cmocean

    x2 = np.arange(0, 384, 1)
    y2 = np.arange(0, 199, 1)
    mX, mY = np.meshgrid(x2, y2)
    
    tt, _, mt = Xsmall.shape
    Xsmall_temp = Xsmall.data.numpy().reshape(tt, mt)    
    u, s, v = np.linalg.svd(Xsmall_temp.T, 0)
       
    
    # Linear reconstruction using PCA - Train
    n_sensors = len(sensor_locations)
    linear_coef = (np.linalg.pinv(u[sensor_locations, 0:n_sensors])).dot(sensors.cpu().data.numpy().reshape(tt, n_sensors).T)    
    redata_linear = (u[:,0:n_sensors].dot(linear_coef)).T

    img_epoch = redata_linear[0,:].reshape(m,n)
    img_epoch += Xmean.reshape(m,n)
     
    minmax = np.max(np.abs(img_epoch)) * 0.65
    plt.figure(facecolor="white",  edgecolor='k', figsize=(7.9,4.7))
    im = plt.imshow(img_epoch.T, cmap=cmocean.cm.balance, interpolation='none', vmin=-minmax, vmax=minmax)
    plt.contourf(mX, mY, img_epoch.T, 80, cmap=cmocean.cm.balance, alpha=1, vmin=-minmax, vmax=minmax)
    
    
    wedge = mpatches.Wedge((0,99), 33, 270, 90, ec="#636363", color='#636363',lw = 5)
    im.axes.add_patch(p=wedge)    
        
    #plt.title('Epoch number ' + str(epoch), fontsize = 16 )
    plt.axis('off')
    plt.title('Reconstructed flow filed using POD')      
    plt.tight_layout()
    #plt.show()
    plt.savefig('results/reconstruction_via_pod.png', dpi=300)          
    plt.close() 
Example 18
Project: ShallowDecoder   Author: erichson   File: utils.py    GNU General Public License v3.0 5 votes vote down vote up
def plot_flow_cyliner_regularized_pod(Xsmall, sensors, Xmean, sensor_locations, m, n, alpha):
    import cmocean
    from sklearn import linear_model

    x2 = np.arange(0, 384, 1)
    y2 = np.arange(0, 199, 1)
    mX, mY = np.meshgrid(x2, y2)
    
    tt, _, mt = Xsmall.shape
    Xsmall_temp = Xsmall.data.numpy().reshape(tt, mt)    
    u, s, v = np.linalg.svd(Xsmall_temp.T, 0)
       
    
    # Linear reconstruction using PCA - Train
    n_sensors = len(sensor_locations)
    reg = linear_model.Ridge(alpha=alpha, fit_intercept=False, normalize=False)
    reg.fit(u[sensor_locations, 0:n_sensors], sensors.cpu().data.numpy().reshape(tt, n_sensors).T)
    redata_linear = (u[:,0:n_sensors].dot(reg.coef_.T)).T

    img_epoch = redata_linear[0,:].reshape(m,n)
    img_epoch += Xmean.reshape(m,n)
     

    minmax = np.max(np.abs(img_epoch)) * 0.65
    plt.figure(facecolor="white",  edgecolor='k', figsize=(7.9,4.7))
    im = plt.imshow(img_epoch.T, cmap=cmocean.cm.balance, interpolation='none', vmin=-minmax, vmax=minmax)
    plt.contourf(mX, mY, img_epoch.T, 80, cmap=cmocean.cm.balance, alpha=1, vmin=-minmax, vmax=minmax)
    wedge = mpatches.Wedge((0,99), 33, 270, 90, ec="#636363", color='#636363',lw = 5)
    im.axes.add_patch(p=wedge)    
        
    #plt.title('Epoch number ' + str(epoch), fontsize = 16 )
    plt.axis('off')
    plt.title('Reconstructed flow filed using POD Plus')          
    plt.tight_layout()
    #plt.show()
    plt.savefig('results/reconstruction_via_pod_plus.png', dpi=300)          
    plt.close() 
Example 19
Project: python3_ios   Author: holzschu   File: polar.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _is_full_circle_deg(thetamin, thetamax):
    """
    Determine if a wedge (in degrees) spans the full circle.

    The condition is derived from :class:`~matplotlib.patches.Wedge`.
    """
    return abs(abs(thetamax - thetamin) - 360.0) < 1e-12 
Example 20
Project: python3_ios   Author: holzschu   File: polar.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _is_full_circle_rad(thetamin, thetamax):
    """
    Determine if a wedge (in radians) spans the full circle.

    The condition is derived from :class:`~matplotlib.patches.Wedge`.
    """
    return abs(abs(thetamax - thetamin) - 2 * np.pi) < 1.74e-14 
Example 21
Project: python3_ios   Author: holzschu   File: polar.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def get_points(self):
        if self._invalid:
            points = self._viewLim.get_points().copy()

            # Scale angular limits to work with Wedge.
            points[:, 0] *= 180 / np.pi
            if points[0, 0] > points[1, 0]:
                points[:, 0] = points[::-1, 0]

            # Scale radial limits based on origin radius.
            points[:, 1] -= self._originLim.y0

            # Scale radial limits to match axes limits.
            rscale = 0.5 / points[1, 1]
            points[:, 1] *= rscale
            width = min(points[1, 1] - points[0, 1], 0.5)

            # Generate bounding box for wedge.
            wedge = mpatches.Wedge(self._center, points[1, 1],
                                   points[0, 0], points[1, 0],
                                   width=width)
            self.update_from_path(wedge.get_path())

            # Ensure equal aspect ratio.
            w, h = self._points[1] - self._points[0]
            if h < w:
                deltah = (w - h) / 2.0
                deltaw = 0.0
            elif w < h:
                deltah = 0.0
                deltaw = (h - w) / 2.0
            else:
                deltah = 0.0
                deltaw = 0.0
            self._points += np.array([[-deltaw, -deltah], [deltaw, deltah]])

            self._invalid = 0

        return self._points 
Example 22
Project: python3_ios   Author: holzschu   File: polar.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _gen_axes_patch(self):
        return mpatches.Wedge((0.5, 0.5), 0.5, 0.0, 360.0) 
Example 23
Project: innstereo   Author: innstereo   File: polar_axes.py    GNU General Public License v2.0 5 votes vote down vote up
def _gen_axes_patch(self):
        return Wedge((0.5, 0.5), 0.5, 270, 360) 
Example 24
Project: innstereo   Author: innstereo   File: polar_axes.py    GNU General Public License v2.0 5 votes vote down vote up
def _gen_axes_spines(self):
        path = Wedge((0, 0), 1.0, 270, 360).get_path()
        spine = mspines.Spine(self, 'circle', path)
        spine.set_patch_circle((0.5, 0.5), 0.5)
        return {'wedge':spine} 
Example 25
Project: linear_neuron   Author: uglyboxer   File: test_patches.py    MIT License 5 votes vote down vote up
def test_wedge_movement():
    param_dict = {'center': ((0, 0), (1, 1), 'set_center'),
                  'r': (5, 8, 'set_radius'),
                  'width': (2, 3, 'set_width'),
                  'theta1': (0, 30, 'set_theta1'),
                  'theta2': (45, 50, 'set_theta2')}

    init_args = dict((k, v[0]) for (k, v) in six.iteritems(param_dict))

    w = mpatches.Wedge(**init_args)
    for attr, (old_v, new_v, func) in six.iteritems(param_dict):
        assert_equal(getattr(w, attr), old_v)
        getattr(w, func)(new_v)
        assert_equal(getattr(w, attr), new_v) 
Example 26
Project: linear_neuron   Author: uglyboxer   File: test_patches.py    MIT License 5 votes vote down vote up
def test_wedge_range():
    ax = plt.axes()

    t1 = 2.313869244286224

    args = [[52.31386924, 232.31386924],
            [52.313869244286224, 232.31386924428622],
            [t1, t1 + 180.0],
            [0, 360],
            [90, 90 + 360],
            [-180, 180],
            [0, 380],
            [45, 46],
            [46, 45]]

    for i, (theta1, theta2) in enumerate(args):
        x = i % 3
        y = i // 3

        wedge = mpatches.Wedge((x * 3, y * 3), 1, theta1, theta2,
                               facecolor='none', edgecolor='k', lw=3)

        ax.add_artist(wedge)

    ax.set_xlim([-2, 8])
    ax.set_ylim([-2, 9]) 
Example 27
Project: wgdi   Author: SunPengChuan   File: circos.py    BSD 2-Clause "Simplified" License 5 votes vote down vote up
def plot_labels(self, root, labels, loc_chr, radius, horizontalalignment="center", verticalalignment="center", fontsize=6,
                    color='black'):
        for k in loc_chr:
            loc = sum(loc_chr[k]) * 0.5
            x, y = radius * np.cos(loc), radius * np.sin(loc)
            self.Wedge(root, (x, y), self.label_radius, 0,
                       360, self.label_radius, 'white', 1)
            if 1 * np.pi < loc < 2 * np.pi:
                loc += np.pi
            plt.text(x, y, labels[k], horizontalalignment=horizontalalignment, verticalalignment=verticalalignment,
                     fontsize=fontsize, color=color, rotation=0) 
Example 28
Project: wgdi   Author: SunPengChuan   File: circos.py    BSD 2-Clause "Simplified" License 5 votes vote down vote up
def Wedge(self, ax, loc, radius, start, end, width, color, alpha):
        p = mpatches.Wedge(loc, radius, start, end, width=width,
                           edgecolor=None, facecolor=color, alpha=alpha)
        ax.add_patch(p) 
Example 29
Project: wgdi   Author: SunPengChuan   File: circos.py    BSD 2-Clause "Simplified" License 5 votes vote down vote up
def run(self):
        fig = plt.figure(figsize=(tuple(self.figsize)))
        root = plt.axes([0, 0, 1, 1])
        mpl.rcParams['agg.path.chunksize'] = 100000000
        lens = base.newlens(self.lens, self.position)
        radius, angle_gap = float(self.radius), float(self.angle_gap)
        angle = (2 * np.pi - (int(len(lens))) * angle_gap) / (int(lens.sum()))
        loc_chr = self.chr_loction(lens, angle_gap, angle)
        list_colors = [str(k).strip() for k in re.split(',|:', self.colors)]
        chr_color = dict(zip(list_colors[::2], list_colors[1::2]))
        for k in loc_chr:
            start, end = loc_chr[k]
            self.Wedge(root, (0.0, 0.0), radius+self.ring_width, start * 180 /
                       np.pi, end * 180 / np.pi, self.ring_width, chr_color[k], 0.9)
        gff = base.newgff(self.gff)
        if hasattr(self, 'ancestor'):
            ancestor = pd.read_csv(self.ancestor, sep='\t', header=None)
            al = pd.read_csv(self.ancestor_location, sep='\t', header=None)
            al.rename(columns={0: 'chr', 1: 'start',
                               2: 'end', 3: 'color'}, inplace=True)
            al['chr'] = al['chr'].astype(str)
            data = self.deal_ancestor(ancestor, gff, lens, loc_chr, angle, al)
            self.plot_colinearity(data, radius, lw=0.1, alpha=0.8)

        if hasattr(self,'alignment'):
            alignment = pd.read_csv(self.alignment, sep='\t', header=None)
            newalignment = self.deal_alignment(
                alignment, gff, lens, loc_chr, angle)
            for k, v in enumerate(newalignment.columns[1:-2]):
                r = radius + self.ring_width*(k+1)
                self.plot_circle(loc_chr, r, lw=0.5, alpha=0.5, color='grey')
                self.plot_bar(newalignment[[v, 'rad']], r + self.ring_width *
                            0.15, self.ring_width*0.7, 0.15, chr_color, 1)
        labels = self.chr_label + lens.index
        labels = dict(zip(lens.index, labels))
        self.plot_labels(root,labels, loc_chr, radius - self.ring_width*1.2, fontsize=self.label_size)
        root.set_xlim(-1, 1)
        root.set_ylim(-1.05, 0.95)
        root.set_axis_off()
        plt.savefig(self.savefig, dpi=500)
        sys.exit(0) 
Example 30
Project: wgdi   Author: SunPengChuan   File: circos.py    BSD 2-Clause "Simplified" License 5 votes vote down vote up
def plot_labels(self, root, labels, loc_chr, radius, horizontalalignment="center", verticalalignment="center", fontsize=6,
                    color='black'):
        for k in loc_chr:
            loc = sum(loc_chr[k]) * 0.5
            x, y = radius * np.cos(loc), radius * np.sin(loc)
            self.Wedge(root, (x, y), self.label_radius, 0,
                       360, self.label_radius, 'white', 1)
            if 1 * np.pi < loc < 2 * np.pi:
                loc += np.pi
            plt.text(x, y, labels[k], horizontalalignment=horizontalalignment, verticalalignment=verticalalignment,
                     fontsize=fontsize, color=color, rotation=0) 
Example 31
Project: wgdi   Author: SunPengChuan   File: circos.py    BSD 2-Clause "Simplified" License 5 votes vote down vote up
def Wedge(self, ax, loc, radius, start, end, width, color, alpha):
        p = mpatches.Wedge(loc, radius, start, end, width=width,
                           edgecolor=None, facecolor=color, alpha=alpha)
        ax.add_patch(p) 
Example 32
Project: psychrometric-chart-makeover   Author: buds-lab   File: polar.py    MIT License 5 votes vote down vote up
def _is_full_circle_deg(thetamin, thetamax):
    """
    Determine if a wedge (in degrees) spans the full circle.

    The condition is derived from :class:`~matplotlib.patches.Wedge`.
    """
    return abs(abs(thetamax - thetamin) - 360.0) < 1e-12 
Example 33
Project: psychrometric-chart-makeover   Author: buds-lab   File: polar.py    MIT License 5 votes vote down vote up
def _is_full_circle_rad(thetamin, thetamax):
    """
    Determine if a wedge (in radians) spans the full circle.

    The condition is derived from :class:`~matplotlib.patches.Wedge`.
    """
    return abs(abs(thetamax - thetamin) - 2 * np.pi) < 1.74e-14 
Example 34
Project: psychrometric-chart-makeover   Author: buds-lab   File: polar.py    MIT License 5 votes vote down vote up
def get_points(self):
        # docstring inherited
        if self._invalid:
            points = self._viewLim.get_points().copy()
            # Scale angular limits to work with Wedge.
            points[:, 0] *= 180 / np.pi
            if points[0, 0] > points[1, 0]:
                points[:, 0] = points[::-1, 0]

            # Scale radial limits based on origin radius.
            points[:, 1] -= self._originLim.y0

            # Scale radial limits to match axes limits.
            rscale = 0.5 / points[1, 1]
            points[:, 1] *= rscale
            width = min(points[1, 1] - points[0, 1], 0.5)

            # Generate bounding box for wedge.
            wedge = mpatches.Wedge(self._center, points[1, 1],
                                   points[0, 0], points[1, 0],
                                   width=width)
            self.update_from_path(wedge.get_path())

            # Ensure equal aspect ratio.
            w, h = self._points[1] - self._points[0]
            deltah = max(w - h, 0) / 2
            deltaw = max(h - w, 0) / 2
            self._points += np.array([[-deltaw, -deltah], [deltaw, deltah]])

            self._invalid = 0

        return self._points 
Example 35
Project: psychrometric-chart-makeover   Author: buds-lab   File: polar.py    MIT License 5 votes vote down vote up
def _gen_axes_patch(self):
        return mpatches.Wedge((0.5, 0.5), 0.5, 0.0, 360.0) 
Example 36
Project: SignLanguage_ML   Author: mareep-raljodid   File: polar.py    MIT License 5 votes vote down vote up
def _is_full_circle_deg(thetamin, thetamax):
    """
    Determine if a wedge (in degrees) spans the full circle.

    The condition is derived from :class:`~matplotlib.patches.Wedge`.
    """
    return abs(abs(thetamax - thetamin) - 360.0) < 1e-12 
Example 37
Project: SignLanguage_ML   Author: mareep-raljodid   File: polar.py    MIT License 5 votes vote down vote up
def _is_full_circle_rad(thetamin, thetamax):
    """
    Determine if a wedge (in radians) spans the full circle.

    The condition is derived from :class:`~matplotlib.patches.Wedge`.
    """
    return abs(abs(thetamax - thetamin) - 2 * np.pi) < 1.74e-14 
Example 38
Project: SignLanguage_ML   Author: mareep-raljodid   File: polar.py    MIT License 5 votes vote down vote up
def get_points(self):
        # docstring inherited
        if self._invalid:
            points = self._viewLim.get_points().copy()
            # Scale angular limits to work with Wedge.
            points[:, 0] *= 180 / np.pi
            if points[0, 0] > points[1, 0]:
                points[:, 0] = points[::-1, 0]

            # Scale radial limits based on origin radius.
            points[:, 1] -= self._originLim.y0

            # Scale radial limits to match axes limits.
            rscale = 0.5 / points[1, 1]
            points[:, 1] *= rscale
            width = min(points[1, 1] - points[0, 1], 0.5)

            # Generate bounding box for wedge.
            wedge = mpatches.Wedge(self._center, points[1, 1],
                                   points[0, 0], points[1, 0],
                                   width=width)
            self.update_from_path(wedge.get_path())

            # Ensure equal aspect ratio.
            w, h = self._points[1] - self._points[0]
            deltah = max(w - h, 0) / 2
            deltaw = max(h - w, 0) / 2
            self._points += np.array([[-deltaw, -deltah], [deltaw, deltah]])

            self._invalid = 0

        return self._points 
Example 39
Project: SignLanguage_ML   Author: mareep-raljodid   File: polar.py    MIT License 5 votes vote down vote up
def _gen_axes_patch(self):
        return mpatches.Wedge((0.5, 0.5), 0.5, 0.0, 360.0) 
Example 40
Project: ImageFusion   Author: pfchai   File: test_patches.py    MIT License 5 votes vote down vote up
def test_wedge_movement():
    param_dict = {'center': ((0, 0), (1, 1), 'set_center'),
                  'r': (5, 8, 'set_radius'),
                  'width': (2, 3, 'set_width'),
                  'theta1': (0, 30, 'set_theta1'),
                  'theta2': (45, 50, 'set_theta2')}

    init_args = dict((k, v[0]) for (k, v) in six.iteritems(param_dict))

    w = mpatches.Wedge(**init_args)
    for attr, (old_v, new_v, func) in six.iteritems(param_dict):
        assert_equal(getattr(w, attr), old_v)
        getattr(w, func)(new_v)
        assert_equal(getattr(w, attr), new_v) 
Example 41
Project: ImageFusion   Author: pfchai   File: test_patches.py    MIT License 5 votes vote down vote up
def test_wedge_range():
    ax = plt.axes()

    t1 = 2.313869244286224

    args = [[52.31386924, 232.31386924],
            [52.313869244286224, 232.31386924428622],
            [t1, t1 + 180.0],
            [0, 360],
            [90, 90 + 360],
            [-180, 180],
            [0, 380],
            [45, 46],
            [46, 45]]

    for i, (theta1, theta2) in enumerate(args):
        x = i % 3
        y = i // 3

        wedge = mpatches.Wedge((x * 3, y * 3), 1, theta1, theta2,
                               facecolor='none', edgecolor='k', lw=3)

        ax.add_artist(wedge)

    ax.set_xlim([-2, 8])
    ax.set_ylim([-2, 9]) 
Example 42
Project: Blackjack-Tracker   Author: martinabeleda   File: polar.py    MIT License 5 votes vote down vote up
def _is_full_circle_deg(thetamin, thetamax):
    """
    Determine if a wedge (in degrees) spans the full circle.

    The condition is derived from :class:`~matplotlib.patches.Wedge`.
    """
    return abs(abs(thetamax - thetamin) - 360.0) < 1e-12 
Example 43
Project: Blackjack-Tracker   Author: martinabeleda   File: polar.py    MIT License 5 votes vote down vote up
def _is_full_circle_rad(thetamin, thetamax):
    """
    Determine if a wedge (in radians) spans the full circle.

    The condition is derived from :class:`~matplotlib.patches.Wedge`.
    """
    return abs(abs(thetamax - thetamin) - 2 * np.pi) < 1.74e-14 
Example 44
Project: Blackjack-Tracker   Author: martinabeleda   File: polar.py    MIT License 5 votes vote down vote up
def get_points(self):
        if self._invalid:
            points = self._viewLim.get_points().copy()

            # Scale angular limits to work with Wedge.
            points[:, 0] *= 180 / np.pi
            if points[0, 0] > points[1, 0]:
                points[:, 0] = points[::-1, 0]

            # Scale radial limits based on origin radius.
            points[:, 1] -= self._originLim.y0

            # Scale radial limits to match axes limits.
            rscale = 0.5 / points[1, 1]
            points[:, 1] *= rscale
            width = min(points[1, 1] - points[0, 1], 0.5)

            # Generate bounding box for wedge.
            wedge = mpatches.Wedge(self._center, points[1, 1],
                                   points[0, 0], points[1, 0],
                                   width=width)
            self.update_from_path(wedge.get_path())

            # Ensure equal aspect ratio.
            w, h = self._points[1] - self._points[0]
            if h < w:
                deltah = (w - h) / 2.0
                deltaw = 0.0
            elif w < h:
                deltah = 0.0
                deltaw = (h - w) / 2.0
            else:
                deltah = 0.0
                deltaw = 0.0
            self._points += np.array([[-deltaw, -deltah], [deltaw, deltah]])

            self._invalid = 0

        return self._points 
Example 45
Project: Blackjack-Tracker   Author: martinabeleda   File: polar.py    MIT License 5 votes vote down vote up
def _gen_axes_patch(self):
        return mpatches.Wedge((0.5, 0.5), 0.5, 0.0, 360.0) 
Example 46
Project: Blackjack-Tracker   Author: martinabeleda   File: test_patches.py    MIT License 5 votes vote down vote up
def test_wedge_range():
    ax = plt.axes()

    t1 = 2.313869244286224

    args = [[52.31386924, 232.31386924],
            [52.313869244286224, 232.31386924428622],
            [t1, t1 + 180.0],
            [0, 360],
            [90, 90 + 360],
            [-180, 180],
            [0, 380],
            [45, 46],
            [46, 45]]

    for i, (theta1, theta2) in enumerate(args):
        x = i % 3
        y = i // 3

        wedge = mpatches.Wedge((x * 3, y * 3), 1, theta1, theta2,
                               facecolor='none', edgecolor='k', lw=3)

        ax.add_artist(wedge)

    ax.set_xlim([-2, 8])
    ax.set_ylim([-2, 9]) 
Example 47
Project: Blackjack-Tracker   Author: martinabeleda   File: test_transforms.py    MIT License 5 votes vote down vote up
def test_transformed_patch_path():
    trans = mtransforms.Affine2D()
    patch = mpatches.Wedge((0, 0), 1, 45, 135, transform=trans)

    tpatch = mtransforms.TransformedPatchPath(patch)
    points = tpatch.get_fully_transformed_path().vertices

    # Changing the transform should change the result.
    trans.scale(2)
    assert_allclose(tpatch.get_fully_transformed_path().vertices, points * 2)

    # Changing the path should change the result (and cancel out the scaling
    # from the transform).
    patch.set_radius(0.5)
    assert_allclose(tpatch.get_fully_transformed_path().vertices, points) 
Example 48
Project: lambda-tensorflow-object-detection   Author: mikylucky   File: polar.py    GNU General Public License v3.0 5 votes vote down vote up
def _is_full_circle_deg(thetamin, thetamax):
    """
    Determine if a wedge (in degrees) spans the full circle.

    The condition is derived from :class:`~matplotlib.patches.Wedge`.
    """
    return abs(abs(thetamax - thetamin) - 360.0) < 1e-12 
Example 49
Project: lambda-tensorflow-object-detection   Author: mikylucky   File: polar.py    GNU General Public License v3.0 5 votes vote down vote up
def _is_full_circle_rad(thetamin, thetamax):
    """
    Determine if a wedge (in radians) spans the full circle.

    The condition is derived from :class:`~matplotlib.patches.Wedge`.
    """
    return abs(abs(thetamax - thetamin) - 2 * np.pi) < 1.74e-14 
Example 50
Project: lambda-tensorflow-object-detection   Author: mikylucky   File: polar.py    GNU General Public License v3.0 5 votes vote down vote up
def get_points(self):
        # docstring inherited
        if self._invalid:
            points = self._viewLim.get_points().copy()
            # Scale angular limits to work with Wedge.
            points[:, 0] *= 180 / np.pi
            if points[0, 0] > points[1, 0]:
                points[:, 0] = points[::-1, 0]

            # Scale radial limits based on origin radius.
            points[:, 1] -= self._originLim.y0

            # Scale radial limits to match axes limits.
            rscale = 0.5 / points[1, 1]
            points[:, 1] *= rscale
            width = min(points[1, 1] - points[0, 1], 0.5)

            # Generate bounding box for wedge.
            wedge = mpatches.Wedge(self._center, points[1, 1],
                                   points[0, 0], points[1, 0],
                                   width=width)
            self.update_from_path(wedge.get_path())

            # Ensure equal aspect ratio.
            w, h = self._points[1] - self._points[0]
            deltah = max(w - h, 0) / 2
            deltaw = max(h - w, 0) / 2
            self._points += np.array([[-deltaw, -deltah], [deltaw, deltah]])

            self._invalid = 0

        return self._points 
Example 51
Project: lambda-tensorflow-object-detection   Author: mikylucky   File: polar.py    GNU General Public License v3.0 5 votes vote down vote up
def _gen_axes_patch(self):
        return mpatches.Wedge((0.5, 0.5), 0.5, 0.0, 360.0) 
Example 52
Project: FX-RER-Value-Extraction   Author: tsKenneth   File: polar.py    MIT License 4 votes vote down vote up
def draw(self, *args, **kwargs):
        thetamin, thetamax = np.rad2deg(self._realViewLim.intervalx)
        if thetamin > thetamax:
            thetamin, thetamax = thetamax, thetamin
        rmin, rmax = ((self._realViewLim.intervaly - self.get_rorigin()) *
                        self.get_rsign())
        if isinstance(self.patch, mpatches.Wedge):
            # Backwards-compatibility: Any subclassed Axes might override the
            # patch to not be the Wedge that PolarAxes uses.
            center = self.transWedge.transform_point((0.5, 0.5))
            self.patch.set_center(center)
            self.patch.set_theta1(thetamin)
            self.patch.set_theta2(thetamax)

            edge, _ = self.transWedge.transform_point((1, 0))
            radius = edge - center[0]
            width = min(radius * (rmax - rmin) / rmax, radius)
            self.patch.set_radius(radius)
            self.patch.set_width(width)

            inner_width = radius - width
            inner = self.spines.get('inner', None)
            if inner:
                inner.set_visible(inner_width != 0.0)

        visible = not _is_full_circle_deg(thetamin, thetamax)
        # For backwards compatibility, any subclassed Axes might override the
        # spines to not include start/end that PolarAxes uses.
        start = self.spines.get('start', None)
        end = self.spines.get('end', None)
        if start:
            start.set_visible(visible)
        if end:
            end.set_visible(visible)
        if visible:
            yaxis_text_transform = self._yaxis_transform
        else:
            yaxis_text_transform = self._r_label_position + self.transData
        if self._yaxis_text_transform != yaxis_text_transform:
            self._yaxis_text_transform.set(yaxis_text_transform)
            self.yaxis.reset_ticks()
            self.yaxis.set_clip_path(self.patch)

        Axes.draw(self, *args, **kwargs) 
Example 53
Project: ble5-nrf52-mac   Author: tomasero   File: polar.py    MIT License 4 votes vote down vote up
def draw(self, *args, **kwargs):
        thetamin, thetamax = np.rad2deg(self._realViewLim.intervalx)
        if thetamin > thetamax:
            thetamin, thetamax = thetamax, thetamin
        rmin, rmax = self._realViewLim.intervaly - self.get_rorigin()

        if isinstance(self.patch, mpatches.Wedge):
            # Backwards-compatibility: Any subclassed Axes might override the
            # patch to not be the Wedge that PolarAxes uses.
            center = self.transWedge.transform_point((0.5, 0.5))
            self.patch.set_center(center)
            self.patch.set_theta1(thetamin)
            self.patch.set_theta2(thetamax)

            edge, _ = self.transWedge.transform_point((1, 0))
            radius = edge - center[0]
            width = min(radius * (rmax - rmin) / rmax, radius)
            self.patch.set_radius(radius)
            self.patch.set_width(width)

            inner_width = radius - width
            inner = self.spines.get('inner', None)
            if inner:
                inner.set_visible(inner_width != 0.0)

        visible = not _is_full_circle_deg(thetamin, thetamax)
        # For backwards compatibility, any subclassed Axes might override the
        # spines to not include start/end that PolarAxes uses.
        start = self.spines.get('start', None)
        end = self.spines.get('end', None)
        if start:
            start.set_visible(visible)
        if end:
            end.set_visible(visible)
        if visible:
            yaxis_text_transform = self._yaxis_transform
        else:
            yaxis_text_transform = self._r_label_position + self.transData
        if self._yaxis_text_transform != yaxis_text_transform:
            self._yaxis_text_transform.set(yaxis_text_transform)
            self.yaxis.reset_ticks()
            self.yaxis.set_clip_path(self.patch)

        Axes.draw(self, *args, **kwargs) 
Example 54
Project: lightct   Author: casimp   File: tomo_scan.py    MIT License 4 votes vote down vote up
def image_acquisition(num_proj, camera_port=0, wait=0,
                      hsv='v', fancy_out=True):
    hsv_dict = {'h': 0, 's': 1, 'v': 2}
    camera = cv2.VideoCapture(camera_port)
    camera.set(3, 2000)
    camera.set(4, 2000)
    try:
        dims = camera.read()[1][:, :, 2].shape + (num_proj, )
    except TypeError:
        error = ('Camera returning None. Check camera settings (port) and'
                 ' ensure camera is not being run by other software.')
        raise TypeError(error)
    im_stack = np.zeros(dims)

    if fancy_out:
        fig, ax = plt.subplots(figsize=(4, 4))
        fig.canvas.set_window_title('Acquisition')
        patch = Wedge((.5, .5), .375, 90, 90, width=0.1)
        ax.add_patch(patch)
        ax.axis('equal')
        ax.set_xlim([0, 1])
        ax.set_ylim([0, 1])
        ax.axis('off')
        t = ax.text(0.5, 0.5, '0%%', fontsize=15, ha='center', va='center')

    # Acquires defined number of images (saves slice from hsv)
    for i in range(num_proj):
        _, im = camera.read()
        im_stack[:, :, i] = color.rgb2hsv(im)[:, :, hsv_dict[hsv]]
        if fancy_out:

            patch.set_theta1(90 - 360 * (i+1) /num_proj)
            progress = 100 * (i+1) / num_proj
            t.set_text('%02d%%' % progress)
            plt.pause(0.001)
        else:
            sys.stdout.write('\rProgress: [{0:20s}] {1:.0f}%'.format('#' *
                             int(20*(i + 1) / num_proj),
                             100*((i + 1)/num_proj)))
            sys.stdout.flush()
        time.sleep(wait)

    del camera
    if fancy_out:
        plt.close()
    return im_stack 
Example 55
Project: GraphicDesignPatternByPython   Author: Relph1119   File: polar.py    MIT License 4 votes vote down vote up
def draw(self, *args, **kwargs):
        thetamin, thetamax = np.rad2deg(self._realViewLim.intervalx)
        if thetamin > thetamax:
            thetamin, thetamax = thetamax, thetamin
        rmin, rmax = self._realViewLim.intervaly - self.get_rorigin()

        if isinstance(self.patch, mpatches.Wedge):
            # Backwards-compatibility: Any subclassed Axes might override the
            # patch to not be the Wedge that PolarAxes uses.
            center = self.transWedge.transform_point((0.5, 0.5))
            self.patch.set_center(center)
            self.patch.set_theta1(thetamin)
            self.patch.set_theta2(thetamax)

            edge, _ = self.transWedge.transform_point((1, 0))
            radius = edge - center[0]
            width = min(radius * (rmax - rmin) / rmax, radius)
            self.patch.set_radius(radius)
            self.patch.set_width(width)

            inner_width = radius - width
            inner = self.spines.get('inner', None)
            if inner:
                inner.set_visible(inner_width != 0.0)

        visible = not _is_full_circle_deg(thetamin, thetamax)
        # For backwards compatibility, any subclassed Axes might override the
        # spines to not include start/end that PolarAxes uses.
        start = self.spines.get('start', None)
        end = self.spines.get('end', None)
        if start:
            start.set_visible(visible)
        if end:
            end.set_visible(visible)
        if visible:
            yaxis_text_transform = self._yaxis_transform
        else:
            yaxis_text_transform = self._r_label_position + self.transData
        if self._yaxis_text_transform != yaxis_text_transform:
            self._yaxis_text_transform.set(yaxis_text_transform)
            self.yaxis.reset_ticks()
            self.yaxis.set_clip_path(self.patch)

        Axes.draw(self, *args, **kwargs) 
Example 56
Project: ShallowDecoder   Author: erichson   File: utils.py    GNU General Public License v3.0 4 votes vote down vote up
def plot_flow_cyliner(Xsmall, sensor_locations, m, n, Xmean):
    import cmocean

    x2 = np.arange(0, 384, 1)
    y2 = np.arange(0, 199, 1)
    mX, mY = np.meshgrid(x2, y2)

    img = Xsmall[0,:]  + Xmean
    img = img.reshape(384,199)

    minmax = np.max(np.abs(img)) * 0.65
    plt.figure(facecolor="white",  edgecolor='k', figsize=(7.9,4.7))
    plt.contourf(mX, mY, img.T, 80, cmap=cmocean.cm.balance, alpha=1, vmin=-minmax, vmax=minmax)
    plt.contour(mX, mY, img.T, 80, colors='black', alpha=0.5, vmin=-minmax, vmax=minmax)
    im = plt.imshow(img.T, cmap=cmocean.cm.balance, interpolation='none', vmin=-minmax, vmax=minmax)
    
    wedge = mpatches.Wedge((0,99), 33, 270, 90, ec="#636363", color='#636363',lw = 5, zorder=200)
    im.axes.add_patch(p=wedge)    
    
    plt.tight_layout()
    plt.axis('off')
    
    ygrid = range(n)
    xgrid = range(m)
    yv, xv = np.meshgrid(ygrid, xgrid)
    
    x_sensors = xv.reshape(1, m*n)[:, sensor_locations]
    y_sensors = yv.reshape(1, m*n)[:, sensor_locations]

    plt.scatter(x_sensors, y_sensors, marker='.', color='#ff7f00', s=500, zorder=5)
    plt.title('Truth with sensor locations')      
    #plt.show()
    plt.savefig('results/flow_truth_with_sensors.png', dpi=300)          
    plt.close()


    img = Xsmall[0,:]  + Xmean
    img = img.reshape(384,199)

    plt.figure(facecolor="white",  edgecolor='k', figsize=(7.9,4.7))
    plt.contourf(mX, mY, img.T, 80, cmap=cmocean.cm.balance, alpha=1, vmin=-minmax, vmax=minmax)
    plt.contour(mX, mY, img.T, 80, colors='black', alpha=0.5, vmin=-minmax, vmax=minmax)
    im = plt.imshow(img.T, cmap=cmocean.cm.balance, interpolation='none', vmin=-minmax, vmax=minmax)    
    wedge = mpatches.Wedge((0,99), 33, 270, 90, ec="#636363", color='#636363',lw = 5, zorder=200)
    im.axes.add_patch(p=wedge)    
        
    plt.title('Truth')      
    plt.tight_layout()
    plt.axis('off')
    #plt.show()
    plt.savefig('results/flow_truth.png', dpi=300)          
    plt.close() 
Example 57
Project: python3_ios   Author: holzschu   File: polar.py    BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def draw(self, *args, **kwargs):
        thetamin, thetamax = np.rad2deg(self._realViewLim.intervalx)
        if thetamin > thetamax:
            thetamin, thetamax = thetamax, thetamin
        rmin, rmax = self._realViewLim.intervaly - self.get_rorigin()

        if isinstance(self.patch, mpatches.Wedge):
            # Backwards-compatibility: Any subclassed Axes might override the
            # patch to not be the Wedge that PolarAxes uses.
            center = self.transWedge.transform_point((0.5, 0.5))
            self.patch.set_center(center)
            self.patch.set_theta1(thetamin)
            self.patch.set_theta2(thetamax)

            edge, _ = self.transWedge.transform_point((1, 0))
            radius = edge - center[0]
            width = min(radius * (rmax - rmin) / rmax, radius)
            self.patch.set_radius(radius)
            self.patch.set_width(width)

            inner_width = radius - width
            inner = self.spines.get('inner', None)
            if inner:
                inner.set_visible(inner_width != 0.0)

        visible = not _is_full_circle_deg(thetamin, thetamax)
        # For backwards compatibility, any subclassed Axes might override the
        # spines to not include start/end that PolarAxes uses.
        start = self.spines.get('start', None)
        end = self.spines.get('end', None)
        if start:
            start.set_visible(visible)
        if end:
            end.set_visible(visible)
        if visible:
            yaxis_text_transform = self._yaxis_transform
        else:
            yaxis_text_transform = self._r_label_position + self.transData
        if self._yaxis_text_transform != yaxis_text_transform:
            self._yaxis_text_transform.set(yaxis_text_transform)
            self.yaxis.reset_ticks()
            self.yaxis.set_clip_path(self.patch)

        Axes.draw(self, *args, **kwargs) 
Example 58
Project: calin   Author: sguiz   File: dnaplotlib.py    MIT License 4 votes vote down vote up
def sbol_rbs (ax, type, num, start, end, prev_end, scale, linewidth, opts):
    """ Built-in SBOL ribosome binding site renderer.
    """
    # Default options
    zorder_add = 0.0
    color = (0.7,0.7,0.7)
    start_pad = 2.0
    end_pad = 2.0
    x_extent = 10.0
    edgecolor = (0,0,0)
    # Reset defaults if provided
    if opts != None:
        if 'zorder_add' in list(opts.keys()):
            zorder_add = opts['zorder_add']
        if 'color' in list(opts.keys()):
            color = opts['color']
        if 'start_pad' in list(opts.keys()):
            start_pad = opts['start_pad']
        if 'end_pad' in list(opts.keys()):
            end_pad = opts['end_pad']
        if 'x_extent' in list(opts.keys()):
            x_extent = opts['x_extent']
        if 'linewidth' in list(opts.keys()):
            linewidth = opts['linewidth']
        if 'scale' in list(opts.keys()):
            scale = opts['scale']
        if 'edge_color' in list(opts.keys()):
            edgecolor = opts['edge_color']
    # Check direction add start padding
    dir_fac = 1.0
    final_end = end
    final_start = prev_end
    rbs_center = (0,0)
    if start > end:
        start = prev_end+end_pad+x_extent
        end = prev_end+end_pad
        final_end = start+start_pad
        rbs_center = (end+((start-end)/2.0),0)
        w1 = Wedge(rbs_center, x_extent/2.0, 180, 360, linewidth=linewidth, 
                   facecolor=color, edgecolor=edgecolor, zorder=8+zorder_add)
        ax.add_patch(w1)
    else:
        start = prev_end+start_pad
        end = start+x_extent
        final_end = end+end_pad
        rbs_center = (start+((end-start)/2.0),0)
        w1 = Wedge(rbs_center, x_extent/2.0, 0, 180, linewidth=linewidth, 
                   facecolor=color, edgecolor=edgecolor, zorder=8+zorder_add)
        ax.add_patch(w1)
    if opts != None and 'label' in list(opts.keys()):
        if final_start > final_end:
            write_label(ax, opts['label'], final_end+((final_start-final_end)/2.0), opts=opts)
        else:
            write_label(ax, opts['label'], final_start+((final_end-final_start)/2.0), opts=opts)
    if final_start > final_end:
        return prev_end, final_start
    else:
        return prev_end, final_end 
Example 59
Project: psychrometric-chart-makeover   Author: buds-lab   File: polar.py    MIT License 4 votes vote down vote up
def draw(self, *args, **kwargs):
        thetamin, thetamax = np.rad2deg(self._realViewLim.intervalx)
        if thetamin > thetamax:
            thetamin, thetamax = thetamax, thetamin
        rmin, rmax = ((self._realViewLim.intervaly - self.get_rorigin()) *
                        self.get_rsign())
        if isinstance(self.patch, mpatches.Wedge):
            # Backwards-compatibility: Any subclassed Axes might override the
            # patch to not be the Wedge that PolarAxes uses.
            center = self.transWedge.transform_point((0.5, 0.5))
            self.patch.set_center(center)
            self.patch.set_theta1(thetamin)
            self.patch.set_theta2(thetamax)

            edge, _ = self.transWedge.transform_point((1, 0))
            radius = edge - center[0]
            width = min(radius * (rmax - rmin) / rmax, radius)
            self.patch.set_radius(radius)
            self.patch.set_width(width)

            inner_width = radius - width
            inner = self.spines.get('inner', None)
            if inner:
                inner.set_visible(inner_width != 0.0)

        visible = not _is_full_circle_deg(thetamin, thetamax)
        # For backwards compatibility, any subclassed Axes might override the
        # spines to not include start/end that PolarAxes uses.
        start = self.spines.get('start', None)
        end = self.spines.get('end', None)
        if start:
            start.set_visible(visible)
        if end:
            end.set_visible(visible)
        if visible:
            yaxis_text_transform = self._yaxis_transform
        else:
            yaxis_text_transform = self._r_label_position + self.transData
        if self._yaxis_text_transform != yaxis_text_transform:
            self._yaxis_text_transform.set(yaxis_text_transform)
            self.yaxis.reset_ticks()
            self.yaxis.set_clip_path(self.patch)

        Axes.draw(self, *args, **kwargs) 
Example 60
Project: scalable-irl   Author: makokal   File: puddle_world.py    BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def _setup_visuals(self):
        """Setup visual elements
        """
        self.figure = plt.figure(figsize=(12, 9))
        self.ax = plt.axes([0, 0, 0.8, 1])
        self.figure.add_axes(self.ax)

        self.record_status = self.figure.text(0.825, 0.3, 'Recording [OFF]',
                                              fontsize=14, color='blue')
        self.figure.text(0.825, 0.2, '#Demos: ', fontsize=10)
        self.demo_count = self.figure.text(0.925, 0.2, '0', fontsize=10)
        # catch events
        self.figure.canvas.mpl_connect('key_press_event', self._key_press)
        self.figure.canvas.mpl_connect('button_press_event', self._btn_press)

        # Main rectangle showing the environment
        self.ax.add_artist(Rectangle((0, 0), width=1, height=1, color='c',
                           zorder=0, ec='k', lw=8, fill=False))

        # draw goal region
        points = [[1, 1], [1, 0.95], [0.95, 1]]
        goal_polygon = plt.Polygon(points, color='green')
        self.ax.add_patch(goal_polygon)

        # draw puddles
        x1 = self._world.puddles[0].start[0]
        y1 = self._world.puddles[0].start[1]-0.05
        width = self._world.puddles[0].length
        height = self._world.puddles[1].length
        pd1 = Rectangle((x1, y1), height=0.1, width=width,
                        color='brown', alpha=0.7, aa=True, lw=0)
        self.ax.add_artist(pd1)
        self.ax.add_artist(Wedge(self._world.puddles[0].start, 0.05, 90, 270,
                           fc='brown', alpha=0.7, aa=True, lw=0))
        self.ax.add_artist(Wedge(self._world.puddles[0].end, 0.05, 270, 90,
                           fc='brown', alpha=0.7, aa=True, lw=0))

        x2 = self._world.puddles[1].start[0]-0.05
        y2 = self._world.puddles[1].start[1]
        pd2 = Rectangle((x2, y2), width=0.1, height=height,
                        color='brown', alpha=0.7)
        self.ax.add_artist(pd2)
        self.ax.add_artist(Wedge(self._world.puddles[1].start, 0.05, 180, 360,
                           fc='brown', alpha=0.7, aa=True, lw=0))
        self.ax.add_artist(Wedge(self._world.puddles[1].end, 0.05, 0, 180,
                           fc='brown', alpha=0.7, aa=True, lw=0))

        # draw the agent at initial pose
        robot_start = (0.3, 0.65)
        robot_visual = Circle(robot_start, 0.01, fc='b', ec='k', zorder=3)
        self.ax.add_artist(robot_visual)
        self.robot = Agent(position=robot_start, orientation=(1, 1),
                           visual=robot_visual)
        self.ax.set_xlim([0, 1])
        self.ax.set_ylim([0, 1])
        self.ax.set_xticks([])
        self.ax.set_yticks([]) 
Example 61
Project: funzo   Author: makokal   File: puddleworld.py    MIT License 4 votes vote down vote up
def _setup_visuals(self, ax):
        """Setup visual elements
        """
        # Main rectangle showing the environment
        ax.add_artist(Rectangle((0, 0), width=1, height=1, color='c',
                                zorder=0, ec='k', lw=8, fill=False))

        # draw goal region
        points = [[1, 1], [1, 0.95], [0.95, 1]]
        goal_polygon = plt.Polygon(points, color='green')
        ax.add_patch(goal_polygon)

        # draw puddles
        x1 = self.puddles[0].start[0]
        y1 = self.puddles[0].start[1] - 0.05
        width = self.puddles[0].length
        height = self.puddles[1].length
        pd1 = Rectangle((x1, y1), height=0.1, width=width,
                        color='brown', alpha=0.7, aa=True, lw=0)
        ax.add_artist(pd1)
        ax.add_artist(Wedge(self.puddles[0].start, 0.05, 90, 270,
                            fc='brown', alpha=0.7, aa=True, lw=0))
        ax.add_artist(Wedge(self.puddles[0].end, 0.05, 270, 90,
                            fc='brown', alpha=0.7, aa=True, lw=0))

        x2 = self.puddles[1].start[0] - 0.05
        y2 = self.puddles[1].start[1]
        pd2 = Rectangle((x2, y2), width=0.1, height=height,
                        color='brown', alpha=0.7)
        ax.add_artist(pd2)
        ax.add_artist(Wedge(self.puddles[1].start, 0.05, 180, 360,
                            fc='brown', alpha=0.7, aa=True, lw=0))
        ax.add_artist(Wedge(self.puddles[1].end, 0.05, 0, 180,
                            fc='brown', alpha=0.7, aa=True, lw=0))

        # draw the agent at initial pose
        robot_start = self._start  # (0.3, 0.65)
        robot_visual = Circle(robot_start, 0.01, fc='b', ec='k', zorder=3)
        ax.add_artist(robot_visual)
        self.robot = Agent(position=robot_start, orientation=(1, 1),
                           visual=robot_visual)
        ax.set_xlim([0, 1])
        ax.set_ylim([0, 1])
        ax.set_xticks([])
        ax.set_yticks([])

        return ax 
Example 62
Project: SignLanguage_ML   Author: mareep-raljodid   File: polar.py    MIT License 4 votes vote down vote up
def draw(self, *args, **kwargs):
        thetamin, thetamax = np.rad2deg(self._realViewLim.intervalx)
        if thetamin > thetamax:
            thetamin, thetamax = thetamax, thetamin
        rmin, rmax = ((self._realViewLim.intervaly - self.get_rorigin()) *
                        self.get_rsign())
        if isinstance(self.patch, mpatches.Wedge):
            # Backwards-compatibility: Any subclassed Axes might override the
            # patch to not be the Wedge that PolarAxes uses.
            center = self.transWedge.transform_point((0.5, 0.5))
            self.patch.set_center(center)
            self.patch.set_theta1(thetamin)
            self.patch.set_theta2(thetamax)

            edge, _ = self.transWedge.transform_point((1, 0))
            radius = edge - center[0]
            width = min(radius * (rmax - rmin) / rmax, radius)
            self.patch.set_radius(radius)
            self.patch.set_width(width)

            inner_width = radius - width
            inner = self.spines.get('inner', None)
            if inner:
                inner.set_visible(inner_width != 0.0)

        visible = not _is_full_circle_deg(thetamin, thetamax)
        # For backwards compatibility, any subclassed Axes might override the
        # spines to not include start/end that PolarAxes uses.
        start = self.spines.get('start', None)
        end = self.spines.get('end', None)
        if start:
            start.set_visible(visible)
        if end:
            end.set_visible(visible)
        if visible:
            yaxis_text_transform = self._yaxis_transform
        else:
            yaxis_text_transform = self._r_label_position + self.transData
        if self._yaxis_text_transform != yaxis_text_transform:
            self._yaxis_text_transform.set(yaxis_text_transform)
            self.yaxis.reset_ticks()
            self.yaxis.set_clip_path(self.patch)

        Axes.draw(self, *args, **kwargs) 
Example 63
Project: Blackjack-Tracker   Author: martinabeleda   File: polar.py    MIT License 4 votes vote down vote up
def draw(self, *args, **kwargs):
        thetamin, thetamax = self._realViewLim.intervalx
        thetamin *= 180 / np.pi
        thetamax *= 180 / np.pi
        if thetamin > thetamax:
            thetamin, thetamax = thetamax, thetamin
        rmin, rmax = self._realViewLim.intervaly - self.get_rorigin()

        if isinstance(self.patch, mpatches.Wedge):
            # Backwards-compatibility: Any subclassed Axes might override the
            # patch to not be the Wedge that PolarAxes uses.
            center = self.transWedge.transform_point((0.5, 0.5))
            self.patch.set_center(center)
            self.patch.set_theta1(thetamin)
            self.patch.set_theta2(thetamax)

            edge, _ = self.transWedge.transform_point((1, 0))
            radius = edge - center[0]
            width = min(radius * (rmax - rmin) / rmax, radius)
            self.patch.set_radius(radius)
            self.patch.set_width(width)

            inner_width = radius - width
            inner = self.spines.get('inner', None)
            if inner:
                inner.set_visible(inner_width != 0.0)

        visible = not _is_full_circle_deg(thetamin, thetamax)
        # For backwards compatibility, any subclassed Axes might override the
        # spines to not include start/end that PolarAxes uses.
        start = self.spines.get('start', None)
        end = self.spines.get('end', None)
        if start:
            start.set_visible(visible)
        if end:
            end.set_visible(visible)
        if visible:
            yaxis_text_transform = self._yaxis_transform
        else:
            yaxis_text_transform = self._r_label_position + self.transData
        if self._yaxis_text_transform != yaxis_text_transform:
            self._yaxis_text_transform.set(yaxis_text_transform)
            self.yaxis.reset_ticks()
            self.yaxis.set_clip_path(self.patch)

        Axes.draw(self, *args, **kwargs) 
Example 64
Project: ecogtools   Author: choldgraf   File: viz.py    BSD 2-Clause "Simplified" License 4 votes vote down vote up
def plot_split_circles(centers, radius, n_wedges=2, angle=0, ax=None,
                       colors=None, scale_by_ax=True, **kwargs):
    """
    Plot a circle at the specified location that is split into sub-colors.

    Parameters
    ----------
    centers : array, shape (n_circles, 2)
        The x/y coordinate of the circle centers
    radius : float | int
        The radius of the circle. If scale_by_ax is True, must be b/w 0 and 1
    n_wedges : int
        The number of wedges in the circle
    angle : float
        The rotation angle in degrees
    ax : None | mpl axis
        The axis object to plot on. If None, a new axis is created.
    colors : list, length == n_wedges | None
        The colors for each wedge
    scale_by_ax : bool
        Whether to treat `radius` as raw data units, or as a fraction of the
        figure x-axis (in which case radius must be between 0 and 1)
    kwargs : dictionary
        To be passed to the mpl Wedge call.

    Returns
    -------
    wedges : list
        A lit of mpl Wedge objects correspond to each wedge in the circle
    """
    from matplotlib.patches import Wedge
    if ax is None:
        f, ax = plt.subplots()
    if colors is None:
        colors = plt.cm.rainbow(np.arange(n_wedges) / float(n_wedges))
    if scale_by_ax is True:
        radius = radius * (ax.get_xlim()[1] - ax.get_xlim()[0])
    radii = radius
    if isinstance(radii, (int, float)):
        radii = np.repeat(radii, centers.shape[0])

    arc = 360. / n_wedges

    # Do the plotting
    wedges = []
    for ixy, iradius in zip(centers, radii):
        for icolor in colors:
            wedges.append(Wedge(ixy, iradius, angle, angle + arc,
                                fc=icolor, **kwargs))
            angle = angle + arc
    for iwedge in wedges:
        ax.add_artist(iwedge)
    return wedges 
Example 65
Project: lambda-tensorflow-object-detection   Author: mikylucky   File: polar.py    GNU General Public License v3.0 4 votes vote down vote up
def draw(self, *args, **kwargs):
        thetamin, thetamax = np.rad2deg(self._realViewLim.intervalx)
        if thetamin > thetamax:
            thetamin, thetamax = thetamax, thetamin
        rmin, rmax = ((self._realViewLim.intervaly - self.get_rorigin()) *
                        self.get_rsign())
        if isinstance(self.patch, mpatches.Wedge):
            # Backwards-compatibility: Any subclassed Axes might override the
            # patch to not be the Wedge that PolarAxes uses.
            center = self.transWedge.transform_point((0.5, 0.5))
            self.patch.set_center(center)
            self.patch.set_theta1(thetamin)
            self.patch.set_theta2(thetamax)

            edge, _ = self.transWedge.transform_point((1, 0))
            radius = edge - center[0]
            width = min(radius * (rmax - rmin) / rmax, radius)
            self.patch.set_radius(radius)
            self.patch.set_width(width)

            inner_width = radius - width
            inner = self.spines.get('inner', None)
            if inner:
                inner.set_visible(inner_width != 0.0)

        visible = not _is_full_circle_deg(thetamin, thetamax)
        # For backwards compatibility, any subclassed Axes might override the
        # spines to not include start/end that PolarAxes uses.
        start = self.spines.get('start', None)
        end = self.spines.get('end', None)
        if start:
            start.set_visible(visible)
        if end:
            end.set_visible(visible)
        if visible:
            yaxis_text_transform = self._yaxis_transform
        else:
            yaxis_text_transform = self._r_label_position + self.transData
        if self._yaxis_text_transform != yaxis_text_transform:
            self._yaxis_text_transform.set(yaxis_text_transform)
            self.yaxis.reset_ticks()
            self.yaxis.set_clip_path(self.patch)

        Axes.draw(self, *args, **kwargs)