# Divide plot into boxes

**URL:** <https://discourse.julialang.org/t/divide-plot-into-boxes/85715>\
**Category:** New to Julia\
**Tags:** plotting\
**Created:** [August 13, 2022, 7:02pm UTC](https://discourse.julialang.org/t/divide-plot-into-boxes/85715 "2022-08-13T19:02:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mahmoud](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@Mahmoud](https://discourse.julialang.org/u/Mahmoud)\
**Post date:** [August 13, 2022, 7:02pm UTC](https://discourse.julialang.org/t/divide-plot-into-boxes/85715/1 "2022-08-13T19:02:49Z")

</div>

I use this code to distribute points over a grid in the first photo

```julia
Npopulations = 10000
Person = [Dict("x" => 0,"y" => 0,"color" => "white","timecounter" => 0) for i ∈ 1:Npopulations]
 yincrement = 0
    for ipop in 2:Npopulations 
        Person[ipop]["x"] = Person[ipop-1]["x"] + gapstep 
        Person[ipop]["y"] += yincrement
        if (Person[ipop]["x"] + gapstep > Lgrid)
            Person[ipop]["x"] = 0
            yincrement += gapstep
            Person[ipop]["y"] = yincrement
        end            
    end

```

![anim_fps1001](https://global.discourse-cdn.com/julialang/original/3X/c/9/c961b46605ba78cc35c23dfa28e7e372eb0f65a8.gif)  
My question is how to distribute them like this hand written photo with lines between or in boxes ?

 ![discourse](https://global.discourse-cdn.com/julialang/original/3X/e/d/ed129c8efd6e08ddbc1733225edeb08f6840f990.png)

---

<div class="post-metadata">

**Author:** ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Post date:** [August 14, 2022, 11:56am UTC](https://discourse.julialang.org/t/divide-plot-into-boxes/85715/2 "2022-08-14T11:56:52Z")

</div>

There are probably more elegant approachers, but this should get you started. You will need to replace the random values with your own values.

```julia
using Plots, Random 
Random.seed!(5474)

n_lines = 2
min_x = 0
max_x = 10
min_y = 0
max_y = 10
mid_point = (2 + n_lines) / 2 + 1
padding = 1

xvals = range(min_x, max_x, length = n_lines + 2)
yvals = range(min_y, max_y, length = n_lines + 2)

p = plot(framestyle=:box, grid=false, 
    xlims=(min_x,max_x), ylims=(min_y,max_y))
for r in 2:length(xvals), c in 2:length(yvals)
    rnd_x = rand(5) * (xvals[c] .- xvals[c-1] .- 2 * padding) .+ xvals[c-1] .+ padding
    rnd_y = rand(5) * (yvals[r] .- yvals[r-1] .- 2 * padding) .+ yvals[r-1] .+ padding
    color = (r == mid_point) && (c == mid_point) ? :black : :red
    scatter!(rnd_x, rnd_y, leg=false, markerstrokecolor=color, 
        markercolor=:white, markerstrokewidth=4)
    c ≠ length(xvals) ? hline!([xvals[c]], color=:red) : nothing
    r ≠ length(xvals) ? vline!([yvals[r]], color=:red) : nothing
end
display(p)
savefig("example.png")

```

![example](https://global.discourse-cdn.com/julialang/original/3X/3/8/3889b7fac2578a9444242575b05ee3f0bf518b0f.png)
