@@ -7,7 +7,7 @@ export ColorMap, get_cmap, register_cmap, get_cmaps
7
7
# #######################################################################
8
8
# Wrapper around colors.Colormap type:
9
9
10
- type ColorMap
10
+ mutable struct ColorMap
11
11
o:: PyObject
12
12
end
13
13
58
58
59
59
# most general constructors using RGB arrays of triples, defined
60
60
# as for matplotlib.colors.LinearSegmentedColormap
61
- ColorMap {T<:Real} (name:: Union{AbstractString,Symbol} ,
62
- r:: AbstractVector{Tuple{T,T,T}} ,
63
- g:: AbstractVector{Tuple{T,T,T}} ,
64
- b:: AbstractVector{Tuple{T,T,T}} ,
65
- n= max (256 ,length (r),length (g),length (b)), gamma= 1.0 ) =
61
+ ColorMap (name:: Union{AbstractString,Symbol} ,
62
+ r:: AbstractVector{Tuple{T,T,T}} ,
63
+ g:: AbstractVector{Tuple{T,T,T}} ,
64
+ b:: AbstractVector{Tuple{T,T,T}} ,
65
+ n= max (256 ,length (r),length (g),length (b)), gamma= 1.0 ) where {T <: Real } =
66
66
ColorMap (name, r,g,b, Array {Tuple{T,T,T}} (0 ), n, gamma)
67
67
68
68
# as above, but also passing an alpha array
69
- function ColorMap {T<:Real} (name:: Union{AbstractString,Symbol} ,
70
- r:: AbstractVector{Tuple{T,T,T}} ,
71
- g:: AbstractVector{Tuple{T,T,T}} ,
72
- b:: AbstractVector{Tuple{T,T,T}} ,
73
- a:: AbstractVector{Tuple{T,T,T}} ,
74
- n= max (256 ,length (r),length (g),length (b),length (a)),
75
- gamma= 1.0 )
69
+ function ColorMap (name:: Union{AbstractString,Symbol} ,
70
+ r:: AbstractVector{Tuple{T,T,T}} ,
71
+ g:: AbstractVector{Tuple{T,T,T}} ,
72
+ b:: AbstractVector{Tuple{T,T,T}} ,
73
+ a:: AbstractVector{Tuple{T,T,T}} ,
74
+ n= max (256 ,length (r),length (g),length (b),length (a)),
75
+ gamma= 1.0 ) where T <: Real
76
76
segmentdata = Dict (" red" => r, " green" => g, " blue" => b)
77
77
if ! isempty (a)
78
78
segmentdata[" alpha" ] = a
@@ -82,8 +82,8 @@ function ColorMap{T<:Real}(name::Union{AbstractString,Symbol},
82
82
end
83
83
84
84
# create from an array c, assuming linear mapping from [0,1] to c
85
- function ColorMap {T<:Colorant} (name:: Union{AbstractString,Symbol} ,
86
- c:: AbstractVector{T} , n= max (256 , length (c)), gamma= 1.0 )
85
+ function ColorMap (name:: Union{AbstractString,Symbol} ,
86
+ c:: AbstractVector{T} , n= max (256 , length (c)), gamma= 1.0 ) where T <: Colorant
87
87
nc = length (c)
88
88
if nc == 0
89
89
throw (ArgumentError (" ColorMap requires a non-empty Colorant array" ))
@@ -111,12 +111,12 @@ function ColorMap{T<:Colorant}(name::Union{AbstractString,Symbol},
111
111
ColorMap (name, r,g,b,a, n, gamma)
112
112
end
113
113
114
- ColorMap {T<:Colorant} (c:: AbstractVector{T} ,
115
- n= max (256 , length (c)), gamma= 1.0 ) =
114
+ ColorMap (c:: AbstractVector{T} ,
115
+ n= max (256 , length (c)), gamma= 1.0 ) where {T <: Colorant } =
116
116
ColorMap (string (" cm_" , hash (c)), c, n, gamma)
117
117
118
- function ColorMap {T<:Real} (name:: Union{AbstractString,Symbol} , c:: AbstractMatrix{T} ,
119
- n= max (256 , size (c,1 )), gamma= 1.0 )
118
+ function ColorMap (name:: Union{AbstractString,Symbol} , c:: AbstractMatrix{T} ,
119
+ n= max (256 , size (c,1 )), gamma= 1.0 ) where T <: Real
120
120
if size (c,2 ) == 3
121
121
return ColorMap (name,
122
122
[RGB {T} (c[i,1 ],c[i,2 ],c[i,3 ]) for i in 1 : size (c,1 )],
@@ -131,7 +131,7 @@ function ColorMap{T<:Real}(name::Union{AbstractString,Symbol}, c::AbstractMatrix
131
131
end
132
132
end
133
133
134
- ColorMap {T<:Real} (c:: AbstractMatrix{T} , n= max (256 , size (c,1 )), gamma= 1.0 ) =
134
+ ColorMap (c:: AbstractMatrix{T} , n= max (256 , size (c,1 )), gamma= 1.0 ) where {T <: Real } =
135
135
ColorMap (string (" cm_" , hash (c)), c, n, gamma)
136
136
137
137
# #######################################################################
0 commit comments