@@ -121,52 +121,74 @@ SCATTER\\_GPLOT!(X; ...) adds a plot to `current` one.
121121
122122"""
123123function scatter_gplot (X; marker = nothing , ms = 4 , plotOrder = :normal , c = :viridis )
124- dim = size (X,2 )
125- if marker != nothing && plotOrder != :normal
126- if plotOrder == :s2l
124+ N, dim = size (X)
125+ if marker != nothing
126+ if size (marker) == (N,) || size (marker) == (N, 1 )
127+ marker = marker[:] # reshape N x 1 matrix to a vector of length N
128+ else
129+ error (" marker only accepts a vector of length $(N) or a matrix of size $(N) x 1." )
130+ end
131+ if plotOrder == :normal
132+ idx = 1 : N
133+ elseif plotOrder == :s2l
127134 idx = sortperm (marker)
128135 elseif plotOrder == :l2s
129- idx = sortperm (marker, rev= true )
136+ idx = sortperm (marker, rev = true )
130137 else
131- print ( " Error: plotOrder only supports for :normal, :s2l, or :l2s." )
138+ error ( " plotOrder only supports for :normal, :s2l, or :l2s." )
132139 end
133- X = X[idx,:]
140+ X = X[idx, :]
134141 marker = marker[idx]
135142 if length (ms) > 1
136143 ms = ms[idx]
137144 end
138145 end
139146 if dim == 2
140- scatter (X[:,1 ],X[:,2 ], marker_z = marker, ms = ms, c = c, legend = false , mswidth = 0 , cbar = true , aspect_ratio = 1 , grid = false )
147+ scatter (X[:, 1 ], X[:, 2 ], marker_z = marker, ms = ms, c = c,
148+ legend = false , mswidth = 0 , cbar = true , aspect_ratio = 1 ,
149+ grid = false )
141150 elseif dim == 3
142- scatter (X[:,1 ],X[:,2 ],X[:,3 ], marker_z = marker, ms = ms, c = c, legend = false , mswidth = 0 , cbar = true , aspect_ratio = 1 , grid = false )
151+ scatter (X[:, 1 ], X[:, 2 ], X[:, 3 ], marker_z = marker, ms = ms, c = c,
152+ legend = false , mswidth = 0 , cbar = true , aspect_ratio = 1 ,
153+ grid = false )
143154 else
144- print (" Dimension Error: scatter_gplot only supports for 2-dim or 3-dim scatter plots." )
155+ error (" Dimension Error: scatter_gplot only supports for 2-dim or 3-dim scatter plots." )
145156 end
146157end
147158
148159function scatter_gplot! (X; marker = nothing , ms = 4 , plotOrder = :normal , c = :viridis )
149- dim = size (X,2 )
150- if marker != nothing && plotOrder != :normal
151- if plotOrder == :s2l
160+ N, dim = size (X)
161+ if marker != nothing
162+ if size (marker) == (N,) || size (marker) == (N, 1 )
163+ marker = marker[:] # reshape N x 1 matrix to a vector of length N
164+ else
165+ error (" marker only accepts a vector of length $(N) or a matrix of size $(N) x 1." )
166+ end
167+ if plotOrder == :normal
168+ idx = 1 : N
169+ elseif plotOrder == :s2l
152170 idx = sortperm (marker)
153171 elseif plotOrder == :l2s
154- idx = sortperm (marker, rev= true )
172+ idx = sortperm (marker, rev = true )
155173 else
156- print ( " Error: plotOrder only supports for :normal, :s2l, or :l2s." )
174+ error ( " plotOrder only supports for :normal, :s2l, or :l2s." )
157175 end
158- X = X[idx,:]
176+ X = X[idx, :]
159177 marker = marker[idx]
160178 if length (ms) > 1
161179 ms = ms[idx]
162180 end
163181 end
164182 if dim == 2
165- scatter! (X[:,1 ],X[:,2 ], marker_z = marker, ms = ms, c = c, legend = false , mswidth = 0 , cbar = true , aspect_ratio = 1 , grid = false )
183+ scatter! (X[:, 1 ], X[:, 2 ], marker_z = marker, ms = ms, c = c,
184+ legend = false , mswidth = 0 , cbar = true , aspect_ratio = 1 ,
185+ grid = false )
166186 elseif dim == 3
167- scatter! (X[:,1 ],X[:,2 ],X[:,3 ], marker_z = marker, ms = ms, c = c, legend = false , mswidth = 0 , cbar = true , aspect_ratio = 1 , grid = false )
187+ scatter! (X[:, 1 ], X[:, 2 ], X[:, 3 ], marker_z = marker, ms = ms, c = c,
188+ legend = false , mswidth = 0 , cbar = true , aspect_ratio = 1 ,
189+ grid = false )
168190 else
169- print (" Dimension Error: scatter_gplot! only supports for 2-dim or 3-dim scatter plots." )
191+ error (" Dimension Error: scatter_gplot! only supports for 2-dim or 3-dim scatter plots." )
170192 end
171193end
172194
0 commit comments