Fast way to display category data as image

I have a 500x500 array of Int64s between 1 and 10, representing arbitrary categories. I can display this as an image by doing the following in a notebook:

using Colors
colors = distinguishable_colors(10)

and then

[colors[d] for d in my_data]

but the problem is it takes quite a few seconds before the image is displayed, which makes me think I’m doing it the wrong way.

Is there a faster way to achieve the same effect? I was hoping to be able to animate the image as my data updates.

On my laptop, I just times an ímshow (from ImageView) of a 500x500 random array

julia> @time imshow(mydata)
15.419194 seconds (22.85 M allocations: 1.125 GiB, 5.20% gc time)
BUT do that again
julia> @time imshow(mydata)
0.139453 seconds (14.20 k allocations: 850.146 KiB)

Try this with your own data - the second and subsequent calls should be much faster.

I should have mentioned - I’m not able to install ImageView because of this problem. (I basically can’t install anything that relies certain dependencies, which seems to rule out most of the best options.)

The method I posted unfortunately doesn’t run faster the second time.

So you should use UInt8 instead of Int64.
Unfortunately GMT.jl has also become a bit slow on time-to-first plot, but it’s quick after

using GMT
julia> im = round.(rand(500,500)*9 .+ 1);

julia> @time imshow(im)
 11.931602 seconds (33.25 M allocations: 1.531 GiB, 6.28% gc time)

julia> @time imshow(im)
  0.335668 seconds (504.17 k allocations: 8.864 MiB)