# Flipping the y-axis of heatmap in CairoMakie

**URL:** <https://discourse.julialang.org/t/flipping-the-y-axis-of-heatmap-in-cairomakie/86055>\
**Category:** Visualization\
**Tags:** makie, cairo\
**Created:** [August 20, 2022, 7:27am UTC](https://discourse.julialang.org/t/flipping-the-y-axis-of-heatmap-in-cairomakie/86055 "2022-08-20T07:27:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xavier\_Gonzalez](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xavier_gonzalez/32/36033_2.png) [@Xavier\_Gonzalez](https://discourse.julialang.org/u/Xavier_Gonzalez)\
**Post date:** [August 20, 2022, 7:27am UTC](https://discourse.julialang.org/t/flipping-the-y-axis-of-heatmap-in-cairomakie/86055/1 "2022-08-20T07:27:14Z")

</div>

I am trying to flip the y-axis in some heatmaps.

The below code (when I have only one heatmap) works fine:

```julia
begin
	fig = Figure(resolution=(600, 600))
	ax = Axis(fig[1, 1])
	hm = heatmap!(fig[1,1],mat)
	cb = Colorbar(fig[1, 2], hm)
	ax.yreversed=true
	fig
end

```

However, when I have two heatmaps, I have not yet figured out how to reverse the y-axis!  
The below code does not work.

```julia
begin
	f = Figure(resolution=(1100, 600), fontsize=14)
	CairoMakie.heatmap(f[1,1], mat1, yflip=true)
	CairoMakie.heatmap(f[1,2], mat2, yflip=true)
	f
end

```

The above code simply doesn’t flip anything.

Alternatively, when I try this code, I get the following horrendous error message

```julia
begin
	figg = Figure(resolution=(1100, 600), fontsize=14)
	ax1 = Axis(figg[1, 1])
	CairoMakie.heatmap(ax1, mat1)
	ax1.yreversed=true
	ax2 = Axis(figg[1, 2])
	CairoMakie.heatmap(ax2,mat2)
	ax2.yreversed=true
	figg
end

```

Here is the horrendous error message:

```julia
`Makie.convert_arguments` for the plot type MakieCore.Heatmap{Tuple{Makie.Axis, Matrix{Int64}}} and its conversion trait MakieCore.DiscreteSurface() was unsuccessful.

The signature that could not be converted was:

::Makie.Axis, ::Matrix{Float32}

Makie needs to convert all plot input arguments to types that can be consumed by the backends (typically Arrays with Float32 elements).

You can define a method for `Makie.convert_arguments` (a type recipe) for these types or their supertypes to make this set of arguments convertible (See http://makie.juliaplots.org/stable/documentation/recipes/index.html).

Alternatively, you can define `Makie.convert_single_argument` for single arguments which have types that are unknown to Makie but which can be converted to known types and fed back to the conversion pipeline.

error(::String)@error.jl:33
var"#convert_arguments#141"(::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, ::typeof(MakieCore.convert_arguments), ::Type{MakieCore.Heatmap{Tuple{Makie.Axis, Matrix{Int64}}}}, ::Makie.Axis, ::Vararg{Any})@conversions.jl:17
convert_arguments(::Type{MakieCore.Heatmap{Tuple{Makie.Axis, Matrix{Int64}}}}, ::Makie.Axis, ::Matrix{Float32})@conversions.jl:8
convert_arguments_individually(::Type{MakieCore.Heatmap{Tuple{Makie.Axis, Matrix{Int64}}}}, ::Makie.Axis, ::Vararg{Any})@conversions.jl:51
var"#convert_arguments#141"(::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, ::typeof(MakieCore.convert_arguments), ::Type{MakieCore.Heatmap{Tuple{Makie.Axis, Matrix{Int64}}}}, ::Makie.Axis, ::Vararg{Any})@conversions.jl:14
convert_arguments(::Type{MakieCore.Heatmap{Tuple{Makie.Axis, Matrix{Int64}}}}, ::Makie.Axis, ::Matrix{Int64})@conversions.jl:8
var"#plot!#136"(::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, ::typeof(MakieCore.plot!), ::Makie.Scene, ::Type{MakieCore.Heatmap}, ::MakieCore.Attributes, ::Makie.Axis, ::Vararg{Any})@interfaces.jl:315
plot!(::Makie.Scene, ::Type{MakieCore.Heatmap}, ::MakieCore.Attributes, ::Makie.Axis, ::Matrix{Int64})@interfaces.jl:301
var"#plot#1777"(::NamedTuple{(), Tuple{}}, ::NamedTuple{(), Tuple{}}, ::Base.Pairs{Symbol, Any, Tuple{Symbol, Symbol}, NamedTuple{(:colorrange, :colormap), Tuple{Tuple{Int64, Int64}, Symbol}}}, ::typeof(MakieCore.plot), ::Type{MakieCore.Heatmap}, ::Makie.Axis, ::Vararg{Any})@figureplotting.jl:48
var"#heatmap#19"(::Base.Pairs{Symbol, Any, Tuple{Symbol, Symbol}, NamedTuple{(:colorrange, :colormap), Tuple{Tuple{Int64, Int64}, Symbol}}}, ::typeof(MakieCore.heatmap), ::Makie.Axis, ::Vararg{Any})@recipes.jl:34
top-level scope@Local: 4[inlined]

```

Can anybody help me flip the y-axes for these heatmaps, or help me understand what is going on?

---

<div class="post-metadata">

**Author:** ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)\
**Post date:** [August 20, 2022, 7:38am UTC](https://discourse.julialang.org/t/flipping-the-y-axis-of-heatmap-in-cairomakie/86055/2 "2022-08-20T07:38:11Z")

</div>

> [@Xavier\_Gonzalez](#):
>
> ```julia
> CairoMakie.heatmap(ax2,mat2)
> 
> ```

I think it is just missing an `!` in these function calls: `CairoMakie.heatmap!(ax2,mat2)`  
(Since you plot into an existing axis the `!` is needed. The error message is coming since it was trying to make sense of `ax2` as `x` coordinates 😉 )

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [August 20, 2022, 10:56am UTC](https://discourse.julialang.org/t/flipping-the-y-axis-of-heatmap-in-cairomakie/86055/3 "2022-08-20T10:56:06Z")

</div>

There are examples of image orientation here [image](https://makie.juliaplots.org/stable/examples/plotting_functions/image/#examples)

---

<div class="post-metadata">

**Author:** ![Xavier\_Gonzalez](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xavier_gonzalez/32/36033_2.png) [@Xavier\_Gonzalez](https://discourse.julialang.org/u/Xavier_Gonzalez)\
**Post date:** [August 20, 2022, 5:56pm UTC](https://discourse.julialang.org/t/flipping-the-y-axis-of-heatmap-in-cairomakie/86055/4 "2022-08-20T17:56:45Z")

</div>

> [@Xavier\_Gonzalez](#):
>
> `	CairoMakie.heatmap(ax2,mat2)`

thank you so much, I did not understand what the ! was for
