# Display array as image in Pluto

**URL:** https://discourse.julialang.org/t/display-array-as-image-in-pluto/48732
**Category:** Visualization
**Tags:** images, array, pluto
**Created:** [October 21, 2020, 8:41am UTC](https://discourse.julialang.org/t/display-array-as-image-in-pluto/48732 "2020-10-21T08:41:47Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![dahnielson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dahnielson/32/18821_2.png) [@dahnielson](https://discourse.julialang.org/u/dahnielson)
#### Post date: [October 21, 2020, 8:41am UTC](https://discourse.julialang.org/t/display-array-as-image-in-pluto/48732/1 "2020-10-21T08:41:47Z")

</div>

I’m pretty new to Julia and Pluto so this is my first stumbling block. How do I display an array as an image in Pluto? Say I have an 8x8 array of Float64 that I want to display as a gray scale image.

The JuliaImages documentation have screenshots of it being done in a Jupyter notebook but I can’t get it to work in my Pluto notebook.

---

<div class="post-metadata">

### Author: ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)
#### Post date: [October 21, 2020, 9:47am UTC](https://discourse.julialang.org/t/display-array-as-image-in-pluto/48732/2 "2020-10-21T09:47:42Z")

</div>

Just transform it to Colors should work. Pluto doesn’t work on my machine so I can’t test but I assume sth like

```julia
mat = rand(8,8)
using Colors
Gray.(mat)

```

should work.

---

<div class="post-metadata">

### Author: ![dahnielson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dahnielson/32/18821_2.png) [@dahnielson](https://discourse.julialang.org/u/dahnielson)
#### Post date: [October 21, 2020, 5:02pm UTC](https://discourse.julialang.org/t/display-array-as-image-in-pluto/48732/3 "2020-10-21T17:02:03Z")

</div>

Unfortunately that only result in the following MethodError in Pluto:

```julia
Failed to show value:
MethodError: no method matching save(::IOContext{Base.GenericIOBuffer{Array{UInt8,1}}}, ::Array{ColorTypes.Gray{Float64},2}, ::Pair{Symbol,ImageShow.var"#14#16"})
Closest candidates are:
save(::IO, ::S; compression_level, compression_strategy, filters, palette) where {T, S<:Union{AbstractArray{T,3}, AbstractArray{T,2} where T}} at H:\Users\Anders Dahnielson\.julia\packages\PNGFiles\Sgsmw\src\io.jl:278
save(!Matched::String, ::S; compression_level, compression_strategy, filters, palette) where {T, S<:Union{AbstractArray{T,3}, AbstractArray{T,2} where T}} at H:\Users\Anders Dahnielson\.julia\packages\PNGFiles\Sgsmw\src\io.jl:246

1. handle_error(::MethodError, ::FileIO.Stream{FileIO.DataFormat{:PNG},IOContext{Base.GenericIOBuffer{Array{UInt8,1}}}})@error_handling.jl:82
2. handle_exceptions(::Array{Any,1}, ::String)@error_handling.jl:77
3. #save#31(::Base.Iterators.Pairs{Symbol,ImageShow.var"#14#16",Tuple{Symbol},NamedTuple{(:mapi,),Tuple{ImageShow.var"#14#16"}}}, ::typeof(FileIO.save), ::FileIO.Formatted, ::Any)@loadsave.jl:235
4. #show#13(::Int64, ::Int64, ::Function, ::typeof(show), ::IOContext{Base.GenericIOBuffer{Array{UInt8,1}}}, ::MIME{Symbol("image/png")}, ::Array{ColorTypes.Gray{Float64},2})@showmime.jl:43
5. show(::IOContext{Base.GenericIOBuffer{Array{UInt8,1}}}, ::MIME{Symbol("image/png")}, ::Array{ColorTypes.Gray{Float64},2})@showmime.jl:28
6. #show_richest#18(::Bool, ::typeof(Main.PlutoRunner.show_richest), ::IOContext{Base.GenericIOBuffer{Array{UInt8,1}}}, ::Any)@PlutoRunner.jl:359
7. show_richest(::IOContext{Base.GenericIOBuffer{Array{UInt8,1}}}, ::Any)@PlutoRunner.jl:330
8. #sprint_withreturned#17(::IOContext{Base.PipeEndpoint}, ::Int64, ::typeof(Main.PlutoRunner.sprint_withreturned), ::Function, ::Array{ColorTypes.Gray{Float64},2})@PlutoRunner.jl:302
9. format_output(::Any)@PlutoRunner.jl:242
10. formatted_result_of(::Base.UUID, ::Bool)@PlutoRunner.jl:53
11. top-level scope@none:1

```

---

<div class="post-metadata">

### Author: ![mihalybaci](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mihalybaci/32/13528_2.png) [@mihalybaci](https://discourse.julialang.org/u/mihalybaci)
#### Post date: [October 21, 2020, 5:12pm UTC](https://discourse.julialang.org/t/display-array-as-image-in-pluto/48732/4 "2020-10-21T17:12:06Z")

</div>

Weird, that worked for me. Did you try opening up a blank notebook and just running those three commands?

---

<div class="post-metadata">

### Author: ![dahnielson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dahnielson/32/18821_2.png) [@dahnielson](https://discourse.julialang.org/u/dahnielson)
#### Post date: [October 21, 2020, 5:16pm UTC](https://discourse.julialang.org/t/display-array-as-image-in-pluto/48732/5 "2020-10-21T17:16:33Z")

</div>

Yes, weird. It worked now for me too in a blank notebook.

---

<div class="post-metadata">

### Author: ![mihalybaci](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mihalybaci/32/13528_2.png) [@mihalybaci](https://discourse.julialang.org/u/mihalybaci)
#### Post date: [October 21, 2020, 5:25pm UTC](https://discourse.julialang.org/t/display-array-as-image-in-pluto/48732/6 "2020-10-21T17:25:14Z")

</div>

It worked for me only importing `Colors`, but I got errors if I imported `Images` first so there might be some kind of conflict there.

---

<div class="post-metadata">

### Author: ![1115](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/1115/32/4465_2.png) [@1115](https://discourse.julialang.org/u/1115)
#### Post date: [October 25, 2020, 9:07pm UTC](https://discourse.julialang.org/t/display-array-as-image-in-pluto/48732/7 "2020-10-25T21:07:29Z")

</div>

For large image, Colors does not work too

```julia
┌ Warning: Output swatches are reduced due to the large size (400×400).
│ Load the ImageShow package for large images.
└ @ Colors ~/.julia/packages/Colors/kc2v8/src/display.jl:148

```

---

<div class="post-metadata">

### Author: ![fonsp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fonsp/32/222349_2.png) [@fonsp](https://discourse.julialang.org/u/fonsp)
#### Post date: [October 31, 2020, 1:41pm UTC](https://discourse.julialang.org/t/display-array-as-image-in-pluto/48732/8 "2020-10-31T13:41:54Z")

</div>

Building on the suggestion by @mkborregaard - you need to have Images and ImageMagick in your environment to show png images:  
[https://github.com/JuliaIO/ImageIO.jl/issues/6](https://github.com/JuliaIO/ImageIO.jl/issues/6)

```julia
begin
import Pkg
Pkg.activate(mktempdir())
Pkg.add(["Images", "ImageMagick"])
using Images
end

```

```julia
mat = rand(8,8)

```

```julia
Gray.(mat)

```

---

<div class="post-metadata">

### Author: ![airpmb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/airpmb/32/7826_2.png) [@airpmb](https://discourse.julialang.org/u/airpmb)
#### Post date: [November 7, 2020, 4:33pm UTC](https://discourse.julialang.org/t/display-array-as-image-in-pluto/48732/9 "2020-11-07T16:33:20Z")

</div>

Something simple, requiring no imports:

> <https://gist.github.com/pbouffard/3d48d3c47d9bd70e7c9f52f984d14245>

Usage is just like:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/1/3/138fe0b38fa924acbe4a806db0dfc8dce7f4f6e6.png)

(Credit due to fonsp: this is just slightly adapted from [https://github.com/fonsp/pluto-notebooks/blob/master/svd-video.jl](https://github.com/fonsp/pluto-notebooks/blob/master/svd-video.jl), which I think was used in the [JuliaCon 2020 Pluto talk](https://www.youtube.com/watch?v=IAF8DjrQSSk). It was hard to find again so figured I’d mention it here.)
