# Fast way to display category data as image

**URL:** https://discourse.julialang.org/t/fast-way-to-display-category-data-as-image/24695
**Category:** New to Julia
**Tags:** images
**Created:** [May 28, 2019, 1:36pm UTC](https://discourse.julialang.org/t/fast-way-to-display-category-data-as-image/24695 "2019-05-28T13:36:19Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Nathaniel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nathaniel/32/37854_2.png) [@Nathaniel](https://discourse.julialang.org/u/Nathaniel)
#### Post date: [May 28, 2019, 1:36pm UTC](https://discourse.julialang.org/t/fast-way-to-display-category-data-as-image/24695/1 "2019-05-28T13:36:19Z")

</div>

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

```julia
using Colors
colors = distinguishable_colors(10)

```

and then

```julia
[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.

---

<div class="post-metadata">

### Author: ![johnh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnh/32/3615_2.png) [@johnh](https://discourse.julialang.org/u/johnh)
#### Post date: [May 28, 2019, 1:49pm UTC](https://discourse.julialang.org/t/fast-way-to-display-category-data-as-image/24695/2 "2019-05-28T13:49:47Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Nathaniel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nathaniel/32/37854_2.png) [@Nathaniel](https://discourse.julialang.org/u/Nathaniel)
#### Post date: [May 28, 2019, 2:10pm UTC](https://discourse.julialang.org/t/fast-way-to-display-category-data-as-image/24695/3 "2019-05-28T14:10:52Z")

</div>

I should have mentioned - I’m not able to install ImageView because of [this problem](https://discourse.julialang.org/t/errors-when-building-some-packages-on-os-x-10-11/24646). (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.

---

<div class="post-metadata">

### Author: ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)
#### Post date: [May 28, 2019, 2:26pm UTC](https://discourse.julialang.org/t/fast-way-to-display-category-data-as-image/24695/4 "2019-05-28T14:26:32Z")

</div>

> [@Nathaniel](#):
>
> I have a 500x500 array of `Int64` s between 1 and 10

So you should use UInt8 instead of Int64.  
Unfortunately [GMT.jl](https://github.com/GenericMappingTools/GMT.jl) has also become a bit slow on time-to-first plot, but it’s quick after

```julia
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)

```
