# How to plot a matrix of colors

**URL:** <https://discourse.julialang.org/t/how-to-plot-a-matrix-of-colors/41920>\
**Category:** Visualization\
**Created:** [June 23, 2020, 8:50am UTC](https://discourse.julialang.org/t/how-to-plot-a-matrix-of-colors/41920 "2020-06-23T08:50:49Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![Torkel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/torkel/32/5030_2.png) [@Torkel](https://discourse.julialang.org/u/Torkel)\
**Post date:** [June 23, 2020, 9:36am UTC](https://discourse.julialang.org/t/how-to-plot-a-matrix-of-colors/41920/3 "2020-06-23T09:36:31Z")

</div>

Running the last part of that example gives me an error:

```error
The latex command `lualatex jl_FXPARL.tex` failed
error(::String) at error.jl:33
savepdf(::String, ::TikzDocument; latex_engine::PGFPlotsX.LaTeXEngine, buildflags::Array{String,1}, run_count::Int64, tmp::String) at tikzdocument.jl:197
savepdf at tikzdocument.jl:158 [inlined]
savesvg(::String, ::TikzDocument; latex_engine::PGFPlotsX.LaTeXEngine, buildflags::Array{String,1}, keep_pdf::Bool) at tikzdocument.jl:267
savesvg at tikzdocument.jl:266 [inlined]
save(::String, ::TikzDocument; include_preamble::Bool, latex_engine::PGFPlotsX.LaTeXEngine, buildflags::Array{String,1}, dpi::Int64, showing_ide::Bool) at tikzdocument.jl:84
(::PGFPlotsX.var"#save##kw")(::NamedTuple{(:showing_ide,),Tuple{Bool}}, ::typeof(PGFPlotsX.save), ::String, ::TikzDocument) at tikzdocument.jl:73
#save#60 at tikzpicture.jl:34 [inlined]
save at tikzpicture.jl:34 [inlined]
#save#55 at axislike.jl:45 [inlined]
(::PGFPlotsX.var"#save##kw")(::NamedTuple{(:showing_ide,),Tuple{Bool}}, ::typeof(PGFPlotsX.save), ::String, ::Axis) at axislike.jl:45
show(::IOContext{Base.GenericIOBuffer{Array{UInt8,1}}}, ::MIME{Symbol("image/svg+xml")}, ::Axis) at tikzdocument.jl:289
show(::IOContext{Base.GenericIOBuffer{Array{UInt8,1}}}, ::String, ::Axis) at multimedia.jl:109
displayinplotpane(::Axis) at showdisplay.jl:67
displayandrender(::Axis) at showdisplay.jl:131
(::Atom.var"#208#213"{String})() at eval.jl:136
#invokelatest#1 at essentials.jl:712 [inlined]
invokelatest at essentials.jl:711 [inlined]
macro expansion at dynamic.jl:24 [inlined]
eval(::String, ::Int64, ::String, ::String, ::Bool) at eval.jl:113
invokelatest(::Any, ::Any, ::Vararg{Any,N} where N; kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at essentials.jl:712
invokelatest(::Any, ::Any, ::Vararg{Any,N} where N) at essentials.jl:711
macro expansion at eval.jl:41 [inlined]
(::Atom.var"#188#189")() at task.jl:358

```

Searching on “matrix plot” I found another example at

> [@PGFPlotsX a matrix of RGB](https://discourse.julialang.org/t/pgfplotsx-a-matrix-of-rgb/24709):
>
> I have an image – a matrix of RGBs. The number of pixels is relatively small (e.g. 20×20), so I want to plot it as an array of colored squares. This way the dimensions of the resulting figure won’t be dictated by the low resolution of the image. I think I need a combination of [this](https://kristofferc.github.io/PGFPlotsX.jl/stable/examples/coordinates/#Matrix-plot-1) and [this](https://tex.stackexchange.com/a/57201/12370), but I’m not sure. For the sake of a MWE: img = rand(RGB{Float64}, 20, 20)

here, the line

```julia
rand(RGB{Float64}, 20, 20)

```

seems to plot a random matrix, but I am not sure how to convert from `:red` to `RGB{Float64}`.

---

_[View the full topic](https://discourse.julialang.org/t/how-to-plot-a-matrix-of-colors/41920)._
