控制带有两个嵌板的Julia图形的纵横比



我试图在Julia中制作一个两面板的图,其中左侧面板是热图,右侧面板是直方图。

这是我这样做的代码,使用数组X和向量y

begin
f = Figure()
CairoMakie.heatmap(f[1,1], X)
CairoMakie.hist(f[1,2], y)
f
end

我想强制左侧面板(热图(的纵横比为1。

所有的教程(如本教程(都建议设置一个轴,我认为这将是以下代码中的内容:

begin
f = Figure()
ax1 = Axis(f[1,1], aspect = 1)
ax2 = Axis(f[1,2])
CairoMakie.heatmap(ax1, X)
CairoMakie.hist(ax2, y)
f
end

然而,当我这样做时,我会得到以下错误:

`Makie.convert_arguments` for the plot type MakieCore.Heatmap{Tuple{Makie.MakieLayout.Axis, Matrix{Float64}}} and its conversion trait MakieCore.DiscreteSurface() was unsuccessful.
The signature that could not be converted was:
::Makie.MakieLayout.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#144"(::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, ::typeof(MakieCore.convert_arguments), ::Type{MakieCore.Heatmap{Tuple{Makie.MakieLayout.Axis, Matrix{Float64}}}}, ::Makie.MakieLayout.Axis, ::Vararg{Any})@conversions.jl:17
convert_arguments(::Type{MakieCore.Heatmap{Tuple{Makie.MakieLayout.Axis, Matrix{Float64}}}}, ::Makie.MakieLayout.Axis, ::Matrix{Float32})@conversions.jl:8
convert_arguments_individually(::Type{MakieCore.Heatmap{Tuple{Makie.MakieLayout.Axis, Matrix{Float64}}}}, ::Makie.MakieLayout.Axis, ::Vararg{Any})@conversions.jl:51
var"#convert_arguments#144"(::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, ::typeof(MakieCore.convert_arguments), ::Type{MakieCore.Heatmap{Tuple{Makie.MakieLayout.Axis, Matrix{Float64}}}}, ::Makie.MakieLayout.Axis, ::Vararg{Any})@conversions.jl:14
convert_arguments(::Type{MakieCore.Heatmap{Tuple{Makie.MakieLayout.Axis, Matrix{Float64}}}}, ::Makie.MakieLayout.Axis, ::Matrix{Float64})@conversions.jl:8
var"#plot!#139"(::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, ::typeof(MakieCore.plot!), ::Makie.Scene, ::Type{MakieCore.Heatmap}, ::MakieCore.Attributes, ::Makie.MakieLayout.Axis, ::Vararg{Any})@interfaces.jl:302
plot!(::Makie.Scene, ::Type{MakieCore.Heatmap}, ::MakieCore.Attributes, ::Makie.MakieLayout.Axis, ::Matrix{Float64})@interfaces.jl:288
var"#plot#929"(::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.MakieLayout.Axis, ::Vararg{Any})@figureplotting.jl:28
var"#heatmap#19"(::Base.Pairs{Symbol, Any, Tuple{Symbol, Symbol}, NamedTuple{(:colorrange, :colormap), Tuple{Tuple{Int64, Int64}, Symbol}}}, ::typeof(MakieCore.heatmap), ::Makie.MakieLayout.Axis, ::Vararg{Any})@recipes.jl:33
top-level scope@Local: 6

我真的不明白这个错误是怎么回事,即使在谷歌上搜索了一下

我很好奇是否有人了解这个错误是什么,或者我能做些什么让我的热图的纵横比为1?

目前还没有很好的文档,但Axis会创建一个初始的空白图。因此,一旦定义了Axis,就需要使用bang-char修改函数将数据添加到图中:

using CairoMakie
begin
y = randn(100)
X = collect(1:100)
f = Figure()
ax1 = Axis(f[1,1], aspect = 1)
ax2 = Axis(f[1,2])
CairoMakie.heatmap!(ax1, X, y, y)
CairoMakie.hist!(ax2, y)
f
end

(注意:我创建了一个X和y,因为你没有提供它们。但我怀疑你的X是否是一个1d向量,如果它本身就是热图的话,因为热图!通常需要X、y和z输入值。(

最新更新