Python matplotlib.colors 模块,hsv_to_rgb() 实例源码

我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用matplotlib.colors.hsv_to_rgb()

项目:pywonderland    作者:neozhaoliang    | 项目源码 | 文件源码
def main(imgsize):
    y, x = np.ogrid[6: -6: imgsize*2j, -6: 6: imgsize*2j]
    z = x + y*1j
    z = RiemannSphere(Klein(Mobius(Klein(z))))

    # define colors in hsv space
    H = np.sin(z[0]*np.pi)**2
    S = np.cos(z[1]*np.pi)**2
    V = abs(np.sin(z[2]*np.pi) * np.cos(z[2]*np.pi))**0.2
    HSV = np.dstack((H, S, V))

    # transform to rgb space
    img = hsv_to_rgb(HSV)
    fig = plt.figure(figsize=(imgsize/100.0, imgsize/100.0), dpi=100)
    ax = fig.add_axes([0, 0, 1, 1], aspect=1)
    ax.axis('off')
    ax.imshow(img)
    fig.savefig('kaleidoscope.png')
项目:PyPeVoc    作者:goiosunsw    | 项目源码 | 文件源码
def plot_candidates(self):
        """Plot a representation of candidate periodicity

        Size gives the periodicity strength, 
        color the order of preference
        """

        fig, ax = pl.subplots(2, sharex=True)

        hues = np.arange(self.ncand)/float(self.ncand)
        hsv = np.swapaxes(np.atleast_3d([[hues, np.ones(len(hues)),
                                          np.ones(len(hues))]]), 1, 2)
        cols = hsv_to_rgb(hsv).squeeze()

        for per in self.periods:
            nc = len(per.cand_period)

            ax[0].scatter(per.time*np.ones(nc), per.cand_period,
                          s=per.cand_strength*100,
                          c=cols[0:nc], alpha=.5)

        ax[0].plot(*zip(*[[per.time, float(per.get_preferred_period())]
                        for per in self.periods]), color='k')

        ax[1].plot(self.get_times(), self.get_strength())
项目:pyrealtime    作者:ewhitmire    | 项目源码 | 文件源码
def update_fig(self, data):
        self.series[0].set_data(0, data)
        hue = self.hue_transfer_function(data)
        color = hsv_to_rgb([hue, 1, 0.75])
        self.series[0].set_color(color)
        return self.series
项目:Neural-EM    作者:sjoerdvansteenkiste    | 项目源码 | 文件源码
def get_gamma_colors(nr_colors):
    hsv_colors = np.ones((nr_colors, 3))
    hsv_colors[:, 0] = (np.linspace(0, 1, nr_colors, endpoint=False) + 2/3) % 1.0
    color_conv = hsv_to_rgb(hsv_colors)
    return color_conv
项目:tweetopo    作者:zthxxx    | 项目源码 | 文件源码
def hue_map(self, value):
        '''
        :param value: number 0 to 1, map to hue 0.6 - 0 (blue to red, like heatmap)
                      more highter the value, more warm the color
        :return: hex of rgb
        '''
        HUE_MAX = 0.6
        hue = pow(1 - value, 2) * HUE_MAX
        rgb = colors.hsv_to_rgb((hue, 1, 1))
        hex = colors.to_hex(rgb)
        return hex
项目:flownet2-tf    作者:sampepose    | 项目源码 | 文件源码
def visualize_flow(flow, mode='Y'):
    """
    this function visualize the input flow
    :param flow: input flow in array
    :param mode: choose which color mode to visualize the flow (Y: Ccbcr, RGB: RGB color)
    :return: None
    """
    if mode == 'Y':
        # Ccbcr color wheel
        img = flow_to_image(flow)
        plt.imshow(img)
        plt.show()
    elif mode == 'RGB':
        (h, w) = flow.shape[0:2]
        du = flow[:, :, 0]
        dv = flow[:, :, 1]
        valid = flow[:, :, 2]
        max_flow = max(np.max(du), np.max(dv))
        img = np.zeros((h, w, 3), dtype=np.float64)
        # angle layer
        img[:, :, 0] = np.arctan2(dv, du) / (2 * np.pi)
        # magnitude layer, normalized to 1
        img[:, :, 1] = np.sqrt(du * du + dv * dv) * 8 / max_flow
        # phase layer
        img[:, :, 2] = 8 - img[:, :, 1]
        # clip to [0,1]
        small_idx = img[:, :, 0:3] < 0
        large_idx = img[:, :, 0:3] > 1
        img[small_idx] = 0
        img[large_idx] = 1
        # convert to rgb
        img = cl.hsv_to_rgb(img)
        # remove invalid point
        img[:, :, 0] = img[:, :, 0] * valid
        img[:, :, 1] = img[:, :, 1] * valid
        img[:, :, 2] = img[:, :, 2] * valid
        # show
        plt.imshow(img)
        plt.show()

    return None
