-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #84 from shnarazk/julia-visualization-20250105
Visualization with Julia
- Loading branch information
Showing
5 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# shellcheck shell=bash | ||
source $HOME/.config/direnv/envrc | ||
use flake |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
description = "A basic flake with a shell"; | ||
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; | ||
inputs.flake-utils.url = "github:numtide/flake-utils"; | ||
|
||
outputs = { self, nixpkgs, flake-utils }: | ||
flake-utils.lib.eachDefaultSystem (system: let | ||
pkgs = nixpkgs.legacyPackages.${system}; | ||
in { | ||
devShells.default = pkgs.mkShell { | ||
packages = [ | ||
pkgs.bashInteractive | ||
pkgs.graphviz | ||
pkgs.julia-bin | ||
]; | ||
}; | ||
}); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env julia | ||
import Pkg | ||
# Pkg.add("JSON"), | ||
# Pkg.add("Plots"), | ||
# Pkg.add("GridVisualize"), | ||
# Pkg.add("Colors"), | ||
using JSON, Plots, Colors | ||
|
||
grid_data = JSON.parse(read("2024/day18.json", String))["line"] | ||
|
||
# Extract dimensions of the grid | ||
rows = 1 + maximum([g[1] for g in grid_data]) | ||
cols = 1 + maximum([g[2] for g in grid_data]) | ||
len = length(grid_data) | ||
|
||
# Create an empty matrix for plotting purposes | ||
grid_matrix = fill(RGB(1.0, 1.0, 1.0), rows, cols) | ||
for (i, g) in enumerate(grid_data) | ||
c = (len - i) / len | ||
grid_matrix[g[1]+1, g[2]+1] = RGB(c, c, c) | ||
end | ||
grid_matrix[1, 1] = RGB(1.0, 0.0, 0.0) | ||
|
||
# color_map = Dict( | ||
# :red => RGB(1.0, 0.0, 0.0), | ||
# :white => RGB(1.0, 1.0, 1.0), | ||
# :black => RGB(0.0, 0.0, 0.0), | ||
# ) | ||
# color_matrix = [color_map[element] for element in grid_matrix] | ||
|
||
heatmap( | ||
# color_matrix, | ||
grid_matrix, | ||
title="Y2024 day18", | ||
aspect_ratio=:equal | ||
) | ||
savefig("day18-grid.png") |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env julia | ||
# import Pkg | ||
# Pkg.add("JSON") | ||
# Pkg.add("Plots") | ||
# Pkg.add("KernelDensity") | ||
using JSON, Plots, KernelDensity | ||
|
||
data2024 = read("2024/execution_time.json", String) | ||
data = JSON.parse(data2024) | ||
times = [item["time"] for item in data if haskey(item, "time")] | ||
tl = log2.(times) | ||
ktd = kde(tl) | ||
|
||
histogram( | ||
tl, | ||
xlims=(-5, 20), | ||
ylims=(0, 0.4), | ||
bins=20, | ||
normalize=true, | ||
title="AoC2024 execution time distribution in Rust", | ||
xlabel="log2(time[ms])", | ||
# xlabel="時間", | ||
ylabel="Freq", | ||
legend=false, | ||
# fontfamily="Noto Sans CJK JP" | ||
) | ||
plot!( | ||
ktd.x, | ||
ktd.density, | ||
ylims=(0, 0.4), | ||
color=:red, | ||
linewidth=2) | ||
|
||
savefig("hist2024.png") |