Skip to content

Instantly share code, notes, and snippets.

Avatar
🔍

Anshul Singhvi asinghvi17

🔍
  • Columbia University
  • New York, NY
View GitHub Profile
@asinghvi17
asinghvi17 / makie_tex_font.jl
Created May 26, 2023 19:22
Replacing the Makie latex rendering font
View makie_tex_font.jl
_stix_fonts = Dict(:regular => "/System/Library/Fonts/Supplemental/STIXTwoMath.otf",#joinpath("NewComputerModern", "NewCMMath-Regular.otf"),
:italic => "/System/Library/Fonts/Supplemental/STIXTwoMath.otf",#joinpath("NewComputerModern", "NewCM10-Italic.otf"),
:bold => "/System/Library/Fonts/Supplemental/STIXTwoMath.otf",#joinpath("NewComputerModern", "NewCM10-Bold.otf"),
:bolditalic => "/System/Library/Fonts/Supplemental/STIXTwoMath.otf",#joinpath("NewComputerModern", "NewCM10-BoldItalic.otf"),
:math => "/System/Library/Fonts/Supplemental/STIXTwoMath.otf"
)
Makie.MathTeXEngine.default_font_families["STIX"] = Makie.MathTeXEngine.FontFamily(
_stix_fonts,
@asinghvi17
asinghvi17 / metal_try.jl
Created May 26, 2023 19:21
A try at using Metal for recurrence analysis on MacOS
View metal_try.jl
using BenchmarkTools, Metal
using Makie, CairoMakie
using RecurrenceAnalysis
function recurrence_kernel!(output_matrix, x1, x2)
x, y = Metal.thread_range()
end
@asinghvi17
asinghvi17 / tyler_ui.jl
Created May 25, 2023 16:19
Computing attractiveness metrics on streets
View tyler_ui.jl
# # 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 / meshimage.jl
Created March 14, 2023 16:47
A way to display images on meshes which are pretransformed in Makie.jl
View meshimage.jl
using Makie: GeometryBasics
using Makie.GeometryBasics: StructArrays
@recipe(MeshImage) do scene
Attributes(
npoints = 100,
space = :data,
)
end
@asinghvi17
asinghvi17 / facet.jl
Created February 28, 2023 10:42
Basic faceting utility for Makie
View facet.jl
# 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 / klein_makie.jl
Last active March 3, 2023 12:45
Visualizing the Klein bottle with Makie.jl
View klein_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 / flipped_axis.jl
Created June 16, 2022 12:54
Flip axis in Makie using PointTrans
View flipped_axis.jl
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 / fitzhugh_nagumo_makielayout.jl
Last active May 10, 2022 19:46
Gist of one of my FHN MakieLayout figures
View fitzhugh_nagumo_makielayout.jl
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 / cobweb.jl
Last active May 7, 2022 14:47
Interactive cobweb plot with Makie
View cobweb.jl
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 / insert_pdf_description.jl
Created May 7, 2022 14:27
PDF metadata writing script for Julia
View insert_pdf_description.jl
# 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")