This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| f = Figure() | |
| ax = Axis(f[1, 1]) | |
| ls = map(0:3) do i | |
| lines!(ax, 1:10, (1:10) .* i) | |
| end | |
| for (i, l) in zip(0:3, ls) | |
| Legend(f[1, 2], [l], ["$i"], framevisible = false, padding = (0, 0, 0, 0), | |
| valign = i / 3) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function struct_reinterpret(::Type{T}, x)::T where T | |
| ref = Base.RefValue(x) | |
| GC.@preserve ref unsafe_load(Ptr{T}(pointer_from_objref(ref))) | |
| end | |
| struct TaggedUnion | |
| type::UInt8 | |
| bytes::NTuple{8, UInt8} # would be the max size of all types used, determined automatically | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using Pkg | |
| pkg"activate @portaudio" | |
| using PortAudio.LibPortAudio | |
| mutable struct Audio | |
| ptr::Ptr{Float32} | |
| buffer::Vector{Float32} # vector reference so no problems with garbage collection | |
| len::Int |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using CairoMakie | |
| ## | |
| s = Scene(resolution = (500, 500), camera = campixel!, show_axis = false) | |
| o = Point2f(250, 250) | |
| n = 5 | |
| linewidth = 10 | |
| center_offset = 0 | |
| rotation_gain = 1.5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function bracketlabel!(ax, label, mi, ma, axoffset, bracketwidth, labeloffset) | |
| bracketpoints = lift(ax.finallimits, ax.scene.px_area) do lims, px_area | |
| x = minimum(lims)[1] | |
| pmin = Makie.project(ax.scene, Point2f(x, mi)) | |
| pmax = Makie.project(ax.scene, Point2f(x, ma)) | |
| ps = Point2f[ | |
| pmin, | |
| pmin - Point2f(bracketwidth, 0), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| task_starts = [0, 3, 5, 10] | |
| task_ends = [3, 6, 9, 12] | |
| task_positions = [1, 2, 1, 2] | |
| barplot(task_positions, task_ends, fillto = task_starts, | |
| direction = :x) | |
| text!("task " .* string.(1:4), | |
| position = Point2f0.( | |
| (task_starts .+ task_ends) ./ 2, | |
| task_positions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| f = Figure() | |
| nrows, ncols = (3, 7) | |
| real_axes = map(Iterators.product(1:nrows, 1:ncols)) do (i, j) | |
| ax = Axis(f[2i, j]) | |
| if i < nrows | |
| hidexdecorations!(ax, grid = false) | |
| end | |
| if 1 < j < ncols |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| f = Figure() | |
| [Axis(f[i, j], width = 300, height = 250) for i in 1:3, j in 1:3] | |
| sz = ceil.(Int, GridLayoutBase.determinedirsize.( | |
| Ref(f.layout), | |
| (GridLayoutBase.Col(), GridLayoutBase.Row()))) | |
| resize!(f.scene, sz) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @recipe(Stairs) do scene | |
| a = Attributes( | |
| step = :pre, # :center :post | |
| ) | |
| merge(a, AbstractPlotting.default_theme(scene, Lines)) | |
| end | |
| AbstractPlotting.conversion_trait(x::Type{<: Stairs}) = AbstractPlotting.PointBased() | |
| function AbstractPlotting.plot!(p::Stairs{<:Tuple{<:AbstractVector{<:Point2}}}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct IntegerTicks end | |
| MakieLayout.get_tickvalues(::IntegerTicks, vmin, vmax) = ceil(Int, vmin) : floor(Int, vmax) | |
| lines(0.01:0.001:0.99, axis = (yscale = log10, yticks = LogTicks(IntegerTicks()))) |