# Plot points in grid

**URL:** <https://discourse.julialang.org/t/plot-points-in-grid/75463>\
**Category:** New to Julia\
**Tags:** question, plotting, mesh\
**Created:** [January 30, 2022, 11:30am UTC](https://discourse.julialang.org/t/plot-points-in-grid/75463 "2022-01-30T11:30:06Z")\
**Posts on this page:** 4\
**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:** [January 30, 2022, 11:30am UTC](https://discourse.julialang.org/t/plot-points-in-grid/75463/1 "2022-01-30T11:30:07Z")

</div>

Hi I have a grid of 100 elements that contain only three values 1 or 2 or 3 for each element.  
MyGrid = fill(1, (10, 10));  
MyGrid [rand(1:100)] = 2;

I want to plot this grid as points. Each point will take different color based on its value  
for example point that has 1 colored with red  
point that has 2 colored with green  
point that has 3 colored with black

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [January 30, 2022, 12:14pm UTC](https://discourse.julialang.org/t/plot-points-in-grid/75463/2 "2022-01-30T12:14:05Z")

</div>

Take a look at [MeshViz.jl](https://github.com/JuliaGeometry/MeshViz.jl), I understand you want to plot the centers of cells in a grid with colors?

```julia
using Meshes
using MeshViz

# choose Makie backend
import GLMakie as Mke

grid = CartesianGrid(10, 10)
vals = rand(1:3, 10, 10)

# visualize grid
viz(grid, color=vec(vals))

# visualize centroids
viz(centroid.(grid), color=vec(vals))

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/f/6/f67171e537cfddd385bdd206d9a6f838cd79bb4d.png)  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/7/2/72be91a28987d75afae5d9c7b9d1d424ecf1d93f.png)

---

<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:** [January 30, 2022, 12:33pm UTC](https://discourse.julialang.org/t/plot-points-in-grid/75463/3 "2022-01-30T12:33:02Z")

</div>

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

something like that

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [January 30, 2022, 1:38pm UTC](https://discourse.julialang.org/t/plot-points-in-grid/75463/4 "2022-01-30T13:38:04Z")

</div>

Updated the answer based on your reply.
