# Different behaviour of contour in Plots and GLMakie

**URL:** <https://discourse.julialang.org/t/different-behaviour-of-contour-in-plots-and-glmakie/126247>\
**Category:** Visualization\
**Tags:** plotting\
**Created:** [February 24, 2025, 3:06pm UTC](https://discourse.julialang.org/t/different-behaviour-of-contour-in-plots-and-glmakie/126247 "2025-02-24T15:06:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vtfanta](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vtfanta/32/48144_2.png) [@vtfanta](https://discourse.julialang.org/u/vtfanta)\
**Post date:** [February 24, 2025, 3:06pm UTC](https://discourse.julialang.org/t/different-behaviour-of-contour-in-plots-and-glmakie/126247/1 "2025-02-24T15:06:59Z")

</div>

When plotting a contour plot of a quadratic, behaviour is different for Plots and Makie, while Makie is correct. The motivation is to show an iteration of the Newton method.

> **MWE**
>
> ```julia
> using Plots, GLMakie
> using LinearAlgebra
> 
> x1_grid = -1:0.02:1
> x2_grid = -1:0.02:1
> xk = [0.7, 0.5]
> 
> f(x) = (x[1]+1)^4 + x[1]*x[2] + (x[2]+1)^4
> ∇f(x) = [4(x[1]+1)^3+x[2], x[1]+4(x[2]+1)^3]
> ∇²f(x) = [12(x[1]+1)^2 1;1 12(x[2]+1)^2]
> m(x) = f(xk)+dot(∇f(xk),x-xk) + 1/2*dot(x-xk, ∇²f(xk), x-xk)
> x_kp1 = xk - ∇²f(xk) \ ∇f(xk)
> 
> m_grid = [m([x1, x2]) for x1=x1_grid, x2=x2_grid]
> 
> Plots.contour(x1_grid, x2_grid, m_grid)
> Plots.scatter!([x_kp1[1]], [x_kp1[2]])
> 
> fig = Figure()
> Axis(fig[1,1])
> GLMakie.contour(x1_grid, x2_grid, m_grid)
> GLMakie.scatter!([x_kp1[1]], [x_kp1[2]])
> 
> ```

Makie correctly shows the minimizer in the center of the ellipses while the Plots package is off. Am I doing something wrong?

 ![Screenshot from 2025-02-24 15-39-55](https://global.discourse-cdn.com/julialang/original/3X/4/e/4efe683d48da5dc120d33c9243bcec9af1435169.png)

---

<div class="post-metadata">

**Author:** ![jheinen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jheinen/32/2787_2.png) [@jheinen](https://discourse.julialang.org/u/jheinen)\
**Post date:** [February 24, 2025, 5:02pm UTC](https://discourse.julialang.org/t/different-behaviour-of-contour-in-plots-and-glmakie/126247/2 "2025-02-24T17:02:51Z")

</div>

For `Plots` you will have to switch the coordinates:

`Plots.scatter!([x_kp1[2]], [x_kp1[1]])`

---

<div class="post-metadata">

**Author:** ![vtfanta](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vtfanta/32/48144_2.png) [@vtfanta](https://discourse.julialang.org/u/vtfanta)\
**Post date:** [February 24, 2025, 5:18pm UTC](https://discourse.julialang.org/t/different-behaviour-of-contour-in-plots-and-glmakie/126247/3 "2025-02-24T17:18:41Z")

</div>

I know I can do that, but the plot is still wrong. The function has optimum at `$≈(0.13, 0.0)` and not on the y-axis. The question is, why does `Plots` do this?

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [February 24, 2025, 6:45pm UTC](https://discourse.julialang.org/t/different-behaviour-of-contour-in-plots-and-glmakie/126247/4 "2025-02-24T18:45:10Z")

</div>

When plotting grids or matrices in Plots.jl, you should feed the transpose, i.e.: `m_grid'`

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [February 24, 2025, 7:51pm UTC](https://discourse.julialang.org/t/different-behaviour-of-contour-in-plots-and-glmakie/126247/5 "2025-02-24T19:51:39Z")

</div>

Link to a recent [related thread](https://discourse.julialang.org/t/wrong-heatmap-orientation-with-plots-jl/124822) on the orientation of heatmaps.
