有什么方法可以在matplotlib中使用双变量颜色图吗? [英] Is there any way to use bivariate colormaps in matplotlib?
问题描述
换句话说,我想制作一个热图(或表面图),其中颜色根据 2 变量而变化. (具体来说,亮度=幅度,色调=相位.)是否有任何本地方法可以做到这一点? 相似情节的一些例子:
In other words, I want to make a heatmap (or surface plot) where the color varies as a function of 2 variables. (Specifically, luminance = magnitude and hue = phase.) Is there any native way to do this? Some examples of similar plots:
推荐答案
imshow
将采用NxMx3(rbg)或NxMx4(grba)数组,因此您可以手动"进行颜色映射.
imshow
will take an NxMx3 (rbg) or NxMx4 (grba) array so you can do your color mapping 'by hand'.
通过将Normalize
子类化以将矢量映射到定标器并巧妙地自定义颜色映射 ,您也许能够获得一点吸引力(但是我认为这将结束必须将您的尺寸之一加进仓).
You might be able to get a bit of traction by sub-classing Normalize
to map your vector to a scaler and laying out a custom color map very cleverly (but I think this will end up having to bin one of your dimensions).
我已经做过这样的事情( pdf链接,请参见第页24),但代码在MATLAB
中(并藏在我的档案中的某个位置).
I have done something like this (pdf link, see figure on page 24), but the code is in MATLAB
(and buried someplace in my archives).
我同意使用双变量颜色映射是有用的(主要用于表示非常密集的矢量场,无论您做什么,都可能使小溪流过).
我认为明显的扩展是让颜色映射采用复杂的参数.这将需要Normalize
和Colormap
的专门子类,如果我认为要实施很多工作,我会来回走下去.我怀疑如果您手动操作它,将只是api争吵的问题.
I agree a bi-variate color map would be useful (primarily for representing very dense vector fields where your kinda up the creek no matter what you do).
I think the obvious extension is to let color maps take complex arguments. It would require specialized sub-classes of Normalize
and Colormap
and I am going back and forth on if I think it would be a lot of work to implement. I suspect if you get it working by hand it will just be a matter of api wrangling.
这篇关于有什么方法可以在matplotlib中使用双变量颜色图吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!