@@ -7,7 +7,7 @@ export ColorMap, get_cmap, register_cmap, get_cmaps
77# #######################################################################
88# Wrapper around colors.Colormap type:
99
10- type ColorMap
10+ mutable struct ColorMap
1111 o:: PyObject
1212end
1313
5858
5959# most general constructors using RGB arrays of triples, defined
6060# 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 } =
6666 ColorMap (name, r,g,b, Array {Tuple{T,T,T}} (0 ), n, gamma)
6767
6868# 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
7676 segmentdata = Dict (" red" => r, " green" => g, " blue" => b)
7777 if ! isempty (a)
7878 segmentdata[" alpha" ] = a
@@ -82,8 +82,8 @@ function ColorMap{T<:Real}(name::Union{AbstractString,Symbol},
8282end
8383
8484# 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
8787 nc = length (c)
8888 if nc == 0
8989 throw (ArgumentError (" ColorMap requires a non-empty Colorant array" ))
@@ -111,12 +111,12 @@ function ColorMap{T<:Colorant}(name::Union{AbstractString,Symbol},
111111 ColorMap (name, r,g,b,a, n, gamma)
112112end
113113
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 } =
116116 ColorMap (string (" cm_" , hash (c)), c, n, gamma)
117117
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
120120 if size (c,2 ) == 3
121121 return ColorMap (name,
122122 [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
131131 end
132132end
133133
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 } =
135135 ColorMap (string (" cm_" , hash (c)), c, n, gamma)
136136
137137# #######################################################################
0 commit comments