Flipping the y-axis of heatmap in CairoMakie

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

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

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.

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

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:

`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?

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 :wink: )

1 Like

There are examples of image orientation here image

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

1 Like