# Makie.jl: Plotting contour with fillrange=true above lines

**URL:** <https://discourse.julialang.org/t/makie-jl-plotting-contour-with-fillrange-true-above-lines/39830>\
**Category:** New to Julia\
**Tags:** package, plotting\
**Created:** [May 20, 2020, 1:43pm UTC](https://discourse.julialang.org/t/makie-jl-plotting-contour-with-fillrange-true-above-lines/39830 "2020-05-20T13:43:25Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [May 20, 2020, 10:24pm UTC](https://discourse.julialang.org/t/makie-jl-plotting-contour-with-fillrange-true-above-lines/39830/6 "2020-05-20T22:24:10Z")

</div>

![image](https://global.discourse-cdn.com/julialang/original/3X/3/2/320044b0db30cb31d949fe82f12ffcaabe95973b.jpeg)

Not as easily… I think @jules did some work on this?

I just did a super dirty hack for a simple version:

```julia
using AbstractPlotting, GLMakie

np = 500
nc = 200
f(x) = 2*x+1
x = LinRange(-1,1,f(np))
y = rand(f(np))*2 .- 1
scene = Scene()
x_c = LinRange(-nc/np,nc/np,f(nc))
y_c = LinRange(-nc/np,nc/np,f(nc))
c_mat = @. x_c^2 + y_c'^2
lineplot = lines!(scene, x, y)[end]
translate!(lineplot, 0, 0, -1)
heatmap!(scene,x_c,y_c,c_mat)
cplot = contour!(scene,x_c,y_c,c_mat, linewidth=2, color=:white)[end]

beginnings = Point2f0[]; colors = RGBAf0[]
# First plot in contour is the line plot, first arguments are the points of the contour
segments = cplot.plots[1][1][]
for (i, p) in enumerate(segments)
    # the segments are separated by NaN, which signals that a new contour starts
    if isnan(p)
        push!(beginnings, segments[i-1])
    end
end
sc = scatter!(scene, beginnings, markersize=0.06, color=(:white, 0.00001))[end]
translate!(sc, 0, 0, 1)
# Reshuffle the plot order, so that the scatter plot gets drawn before the line plot
delete!(scene, sc)
delete!(scene, cplot)
push!(scene, sc)
push!(scene, cplot)
anno = annotations!(scene, [(string(i), p) for (i, p) in enumerate(beginnings)], 
                    textsize=0.05, align=(:center, :center))[end]
                    
# move, so that text is in front
translate!(anno, 0, 0, 2)

scene

```

Would need some polish to work nicely 😉 (e.g. simply split the contour lines to make a gap, and finding better positions for the numbers)

 ![image](https://global.discourse-cdn.com/julialang/original/3X/7/d/7d89aab18848889cdcec24461b8e69ad84b48972.png)

---

_[View the full topic](https://discourse.julialang.org/t/makie-jl-plotting-contour-with-fillrange-true-above-lines/39830)._
