Skip to content

Instantly share code, notes, and snippets.

View jkrumbiegel's full-sized avatar

Julius Krumbiegel jkrumbiegel

View GitHub Profile
f = Figure()
ax = Axis(f[1, 1])
ax2 = Axis(f[1, 1], width = Relative(0.3), height = Relative(0.3), valign = 0.8, halign = 0.8)
p = Point(1, 1)
scatter!(ax, p, markersize = 15)
limits!(ax, 0, 10, 0, 10)
points = lift(ax.scene.px_area, ax.scene.camera.projectionview, ax2.scene.px_area) do pxa, pv, pxa2
p1 = Makie.bottomright(pxa2) - pxa.origin
using CairoMakie
using Makie.GeometryBasics
function mandelbrot(x, y)
z = c = x + y*im
for i in 1:50.0; abs(z) > 2 && return log(50 - i); z = z^2 + c; end; 0.0
end
# r = Rect(-0.74250066, 0.39089617, 0.43069285, 0.34233275)
r = HyperRectangle{2, Float32}(Float32[-0.62557947, 0.6001665], Float32[0.056850735, 0.041836016])
@jkrumbiegel
jkrumbiegel / glmakie_row_selection_heatmap.jl
Created July 1, 2022 07:58
glmakie row selection heatmap
using GLMakie
data = Observable(randn(30, 30))
lineindex = Observable(1)
linedata = @lift $data[:, $lineindex]
f, ax, hm = heatmap(data, axis = (; aspect = 1))
selectionrect = @lift Rect2f(0.5, $lineindex-0.5, size($data, 1), 1)
wireframe!(selectionrect, color = :white)
@jkrumbiegel
jkrumbiegel / transparent_glmakie_background.jl
Created June 9, 2022 07:28
Transparent GLMakie background
C_1 = C_a * α_a + C_b1 * (1 - α_a)
C_2 = C_a * α_a + C_b2 * (1 - α_a)
C_1 - C_2 = (C_b1 - C_b2) * (1 - α_a)
1 - (C_1 - C_2) / (C_b1 - C_b2) = α_a
(C_1 - (C_b1 * (1 - α_a))) / α_a = C_a
##
@jkrumbiegel
jkrumbiegel / multiobservable.jl
Created May 23, 2022 12:24
Mockup of an observable with multiple entries
mutable struct Multiobservable
value::NamedTuple
listeners::Vector
end
Multiobservable(nt) = Multiobservable(nt, [])
function Makie.Observables.on(f, m::Multiobservable, syms::Symbol...)
push!(m.listeners, f)
f
@jkrumbiegel
jkrumbiegel / makie_3d_barplot.jl
Created May 21, 2022 10:54
Makie 3D Barplot
@recipe(Barplot3D) do scene
Attributes(
color = theme(scene, :markercolor),
colormap = theme(scene, :colormap),
)
end
Makie.conversion_trait(::Type{<:Barplot3D}) = Makie.DiscreteSurface()
function Makie.plot!(p::Barplot3D)
@jkrumbiegel
jkrumbiegel / align_ylabels.jl
Created May 6, 2022 11:12
Makie align y labels
function align_ylabels!(axs...)
max_extent = maximum(axs) do ax
tight_yticklabel_spacing!(ax)
ax.yticklabelspace[]
end
for ax in axs
ax.yticklabelspace = max_extent
end
return
end
@jkrumbiegel
jkrumbiegel / gridlayout_boxes_with_padding.jl
Created May 4, 2022 10:45
GridLayout Boxes with padding
f = Figure()
b = Box(f[1, 1], color = :tomato)
translate!(b.elements[:rect], 0, 0, -100)
gl = f[1, 1] = GridLayout(alignmode = Outside(30))
for i in 1:2, j in 1:2
ax = Axis(gl[i, j])
end
@jkrumbiegel
jkrumbiegel / makie_sankey.jl
Created March 12, 2022 13:25
sankey makie
function sankey!(target, x1, x2, bend, start_min, start_max, stop_min, stop_max, color_start, color_stop)
bezier(t, p1, p2, p3, p4) = (1 - t)^3 * p1 + 3(1 - t)^2 * t * p2 + 3 * (1 - t) * t^2 * p3 + t^3 * p4
b(t, start, stop) = begin
p_start = Point2f(x1, start)
p_stop = Point2f(x2, stop)
c1 = Point2f(x1 + bend * (x2-x1), start)
c2 = Point2f(x2 - bend * (x2-x1), stop)
bezier(t, p_start, c1, c2, p_stop)
end
using Markdown
Docs.getdoc(s::typeof(scatter)) = plot_func_docs(s)
Docs.getdoc(h::typeof(heatmap)) = plot_func_docs(h)
function plot_func_docs(plotfunc)
T = Combined{plotfunc}
io = IOBuffer()