简体   繁体   中英

How can I visualize a color mapping?

I have a function 在此输入图像描述 which takes a color in RGB format as input and outputs a color in RGB format. It is guaranteed to be differentiable, but nothing else. For simplicity, lets say it would just change the order of channels:

def f(r, g, b):
    return b, g, r

Now I would like to visualize this by plotting two color bars like this:

在此输入图像描述

However, I have two problems with this:

  1. I don't know how to implement this (so: what is a reasonable way to interact with a canvas? matplotlib?)
  2. I'm not too sure if this color bar is appropriate. Two color wheels which are inside of each other might be better? Two color triangles next to each other?

A different way of going about the colormaps than the rgb method is to use the matplotlib color maps, available here :

import matplotlib.pyplot as plt
from numpy import linspace

sample_data = [1,5,10,20,45,50] ## y-values

def clr_map(max_index):
    cmap = plt.get_cmap('plasma')
    ## limits of cmap are (0,1) 
    ## ==> use index within (0,1) for each color 
    clrs = [cmap(i) for i in linspace(0, 1, max_index)] 
    return clrs

def clr_plot(data_list):
    clrs = clr_map(len(data_list)) ## call function above
    clr_list = [clr for clr in clrs]
    x_loc = [val+1 for val in range(max(data_list))] ## x-values of barplot
    ## use range for efficiency with multiple overlays
    plt.bar(x_loc[0], data_list[0], label='bar 1', color=clr_list[0])
    plt.bar(x_loc[1], data_list[1], label='bar 2', color=clr_list[1])
    plt.bar(x_loc[2], data_list[2], label='bar 3', color=clr_list[2])
    plt.bar(x_loc[3], data_list[3], label='bar 4', color=clr_list[3])
    plt.bar(x_loc[4], data_list[4], label='bar 5', color=clr_list[4])
    plt.bar(x_loc[5], data_list[5], label='bar 6', color=clr_list[5])
    plt.legend(loc='best')
    plt.show()

clr_plot(sample_data)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM