本文介绍了matplotlib中的2d HSV色彩空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在matplotlib(摘自维基百科)中重现此图

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

基本上是2d hsv色彩空间,其中饱和度设置为1.0.这是我到目前为止所做的

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.

推荐答案

您需要创建HSV数组并将其转换为RGB,这是一个示例:

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()

输出为:

这篇关于matplotlib中的2d HSV色彩空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 00:51