# Number contours in PlotlyJS.contour

**URL:** <https://discourse.julialang.org/t/number-contours-in-plotlyjs-contour/122360>\
**Category:** General Usage\
**Tags:** plotlyjs, contouring\
**Created:** [November 6, 2024, 10:59pm UTC](https://discourse.julialang.org/t/number-contours-in-plotlyjs-contour/122360 "2024-11-06T22:59:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![miguelborrero](https://avatars.discourse-cdn.com/v4/letter/m/eb9ed0/32.png) [@miguelborrero](https://discourse.julialang.org/u/miguelborrero)\
**Post date:** [November 6, 2024, 10:59pm UTC](https://discourse.julialang.org/t/number-contours-in-plotlyjs-contour/122360/1 "2024-11-06T22:59:44Z")

</div>

Hi there, I would like to produce a contour plot of a quadratic function and I found a nice way to do so with `PlotlyJS.contour` but I am not able to customize the number of contours. It seems like the documentation gives a clear way to do so but it is not working for me. Can someone help out please?

```julia
Q(θ; ω = 2.0) = (ω * θ[1] + θ[2])^2 + θ[1]^2
θ_grid = -3.0:0.01:3.0
objective_values = Array{Float64}(undef, length(θ_grid), length(θ_grid))
for (i, x) in pairs(θ_grid)
    for (j, y) in pairs(θ_grid)
        objective_values[i, j] = Q([x, y])
    end
end
contour_plot = PlotlyJS.plot(PlotlyJS.contour(x = θ_grid, y = θ_grid, z = objective_values, autocontour = false,
                                                contours=attr(
                                                    size = 2,
                                                    showlabels = true, # show labels on contours
                                                    labelfont = attr( # label font properties
                                                        size = 12,
                                                        color = "white",
                                                    )
                                                )
                                            )
)

```

In particular, my understanding is that by setting `autocontour = false`, I can determine the size of the contours inside `contours()` through size but chaging this is producing the same graph.

Thanks a lot in advance!

---

<div class="post-metadata">

**Author:** ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)\
**Post date:** [November 7, 2024, 12:20am UTC](https://discourse.julialang.org/t/number-contours-in-plotlyjs-contour/122360/2 "2024-11-07T00:20:23Z")

</div>

Hi Miguel,

The keyword `ncontours` is probably what you want.  
See this page:

> **[Contour](https://plotly.com/julia/reference/contour/#contour-ncontours)**
>
> Figure

For example,

```julia
using PlotlyJS
Q(θ; ω = 2.0) = (ω * θ[1] + θ[2])^2 + θ[1]^2
θ_grid = -3.0:0.01:3.0
objective_values = Q.(Base.Iterators.product(θ_grid,θ_grid));

contour_plot = PlotlyJS.plot(
    PlotlyJS.contour(x = θ_grid, y = θ_grid, z = objective_values,
                    autocontour = false,
                    ncontours=50, #<-- Updated!
                    contours=attr(
                        size = 2,
                        showlabels = true, # show labels on contours
                        labelfont = attr( # label font properties
                            size = 12,
                            color = "white",
                        )
                    )
                )
)

```

 ![n-contours](https://global.discourse-cdn.com/julialang/original/3X/0/b/0bf32730e5f740548f1b7706a26ab0dc219133b2.png)

---

<div class="post-metadata">

**Author:** ![miguelborrero](https://avatars.discourse-cdn.com/v4/letter/m/eb9ed0/32.png) [@miguelborrero](https://discourse.julialang.org/u/miguelborrero)\
**Post date:** [November 7, 2024, 12:28am UTC](https://discourse.julialang.org/t/number-contours-in-plotlyjs-contour/122360/3 "2024-11-07T00:28:21Z")

</div>

Fantastic, thanks!
