# How to plot a gridworld policy in Makie

Hey folks. I was looking at a notebook created by the POMDP folks for plotting the Value Iteration policy for a simple Gridworld.

I have a copy of the picture below. I was wondering how would I plot something like this in Makie. From the image it seems like this is a makie plot.

I imagine I would use the `arrows()` function to create the actual arrows, but I was not sure about a couple of things.

1. How would I setup the grid so that there is only one arrow per grid cell?
2. If I add an obstacle to the grid, how do I color only specific grid cells while leaving the others untouched?

Eventually I would like to create a plot similar to this, which comes from one of Russ Tedrakeâ€™s excellent Underactuated Robotics only textbook.

I get that value iteration does not work in more than a few dimensions, so it is not tractable for real world problems. But some of these simple visualizations help to reinforce the intuition behind the algorithms and also debug some code.

Thanks.

For the grid you can just give arrow positions consistent with the cells? And for obstacles, you can change the cell value to a specific â€śobstacleâ€ť value? (or draw on top of the grid with another plot call). For example:

``````using CairoMakie

x = 0:20
y = 0:15
z = @. (x-2)^2 + (y'-8)^2
d = rand([(0,0.5), (0,-0.5), (0.5,0), (-0.5,0)], size(z))

z[3:4, 2:8] .= -100

fig = Figure()
ax = Axis(fig[1,1], xticks=x, yticks=y)
heatmap!(x, y, z)
arrows!(x, y, first.(d), last.(d))
fig
``````

1 Like

You can use `NaN` and `nan_color` for a border object:

``````using CairoMakie

x = 0:20
y = 0:15
z = @. (x-2)^2 + (y'-8)^2 |> Float32
d = rand([(0,0.5), (0,-0.5), (0.5,0), (-0.5,0)], size(z))