10

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

enter image description here

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

from pylab import *
from numpy import outer

x = outer(arange(0, 1, 0.01), ones(100))

imshow(transpose(x), cmap=cm.hsv)
show()

this plots the hue channel but I don't know how to add a second channel.

pcu
  • 1,204
  • 11
  • 27
none
  • 11,793
  • 9
  • 51
  • 87

1 Answers1

23

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

HYRY
  • 94,853
  • 25
  • 187
  • 187
  • What's the idea behind the complex numbers `100j` and `300j`? – Yannic Mar 14 '21 at 09:30
  • 1
    Ah got it. From the numpy docs: "However, if the step length is a complex number (e.g. 5j), then the integer part of its magnitude is interpreted as specifying the number of points to create between the start and stop values, where the stop value is inclusive." – Yannic Mar 14 '21 at 09:32