2015-09-01 38 views
0

我已经有一些数据的图,我使用contourfcm.jet作为我的色图。 vmin = -100和vmax = 100使用rgba-value Python的Matplotlib色点:O

我读到另一个问题,我可以通过cm.jet(x)(其中x在[0,1]中)从我的色彩映射中访问特定颜色。

我想47的颜色,所以我想尝试它与

fortyseven=pylab.cm.jet(0.735) 

这将返回我的RGB值的47

然后我想绘制一个点这个具体的rgb值:

ax.plot(x, y, fortyseven) 

但是这不会奏效。我总是得到一个

ValueError: third arg must be a format string 

错误。

所以,我用

ax.plot(x, y, 'fortyseven') 

尝试过了,我得到一个

ValueError: Unrecognized character f in format string 

错误。

那么甚至有可能用rgb值给点着色?

还是我忽略了一些东西?

编辑

如果我转换RGB值十六进制值将它的工作?

编辑

我刚刚意识到,它会返回一个RGBA值

回答

1

你也可以只使用color关键字在你plot命令,接受任何matplotlib颜色,包括RGBA tuple,这是什么cm.jet(0.735)回报。

ax.plot(x, y, color = fortyseven) 
+0

这完全正是我想知道的。谢谢! – Peter

0

好吧,我做了一些研究,现在可以回答我自己的问题。

事实上,rgba中的alpha代表透明度,所以它不会影响颜色本身,只是它的透明度不够。

所以基本上,你可以将alpha值切掉,而不会改变颜色本身。

甚至还有一个Python函数to_rgb其中有这个。

描述:

to_rgb(arg) 

Returns an RGB tuple of three floats from 0-1. 

arg can be an RGB or RGBA sequence or a string in any of several forms: 

    a letter from the set ‘rgbcmykw’ 
    a hex color string, like ‘#00FFFF’ 
    a standard name, like ‘aqua’ 
    a string representation of a float, like ‘0.4’, indicating gray on a 0-1 scale 

if arg is RGBA, the A will simply be discarded. 

所以现在我可以用RGB值工作,我的绘制点。