Skip to content

Instantly share code, notes, and snippets.

View jkrumbiegel's full-sized avatar

Julius Krumbiegel jkrumbiegel

View GitHub Profile
@jkrumbiegel
jkrumbiegel / striped_line_makie.jl
Last active November 22, 2024 13:49
Striped line Makie
using LinearAlgebra
@recipe(Stripy) do scene
Attributes(;
Makie.default_theme(scene, Lines)...,
n = 3,
offset = 10,
)
end
@jkrumbiegel
jkrumbiegel / makie_menu_bar.jl
Created November 18, 2024 10:43
Makie top menu bar
using GLMakie
f = Figure(figure_padding = 0)
topbar = GridLayout(f[1, 1], default_colgap = 1, halign = :left, tellwidth = false)
Box(f[1, 1], strokewidth = 0)
Button(topbar[1, 1], label = "Button", cornerradius = 0)
Menu(topbar[1, 2], options = ["Menu A", "Menu B", "Menu C"], width = 100)
maingl = GridLayout(f[2, 1], alignmode = Outside(16))
Axis(maingl[1, 1])
f
@jkrumbiegel
jkrumbiegel / typesetting.jl
Created September 28, 2024 06:46
Latex or typst like matrix or table typesetting in Makie
using CairoMakie
f = Figure(fonts = (; regular = "CMU"))
Label(f[1, 1], "Weights", fontsize = 20)
gl = GridLayout(f[2, 1])
for i in 1:5, j in 1:5
text = if i <=3 && j <= 3
rich("w", subscript("$i,$j"))
@recipe(AxisFunction) do scene
default_theme(scene, Lines)
end
Makie.data_limits(::AxisFunction) = Rect3f(Point3f(NaN), Vec3f(NaN))
Makie.boundingbox(::AxisFunction, space::Symbol = :data) = Rect3f(Point3f(NaN), Vec3f(NaN))
function Makie.plot!(p::AxisFunction)
func = p[1]
# # could use transf to compute points equidistant in transformed space
@jkrumbiegel
jkrumbiegel / legend_override_markersize.jl
Created May 31, 2024 11:32
Makie override axis scatter markersize in Legend
f, ax, sc = scatter(cumsum(randn(1000)), markersize = 3, label = "Scatter")
leg = Legend(f[1, 2], ax)
leg.entrygroups[][1][2][1].elements[1].attributes.markersize = Observable(10)
notify(leg.entrygroups)
f
@jkrumbiegel
jkrumbiegel / mixed_coordinate_text.jl
Created May 31, 2024 08:42
Makie mixed coordinate space text
f = Figure()
ax = Axis(f[1, 1])
relative_y(ax, x, y_rel) = lift(ax.finallimits) do lims
y = lims.origin[2] + lims.widths[2] * y_rel
Point(x, y)
end
text!(ax, relative_y(ax, 50, 0.8), text = "50, 0.8", yautolimits = false)
text!(ax, relative_y(ax, 50, 0.2), text = "50, 0.2", yautolimits = false)
@jkrumbiegel
jkrumbiegel / makie_delete_gridlayout_recursively.jl
Created February 28, 2024 14:34
Makie delete gridlayout recursively
using GLMakie
f = Figure()
b = Button(f[1, 1], tellwidth = false)
gl = GridLayout(f[2, 1])
function delete_contents!(gl::GridLayout)
for c in contents(gl)
if c isa GridLayout
delete_contents!(c)
@jkrumbiegel
jkrumbiegel / get_axis_from_figure.jl
Created February 15, 2024 16:42
how to get axes from a `Figure` in Makie
f = Figure()
for i in 1:3, j in 1:3
Axis(f[i, j], title = "$i, $j")
end
# pretend you get f here and want to change Axes you can't directly get as variables
ax = f.content[3]
ax.subtitle = "f.content[3]"
@jkrumbiegel
jkrumbiegel / makie_layout_boxes.jl
Created February 8, 2024 07:51
Makie layout visualization boxes
f = Figure()
Axis(f[1, 1], title = "Hey")
Axis(f[1, 2], title = "Ho")
Colorbar(f[1, 3])
Label(f[2, :], "A long spanning label")
Colorbar(f[3, 1:2], vertical = false)
f
function show_layout(f::Figure)
fig = Figure(size = size(f.scene), backgroundcolor = :gray50)
@jkrumbiegel
jkrumbiegel / detect_physical_size.jl
Created January 29, 2024 07:59
detect physical size png
function detect_png_physical_size(io::IO)
png_signature = "\x89PNG\r\n\x1a\n"
seekstart(io)
if String([read(io, UInt8) for _ in 1:length(png_signature)]) != png_signature
throw(ArgumentError("Not a png file"))
end
function read_chunk_length()