Skip to content

Instantly share code, notes, and snippets.

View asinghvi17's full-sized avatar
🔍

Anshul Singhvi asinghvi17

🔍
  • Columbia University
  • New York, NY
View GitHub Profile
@asinghvi17
asinghvi17 / position_popup.jl
Created August 6, 2020 00:46
Makie position popup along multiple axes
using Makie
using Makie.AbstractPlotting.MakieLayout
function position_popup!(
scene, axes;
formatter = (point::Point2f0) -> string(round.(Float64.(point), digits = 3)),
)
visible = Observable(false)
@asinghvi17
asinghvi17 / insert_pdf_description.jl
Created May 7, 2022 14:27
PDF metadata writing script for Julia
# Author: Anshul Singhvi
# Works as of 20220507
# Basically, the function is used to edit the metadata of a PDF using Ghostscript
# This could be made pure-Julian with the right logic (searching for keywords, etc.)
# but that is annoying to do.
using Ghostscript_jll
const AUTHOR = Ref{String}("Anshul Singhvi")
@asinghvi17
asinghvi17 / cobweb.jl
Last active May 7, 2022 14:47
Interactive cobweb plot with Makie
using Makie, GLMakie
f(x::Real, r::Real) = r * x * (1 - x)
function cobweb(
xᵢ::Real,
curve_f::Function,
r::Real;
nstep::Real = 30
)::Vector{Point2f} # col 1 is x, col 2 is y
@asinghvi17
asinghvi17 / fitzhugh_nagumo_makielayout.jl
Last active May 10, 2022 19:46
Gist of one of my FHN MakieLayout figures
using Makie, MakieTeX, CairoMakie
# Makie v0.17 and associated packages
using DifferentialEquations, Polynomials
# define the default theme
Makie.set_theme!(Theme(
font = "CMU Serif",
fontsize = 12, # 12,
Axis = (
@asinghvi17
asinghvi17 / flipped_axis.jl
Created June 16, 2022 12:54
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}
@asinghvi17
asinghvi17 / klein_makie.jl
Last active March 3, 2023 12:45
Visualizing the Klein bottle with Makie.jl
using Makie, WGLMakie
# implementation from the PGFPlots example gallery, at https://pgfplots.net/klein-bottle/
klein(u, v) = Point3f((-2/15 * cos(u) * (
3*cos(v) - 30*sin(u)
+ 90 *cos(u)^4 * sin(u)
- 60 *cos(u)^6 * sin(u)
+ 5 * cos(u)*cos(v) * sin(u))
),
(-1/15 * sin(u) * (3*cos(v)
@asinghvi17
asinghvi17 / facet.jl
Created February 28, 2023 10:42
Basic faceting utility for Makie
# auto facet for makie
# Taken from Plots.jl
function compute_gridsize(numplts::Int; landscape = false, nr = -1, nc = -1)
# figure out how many rows/columns we need
if nr < 1
if nc < 1
nr = round(Int, sqrt(numplts))
nc = ceil(Int, numplts / nr)
else
@asinghvi17
asinghvi17 / meshimage.jl
Created March 14, 2023 16:47
A way to display images on meshes which are pretransformed in Makie.jl
using Makie: GeometryBasics
using Makie.GeometryBasics: StructArrays
@recipe(MeshImage) do scene
Attributes(
npoints = 100,
space = :data,
)
end
@asinghvi17
asinghvi17 / tyler_ui.jl
Created May 25, 2023 16:19
Computing attractiveness metrics on streets
# # A GUI to display location "attractiveness"
# The following code creates a GUI which allows you to inspect
# a map of Toronto, and see the attractiveness of different locations
# based on different nearness measures.
# First, we load the necessary packages.
# We will build our GUI with the `Makie` toolchain, consisting of `Makie`, `[W]GLMakie`, and `Tyler` for map tile visualization.
# Data is from OpenStreetMap and is parsed using `OpenStreetMapX`. Attractiveness scores are obtained using `OSMToolset`.
@asinghvi17
asinghvi17 / metal_try.jl
Created May 26, 2023 19:21
A try at using Metal for recurrence analysis on MacOS
using BenchmarkTools, Metal
using Makie, CairoMakie
using RecurrenceAnalysis
function recurrence_kernel!(output_matrix, x1, x2)
x, y = Metal.thread_range()
end