【发布时间】:2022-08-16 11:09:35
【问题描述】:
我正在尝试制作具有边际密度的散点图,并让散点图具有固定的 x 和 y 限制,纵横比等于 1。但是,我似乎找不到轴链接、轴限制的组合,和适合这个的 colsize。
这很接近,但请注意散点图没有相等的轴:
using CairoMakie
n = 3000
r = randn(2,3000)
x = @view r[1,:]
y = @view r[2,:]
fig = Figure(resolution = (1000, 1000), font = \"sans\", fontsize = 20)
ax1 = (Axis(fig[1, 1]))
density!(ax1, y; bins = 20, color = :orange, strokewidth = 1,
strokecolor = :black, label = \"20 bins\", aspect=1)
ax3 = Axis(fig[2, 1]; xlabel = \"value\", ylabel = \"counts\")
ax4 = Axis(fig[2, 2]; xlabel = \"value\", ylabel = \"counts\")
scatter!(ax3, x, y; markersize = 4, color = :black,label=\"samples\")
axislegend(ax3; position = :rt)
density!(ax4, x; label = \"default\",direction=:y)
rowsize!(fig.layout, 2, Auto(3))
colsize!(fig.layout, 1, Auto(3))
xlims!(ax3,-4,4)
ylims!(ax3,-4,4)
linkxaxes!(ax1, ax3)
linkyaxes!(ax3, ax4)
fig
产生:
这是这篇文章的后续问题:Change the size of a sub-figure?
-
只需将 aspect_ratio=1 添加到
scatter!图中? -
@MikaelÖhman,是的,看起来它有效(我有
aspect=1而不是aspect_ratio=1)你想创建一个答案来接受吗?此外,也许对这两个 kwargs 之间差异的快速解释也有助于理解。