@@ -121,15 +121,20 @@ 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 )
124+ N, dim = size (X)
125125 if marker != nothing && plotOrder != :normal
126- marker = marker[:] # reshape N x 1 matrix to a N-dim vector
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 an N x 1 matrix,
130+ where N is the total number of points." )
131+ end
127132 if plotOrder == :s2l
128133 idx = sortperm (marker)
129134 elseif plotOrder == :l2s
130135 idx = sortperm (marker, rev= true )
131136 else
132- print ( " Error: plotOrder only supports for :normal, :s2l, or :l2s." )
137+ error ( " plotOrder only supports for :normal, :s2l, or :l2s." )
133138 end
134139 X = X[idx,:]
135140 marker = marker[idx]
@@ -142,20 +147,25 @@ function scatter_gplot(X; marker = nothing, ms = 4, plotOrder = :normal, c = :vi
142147 elseif dim == 3
143148 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 )
144149 else
145- print (" Dimension Error: scatter_gplot only supports for 2-dim or 3-dim scatter plots." )
150+ error (" Dimension Error: scatter_gplot only supports for 2-dim or 3-dim scatter plots." )
146151 end
147152end
148153
149154function scatter_gplot! (X; marker = nothing , ms = 4 , plotOrder = :normal , c = :viridis )
150- dim = size (X, 2 )
155+ N, dim = size (X)
151156 if marker != nothing && plotOrder != :normal
152- marker = marker[:] # reshape N x 1 matrix to a N-dim vector
157+ if size (marker) == (N,) || size (marker) == (N, 1 )
158+ marker = marker[:] # reshape N x 1 matrix to a vector of length N
159+ else
160+ error (" marker only accepts a vector of length N or an N x 1 matrix,
161+ where N is the total number of points." )
162+ end
153163 if plotOrder == :s2l
154164 idx = sortperm (marker)
155165 elseif plotOrder == :l2s
156166 idx = sortperm (marker, rev= true )
157167 else
158- print ( " Error: plotOrder only supports for :normal, :s2l, or :l2s." )
168+ error ( " plotOrder only supports for :normal, :s2l, or :l2s." )
159169 end
160170 X = X[idx,:]
161171 marker = marker[idx]
@@ -168,7 +178,7 @@ function scatter_gplot!(X; marker = nothing, ms = 4, plotOrder = :normal, c = :v
168178 elseif dim == 3
169179 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 )
170180 else
171- print (" Dimension Error: scatter_gplot! only supports for 2-dim or 3-dim scatter plots." )
181+ error (" Dimension Error: scatter_gplot! only supports for 2-dim or 3-dim scatter plots." )
172182 end
173183end
174184
0 commit comments