项目:PyPeVoc    作者:goiosunsw    | 项目源码 | 文件源码
def plot_candidates(self):
        """Plot a representation of candidate periodicity

        Size gives the periodicity strength, color the order of preference
        """

        hues = np.arange(self.ncand)/float(self.ncand)
        hsv = np.swapaxes(np.atleast_3d([[hues,np.ones(len(hues)),np.ones(len(hues))]]),1,2)
        cols = hsv_to_rgb(hsv).squeeze()

        for per in self.periods:
            nc = len(per.cand_period)

            pl.scatter(per.time*np.ones(nc),per.cand_period,s=per.cand_strength*100,c=cols[0:nc],alpha=.5)
项目:flownetS_tensorflow    作者:studian    | 项目源码 | 文件源码
def visualize_flow(flow, mode='Y'):
    """
    this function visualize the input flow
    :param flow: input flow in array
    :param mode: choose which color mode to visualize the flow (Y: Ccbcr, RGB: RGB color)
    :return: None
    """
    if mode == 'Y':
        # Ccbcr color wheel
        img = flow_to_image(flow)
        plt.imshow(img)
        plt.show()
    elif mode == 'RGB':
        (h, w) = flow.shape[0:2]
        du = flow[:, :, 0]
        dv = flow[:, :, 1]
        valid = flow[:, :, 2]
        max_flow = max(np.max(du), np.max(dv))
        img = np.zeros((h, w, 3), dtype=np.float64)
        # angle layer
        img[:, :, 0] = np.arctan2(dv, du) / (2 * np.pi)
        # magnitude layer, normalized to 1
        img[:, :, 1] = np.sqrt(du * du + dv * dv) * 8 / max_flow
        # phase layer
        img[:, :, 2] = 8 - img[:, :, 1]
        # clip to [0,1]
        small_idx = img[:, :, 0:3] < 0
        large_idx = img[:, :, 0:3] > 1
        img[small_idx] = 0
        img[large_idx] = 1
        # convert to rgb
        img = cl.hsv_to_rgb(img)
        # remove invalid point
        img[:, :, 0] = img[:, :, 0] * valid
        img[:, :, 1] = img[:, :, 1] * valid
        img[:, :, 2] = img[:, :, 2] * valid
        # show
        plt.imshow(img)
        plt.show()

    return None
项目:cryptoverse-probe    作者:Cryptoverse    | 项目源码 | 文件源码
def render_jump_range(params=None):
    if not putil.has_any(params):
        raise CommandException('Specify an origin system to render the jump range from')
    origin_fragment = putil.single_str(params)
    destination_fragment = putil.retrieve_value(params, '-d', None)

    hashes = database.get_star_log_hashes()
    origin_hash = putil.natural_match(origin_fragment, hashes)
    if origin_hash is None:
        raise CommandException('Unable to find an origin system containing %s' % origin_fragment)
    destination_hash = None
    highest = None
    if destination_fragment is not None:
        destination_hash = putil.natural_match(destination_fragment, hashes)
        if destination_hash is None:
            raise CommandException('Unable to find a destination system containing %s' % destination_fragment)
        if not database.get_star_logs_share_chain([origin_hash, destination_hash]):
            raise CommandException('Systems %s and %s exist on different chains' % (util.get_system_name(origin_hash), util.get_system_name(destination_hash)))
        highest = database.get_star_log_highest(database.get_star_log_highest_from_list([origin_hash, destination_hash]))['hash']

    figure = pyplot.figure()
    axes = figure.add_subplot(111, projection='3d')
    hue_start = 0.327
    hue_end = 0.0
    hue_delta = hue_end - hue_start
    for current_system in database.get_star_log_hashes(highest):
        cost = util.get_jump_cost(origin_hash, current_system)
        cost_hue = hue_start + (cost * hue_delta)
        cost_value = 0.0 if cost == 1.0 else 1.0
        color = pycolors.hsv_to_rgb([cost_hue, 0.7, cost_value])
        current_position = util.get_cartesian(current_system)
        xs = [current_position[0], current_position[0]]
        ys = [current_position[1], current_position[1]]
        zs = [0, current_position[2]]
        axes.plot(xs, ys, zs, c=color)
        marker = '^' if current_system == origin_hash else 'o'
        axes.scatter(current_position[0], current_position[1], current_position[2], label=util.get_system_name(current_system), c=color, marker=marker)
    if destination_hash is not None:
        origin_position = util.get_cartesian(origin_hash)
        destination_position = util.get_cartesian(destination_hash)
        xs = [origin_position[0], destination_position[0]]
        ys = [origin_position[1], destination_position[1]]
        zs = [origin_position[2], destination_position[2]]
        axes.plot(xs, ys, zs, linestyle=':')

    axes.legend()
    axes.set_title('Jump Range %s' % util.get_system_name(origin_hash))
    axes.set_xlabel('X')
    axes.set_ylabel('Y')
    axes.set_zlabel('Z')

    pyplot.show()