I’m trying to make a scatter plot where the x,y pairs form a (not necessarily rectangular) grid. The color of each point depends in a rather complicated way on the index of the point. Given two vectors, a1 and a2, my points are
n*a1+m*a2, where n and m each span some integer range.
I made this work by using two nested loops and computing a single index for each point, but I can’t help but think that
CartesianIndices is perfect for this use case. Despite spending a couple of hours, I couldn’t figure out how to use
CartesianIndices. Here’s a minimal working example.
using Plots nx, ny = 4,5 x = zeros(nx*ny) y = zeros(nx*ny) c = zeros(nx*ny) a1, a2 = [1.1,.5], [-.2,1.0] b = hcat(a1,a2) for i in 0:nx-1 for j in 0:ny-1 idx = j+i*ny+1 x[idx],y[idx] = b*[i,j] c[idx] = mod(i,7)/7+mod(j,3)/3 end end scatter(x,y,marker_z=c,colormap=:thermal)
While this is a passable solution, it seems rather like I’m still writing in Fortran…any suggestions on how to make this more Julian?