Matplotlib使用数据绘制背景图像

时间:2019-10-10 03:45:15

标签: python matplotlib background

我正在尝试遵循以下答案:Plot over an image background in python

但是我得到了不同的结果。我有以下数据:

array([  69252,    2237,    2979,    9050,    3158,    3275,    9823,
         21773,   21815,   13283,   37754,   79909,  106263,  159867,
        129817,  324694,  575737,  840000, 1463443, 1190771, 2362873,
       2132900, 1968847, 1666792,  732689, 1171336,  915391,  715237,
        464146,  173408,  236336,  159617,  124630,   93628,   36623,
         76465,   68856,   51249,   67199,   19660,   57228,  105645,
         43557,   10155,   24026,    5947,   17969,    3832,    8442,
          1525,   13909,    5512,   14756,   41719,   15505,   13859,
         21336,   65170,   75611,   43176,  147969,  381229,  135377,
        204684,    6701,     568,   87188,     700,    1235,    4556,
         27384,     588,     350,    2922,      40,     281,     315,
         12740,     424,      48,     547,     281,      76,     339,
            60,     182,    1853,     219,     585,      92,     373,
         22375,     376,     460,    1602,    1084,    8110,    9487,
          5060,    1735])

它是图像的色调直方图。我想生成HSV颜色背景,并在背景顶部绘制直方图。 https://en.wikipedia.org/wiki/File:HSV-RGB-comparison.svg

但是当我尝试在上面绘制数据时

h_hist = np.load("h_hist.npy")    
s_hist = np.load("s_hist.npy")    
v_hist = np.load("v_hist.npy")    

x = h_hist[0,:]

x_h = np.linspace(0, 360, 100)
x_v = np.linspace(0, 255, 100)

h = np.linspace(0, 360, 100)
s = np.ones(100)
v = np.ones(100)

hsv = np.zeros((10, 100, 3))

for i in range(0, 10):
    hsv[i, :, 0] = h
    hsv[i, :, 1] = s
    hsv[i, :, 2] = v

hsv=hsv.astype(np.float32)
rgb=cv.cvtColor(hsv, cv.COLOR_HSV2RGB)

plotlim = [0, 360, 0, np.max(x)]
plt.imshow(rgb, interpolation='bicubic', extent=plotlim)
plt.plot(x_h, x)

enter image description here

0 个答案:

没有答案