logo

First Steps in Lattice Model Simulation: Representing with Heatmaps 📂Dynamics

First Steps in Lattice Model Simulation: Representing with Heatmaps

Simulation

Code Review

Step 1. Creating a Lattice Space

julia> colormap\_SI = [colorant"#EEEEEE", colorant"#111111"]

julia> row\_size = 5
5

julia> column\_size = 5
5

julia> Random.seed!(3);

julia> stage\_lattice = rand(['S'], row\_size, column\_size)
5×5 Array{Char,2}:
 'S'  'S'  'S'  'S'  'S'
 'S'  'S'  'S'  'S'  'S'
 'S'  'S'  'S'  'S'  'S'
 'S'  'S'  'S'  'S'  'S'
 'S'  'S'  'S'  'S'  'S'

The code above creates an empty lattice space of size $5 \times 5$ and fills two random positions. Empty spaces are denoted by the letter 'S', and filled spaces are represented by 'I'.

Step 2. Plotting with a Heatmap

stage\_lattice[rand(1:row\_size), rand(1:column\_size)] = 'I'; stage\_lattice
figure = heatmap(reverse(stage\_lattice,dims=1), color=colormap\_SI,
  xaxis=false,yaxis=false,axis=nothing, size = [400,400], legend = false)
png(figure, "lattice\_tutorial.png"); figure

Executing the above code generates the following image file. As seen in Step 1., the 2 rows and 3 columns of 'I' are painted in black.

lattice_tutorial.png

Complete Code

Below is the Julia code used in this post.

cd(@__DIR__) # 파일 저장 경로

@time using Plots
@time using Random

colormap_SI = [colorant"#EEEEEE", colorant"#111111"]
row_size = 5
column_size = 5
Random.seed!(3);

stage_lattice = rand(['S'], row_size, row_size)
stage_lattice[rand(1:row_size), rand(1:column_size)] = 'I'; stage_lattice
figure = heatmap(reverse(stage_lattice,dims=1), color=colormap_SI,
  xaxis=false,yaxis=false,axis=nothing, size = [400,400], legend = false)
png(figure, "lattice_tutorial.png"); figure