具有 rgba 值 Python 的 Matplotlib 色点:O
Matplotlib color point with rgba-value Python :O
我已经有了一些数据图,我使用 contourf
和 cm.jet
作为我的颜色图。 vmin
=-100 和 vmax
= 100
我在另一个问题中读到,我可以使用 cm.jet(x)
从我的颜色图中访问特定颜色,其中 x 在 [0,1] 中。
我想得到 47 的颜色,所以我想用
试试
fortyseven=pylab.cm.jet(0.735)
这将 return 我的 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-value 转换为 hex-value 会起作用吗?
编辑
我刚刚意识到它会 return 一个 rgba 值
好的,我做了一些研究,现在可以回答我自己的问题了。
实际上 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 值 并绘制我的观点。
您也可以只在 plot
命令中使用 color
关键字,它接受任何 matplotlib
颜色,包括 RGBA tuple
,即 [=15] =] returns.
ax.plot(x, y, color = fortyseven)
我已经有了一些数据图,我使用 contourf
和 cm.jet
作为我的颜色图。 vmin
=-100 和 vmax
= 100
我在另一个问题中读到,我可以使用 cm.jet(x)
从我的颜色图中访问特定颜色,其中 x 在 [0,1] 中。
我想得到 47 的颜色,所以我想用
试试 fortyseven=pylab.cm.jet(0.735)
这将 return 我的 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-value 转换为 hex-value 会起作用吗?
编辑
我刚刚意识到它会 return 一个 rgba 值
好的,我做了一些研究,现在可以回答我自己的问题了。
实际上 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 值 并绘制我的观点。
您也可以只在 plot
命令中使用 color
关键字,它接受任何 matplotlib
颜色,包括 RGBA tuple
,即 [=15] =] returns.
ax.plot(x, y, color = fortyseven)