我正在尝试将从Colors.jl中由distinctable_colors生成的RGB元组分配给朱莉娅lang中带有pyplot的特定行,例如:
using PyPlot, Colors
RGB_1 = distinguishable_colors(10)[5]
plot(linspace(1,10,10), color=RGB_1)
但是似乎rgb空间颜色不适合该图:
ValueError: to_rgba: Invalid rgba arg "<PyCall.jlwrap RGB{U8}(0.0,0.0,0.0)>"
to_rgb: Invalid rgb arg "<PyCall.jlwrap RGB{U8}(0.0,0.0,0.0)>"
cannot convert argument to rgb sequence
无论如何,是否要从Colors.jl生成的数组中获取元组(0.0,0.0,0.0),而不是RGB {U8}(0.0,0.0,0.0)?我注意到
plot(linspace(1,10,10), color=(0.0,0.0,0.0))
确实有效。 Julia 0.3.2和matplotlib 1.4.2。
最佳答案
您可以给color
函数的plot
选项提供3个UFixed8
的元组(这是FixedPointNumbers.UFixed{UInt8,8}
的别名)。 Colors.jl
具有以下功能red
,green
和blue
,以从RGB
类型(每种类型为UFixed8
)获取各个字段。
julia> VERSION
v"0.4.6"
julia> using PyPlot, Colors
julia> rgb₁ = distinguishable_colors(10)[5]
RGB{U8}(0.843,0.267,0.0)
julia> rgb_sequence(c::RGB) = (red(c), green(c), blue(c))
rgb (generic function with 1 method)
julia> rgb₁_tuple = rgb_sequence(rgb₁)
(UFixed8(0.843),UFixed8(0.267),UFixed8(0.0))
julia> eltype(rgb₁_tuple)
FixedPointNumbers.UFixed{UInt8,8}
julia> plot(linspace(1, 10, 10), color = rgb₁_tuple)
1-element Array{Any,1}:
PyObject <matplotlib.lines.Line2D object at 0x000000002864E240>
出:
在
v"0.3.12"
上也进行了测试。唯一的区别是,在我的情况下,RGB₁ = distinguishable_colors(10)[5]
返回的颜色(RGB{U8}(0.0,0.522,1.0)
)不同。关于matplotlib - julia-lang-通过PyPlot命令使用Colors.jl数组,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39570531/