Skip to content

Instantly share code, notes, and snippets.

@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()
@jkrumbiegel
jkrumbiegel / makie_slideshow.jl
Created January 27, 2024 17:50
Makie slide show
using GLMakie
slides = [
(gl) -> begin
for i in 1:2, j in 1:2
lines(gl[i, j], cumsum(randn(1000)))
end
return (; title = "A slide with two Axis")
end,
(gl) -> begin
@jkrumbiegel
jkrumbiegel / multiple_insets.jl
Created January 26, 2024 08:21
multiple inset axes in gridlayout
f = Figure()
main_ax = Axis(f[1, 1])
inset_gl = GridLayout(f[1, 1], alignmode = Outside(15))
inset_ax_1 = Axis(inset_gl[1:2, 1])
Label(inset_gl[1:2, 1, Right()], "(a)", valign = :top, padding = (5, 0, 0, 0))
inset_ax_2 = Axis(inset_gl[1, 2])
Label(inset_gl[1, 2, Left()], "(b)", valign = :top, padding = (0, 5, 0, 0))
inset_ax_3 = Axis(inset_gl[2, 2])
Label(inset_gl[2, 2, Left()], "(c)", valign = :top, padding = (0, 5, 0, 0))
for ax in [inset_ax_1, inset_ax_2, inset_ax_3]
@jkrumbiegel
jkrumbiegel / one_billion_rows.jl
Last active February 1, 2024 16:33
One Billion Rows Challenge Julia
using Mmap
using InlineStrings
using Dictionaries
using Parsers
function aggregate(file)
open(file, "r") do io
arr = mmap(io)
@jkrumbiegel
jkrumbiegel / stepped_contourf_volcano_makie.jl
Created December 19, 2023 10:46
Stepped contourf volcano plot in Makie
using GLMakie
using DelimitedFiles
volcano = readdlm(Makie.assetpath("volcano.csv"), ',', Float64)
_, _, ct = contourf(volcano; colormap = :lipari, levels = 20)
polys = ct.plots[1][1][]
@jkrumbiegel
jkrumbiegel / makie_3d_transformed_bands.jl
Created December 12, 2023 12:01
Makie 3d transformed bands
using CairoMakie
f = Figure()
ax = Axis3(f[1, 1])
for i in 1:5
data = abs.(cumsum(randn(50))) .+ 1
b = band!(ax, 1:50, zero(data), data)
Makie.transform!(b, (:xz, -i))
@jkrumbiegel
jkrumbiegel / detect_png_dpi.jl
Created November 21, 2023 09:54
Julia detect png dpi
function detect_png_dpi(io::IO)
# PNG header signature
png_signature = UInt8['\u89', 'P', 'N', 'G', '\r', '\n', '\u1a', '\n']
# Reset the IO position to the beginning
seekstart(io)
# Check if the PNG signature is present
if [read(io, UInt8) for _ in 1:length(png_signature)] != png_signature
error("Not a png file")