Reputation: 65
I am trying to assign an RGB tuple generated with distinguishable_colors from Colors.jl to an specific line with pyplot in Julia lang, for instance:
using PyPlot, Colors
RGB_1 = distinguishable_colors(10)[5]
plot(linspace(1,10,10), color=RGB_1)
But it seems the rgb space colors are not suitable for the plot:
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
Is there anyway to get the tuple (0.0,0.0,0.0) from the Colors.jl generated arrays, instead of the RGB{U8}(0.0,0.0,0.0)? I noticed that
plot(linspace(1,10,10), color=(0.0,0.0,0.0))
does work. Julia 0.3.2 with matplotlib 1.4.2.
Upvotes: 4
Views: 1106
Reputation: 7893
You can give the color
option of the plot
function a tuple of 3 UFixed8
(which is an alias for FixedPointNumbers.UFixed{UInt8,8}
). Colors.jl
has the following functions red
, green
and blue
to get each respective field from an RGB
type, each one of UFixed8
type:
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>
Out:
Tested on v"0.3.12"
also. The only difference is that RGB₁ = distinguishable_colors(10)[5]
returns a different color (RGB{U8}(0.0,0.522,1.0)
) in my case.
Upvotes: 2