Skip to content

Instantly share code, notes, and snippets.

@asinghvi17
Created June 16, 2022 12:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asinghvi17/977eac26e52e5c6a8dcfa3bbb1084eb8 to your computer and use it in GitHub Desktop.
Save asinghvi17/977eac26e52e5c6a8dcfa3bbb1084eb8 to your computer and use it in GitHub Desktop.
Flip axis in Makie using PointTrans
using Makie, CairoMakie
# patch a bug in Makie, will push a PR laters
@eval Makie begin
function apply_transform(f::PointTrans{N}, point::VecTypes{N}) where N
return f.f(point)
end
function apply_transform(f::PointTrans{N1}, point::VecTypes{N2}) where {N1, N2}
p_dim = to_ndim(Point{N1, Float32}, point, 0.0)
p_trans = f.f(p_dim)
if N1 < N2
p_large = ntuple(i-> i <= N1 ? p_trans[i] : point[i], N2)
return Point{N2, Float32}(p_large)
else
return to_ndim(Point{N2, Float32}, p_trans, 0.0)
end
end
end
trans = Makie.PointTrans{2}(reverse)
Makie.apply_transform(::typeof(trans), r::Rect2) = Rect2(reverse(r.origin), reverse(r.widths))
# taken from documentation example
tbl = (x = [1, 1, 1, 2, 2, 2, 3, 3, 3],
height = 0.1:0.1:0.9,
grp = [1, 2, 3, 1, 2, 3, 1, 2, 3],
grp1 = [1, 2, 2, 1, 1, 2, 1, 1, 2],
grp2 = [1, 1, 2, 1, 2, 1, 1, 2, 1]
)
fig, ax, plt = barplot(tbl.x, tbl.height,
stack = tbl.grp,
color = tbl.grp,
orientation = :x)
st = Stepper(fig)
ax.title[] = "Step 1"
Makie.step!(st)
ax.scene.transformation.transform_func[] = trans
ax.title[] = "Step 2"
Makie.step!(st)
save("axis_transformation", st)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment