# How to plot quiver plot over heatmap

**URL:** https://discourse.julialang.org/t/how-to-plot-quiver-plot-over-heatmap/66000
**Category:** General Usage
**Tags:** plotting, plots
**Created:** [August 7, 2021, 9:58pm UTC](https://discourse.julialang.org/t/how-to-plot-quiver-plot-over-heatmap/66000 "2021-08-07T21:58:53Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![genkuroki](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/genkuroki/32/18030_2.png) [@genkuroki](https://discourse.julialang.org/u/genkuroki)
#### Post date: [August 11, 2021, 1:27pm UTC](https://discourse.julialang.org/t/how-to-plot-quiver-plot-over-heatmap/66000/2 "2021-08-11T13:27:02Z")

</div>

Plots.jl examples

Example 1:

```julia
using ForwardDiff
using Plots

f(x, y) = exp(-(x^2 + y^2))
u(x, y) = ForwardDiff.derivative(Base.Fix2(f, y), x) # = f_x(x, y)
v(x, y) = ForwardDiff.derivative(Base.Fix1(f, x), y) # = f_y(x, y)

xlim = (-1.7, 1.7)
ylim = (-1.7, 1.7)
xs = range(xlim...; length=200)
ys = range(ylim...; length=200)

c = 0.5
x = range(-1.5, 1.5; length=11)
y = range(-1.5, 1.5; length=11)
X, Y = reim(complex.(x', y)) # meshgrid
U, V = c*u.(x', y), c*v.(x', y)

heatmap(xs, ys, f)
quiver!(vec(X-U/2), vec(Y-V/2); quiver=(vec(U), vec(V)), color=:cyan)
plot!(; xlim, ylim, size=(450, 400))

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/5/7/57623025c009cdfdb484aaa7a69c6710ed0fdb90.jpeg)

Example2:

```julia
using ForwardDiff
using Plots

f(x, y) = y * exp(-(x^2 + y^2))
u(x, y) = -ForwardDiff.derivative(Base.Fix2(f, y), x) # = f_x(x, y)
v(x, y) = -ForwardDiff.derivative(Base.Fix1(f, x), y) # = f_y(x, y)

xlim = (-2.2, 2.2)
ylim = (-2.2, 2.2)
xs = range(xlim...; length=200)
ys = range(ylim...; length=200)

c = 0.5
x = range(-2.0, 2.0; length=13)
y = range(-2.0, 2.0; length=13)
X, Y = reim(complex.(x', y)) # meshgrid
U, V = c*u.(x', y), c*v.(x', y)

heatmap(xs, ys, f)
quiver!(vec(X-U/2), vec(Y-V/2); quiver=(vec(U), vec(V)), color=:cyan)
plot!(; xlim, ylim, size=(450, 400))

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/e/f/ef483350899aabab8af5683f856e3bb350724293.jpeg)

---

_[View the full topic](https://discourse.julialang.org/t/how-to-plot-quiver-plot-over-heatmap/66000)._
