2d hsv color space in matplotlib

后端 未结 1 921
后悔当初
后悔当初 2021-01-04 23:43

I\'m trying to reproduce this graph in matplotlib (taken from wikipedia)

basically a 2d hsv color space where saturation is set to 1.0. here\'s what I have

1条回答
  •  礼貌的吻别
    2021-01-05 00:47

    You need to create the HSV array and convert it to RGB, here is an example:

    import numpy as np
    import pylab as pl
    from matplotlib.colors import hsv_to_rgb
    
    V, H = np.mgrid[0:1:100j, 0:1:300j]
    S = np.ones_like(V)
    HSV = np.dstack((H,S,V))
    RGB = hsv_to_rgb(HSV)
    pl.imshow(RGB, origin="lower", extent=[0, 360, 0, 1], aspect=150)
    pl.xlabel("H")
    pl.ylabel("V")
    pl.title("$S_{HSV}=1$")
    pl.show()
    

    the output is:

    enter image description here

    0 讨论(0)
提交回复
热议问题