# Predator-Prey Plot error: no method matching mapslices

**URL:** https://discourse.julialang.org/t/predator-prey-plot-error-no-method-matching-mapslices/85098
**Category:** General Usage
**Tags:** plotting
**Created:** [August 1, 2022, 10:57am UTC](https://discourse.julialang.org/t/predator-prey-plot-error-no-method-matching-mapslices/85098 "2022-08-01T10:57:11Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)
#### Post date: [August 1, 2022, 10:57am UTC](https://discourse.julialang.org/t/predator-prey-plot-error-no-method-matching-mapslices/85098/1 "2022-08-01T10:57:11Z")

</div>

Hi all,

I have this code, Here are what I have done:

1. I change the `linspace` to `range` but then error occurs and I do not know how to solve this:
2. I change the backend from pyplot() to gr()

**MethodError: no method matching mapslices(::typeof(dquiv), ::Matrix{Float64}, ::Int64)**  
**Closest candidates are:**  
\*\* mapslices(::Any, ::AbstractArray; dims) at ~/julia-1.7.3/share/julia/base/abstractarray.jl:2766\*\*

Here is the code:

```julia
using Plots
gr()

"""
Derivatives
prey, predator, growth, comp, conversion, predation, mortality
"""
function ṅ(x, y, r, q, α, β, δ)
   ẋ = r*x - q*x^2 - β*y*x
   ẏ = α*β*y*x - δ*y
   return (ẋ, ẏ)
end

function sim(x, y, r, q, α, β, δ; t::Int64=1000, scal=0.01)
   steps = 0:scal:t
   X = zeros(Float64, size(steps))
   X[1] = x
   Y = zeros(Float64, size(steps))
   Y[1] = x
   for i in eachindex(steps[2:end])
      N = ṅ(X[i], Y[i], r, q, α, β, δ)
      X[i+1] = X[i]+N[1]*scal
      Y[i+1] = Y[i]+N[2]*scal
   end
   return hcat(collect(steps), X, Y)
end

r, q, α, β, δ = 0.4, 0.02, 0.12, 0.1, 0.02
S = sim(1.0, 1.0, r, q, α, β, δ)

xi = range(0, maximum(S[:,2]), 30)
yi = range(0, maximum(S[:,3]), 30)
vxi = repeat(xi, inner=length(yi))
vyi = repeat(yi, outer=length(xi))
N = hcat(vxi, vyi)
function dquiv(X)
   return collect(ṅ(X[1], X[2], r, q, α, β, δ)).*0.35
end
D = mapslices(dquiv, N, 2)
qu = hcat(N, D)
vdn = reshape(abs.(qu[:,3]).+abs.(qu[:,4]), (length(xi), length(yi)))

heatmap(xi, yi, vdn, c=:YlGnBu, xlim=[minimum(xi), maximum(xi)], ylim=[minimum(yi), maximum(yi)], lab="")
quiver!(qu[:,1], qu[:,2], quiver=(qu[:,3], qu[:,4]), c=:grey)
plot!(S[:,2], S[:,3], linewidth=2, c=:black, lab="")
xaxis!("Prey population")
yaxis!("Predator population")

```

---

<div class="post-metadata">

### Author: ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)
#### Post date: [August 1, 2022, 11:01am UTC](https://discourse.julialang.org/t/predator-prey-plot-error-no-method-matching-mapslices/85098/2 "2022-08-01T11:01:21Z")

</div>

`dims` is a keyword argument, not a positional argument (as can be seen by the preceding `;` in the function signature), you want:

```julia
julia> D = mapslices(dquiv, N, dims = 2)
900×2 Matrix{Float64}:
  0.0 0.0
  0.0 -0.00116876
  0.0 -0.00233752
(...)

```

See the docs here:

[https://docs.julialang.org/en/v1/manual/functions/#Keyword-Arguments](https://docs.julialang.org/en/v1/manual/functions/#Keyword-Arguments)
