# Contourf vs contour plotting time in CairoMakie

**URL:** <https://discourse.julialang.org/t/contourf-vs-contour-plotting-time-in-cairomakie/109074>\
**Category:** Visualization\
**Tags:** plotting, makie, cairomakie-plotting, cairomakie\
**Created:** [January 21, 2024, 9:17pm UTC](https://discourse.julialang.org/t/contourf-vs-contour-plotting-time-in-cairomakie/109074 "2024-01-21T21:17:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrew\_burger4](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andrew_burger4/32/206393_2.png) [@andrew\_burger4](https://discourse.julialang.org/u/andrew_burger4)\
**Post date:** [January 21, 2024, 9:17pm UTC](https://discourse.julialang.org/t/contourf-vs-contour-plotting-time-in-cairomakie/109074/1 "2024-01-21T21:17:31Z")

</div>

Hello, if I run the code below with contourf and contour, I see two different times:  
4.5 seconds and 1.5 seconds, respectively. Is this performance hit expected just filling in the contours?

```julia
plotting()
begin
    using CairoMakie
    using LaTeXStrings
    using PlutoUI
end
function plotting()
	x = range(-10,10,step=.01)
	y = range(-10,10,step=.01)
	@time z = circles(x,y)
	@time fig, ax, cf =contour(x, y, z, colormap=:greens, fill=true)
	ax.aspect = 1
	return fig
end
function circles(x_vec, y_vec)
    f(x,y) = x^2 + y^2
    z = [f(x_i, y_i) for x_i in x_vec, y_i in y_vec]
    return z
end

```

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [January 21, 2024, 9:32pm UTC](https://discourse.julialang.org/t/contourf-vs-contour-plotting-time-in-cairomakie/109074/2 "2024-01-21T21:32:39Z")

</div>

Yes contourf has to build polygons out of the contour lines that contour just plots as-is. And those polygons currently always get triangulated, even though CairoMakie doesn’t use the triangulation, only GLMakie needs it. I’m not sure which parts account for what percentage of the additional time, though. One could profile it

---

<div class="post-metadata">

**Author:** ![andrew\_burger4](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andrew_burger4/32/206393_2.png) [@andrew\_burger4](https://discourse.julialang.org/u/andrew_burger4)\
**Post date:** [January 21, 2024, 9:51pm UTC](https://discourse.julialang.org/t/contourf-vs-contour-plotting-time-in-cairomakie/109074/3 "2024-01-21T21:51:51Z")

</div>

interesting, in that case it looks like it may be faster to heatmap, and then plot contours on top?  
I guess that ask the question then of why ever use contourf? Perhaps for categorization and not continuous functions?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [January 21, 2024, 9:53pm UTC](https://discourse.julialang.org/t/contourf-vs-contour-plotting-time-in-cairomakie/109074/4 "2024-01-21T21:53:26Z")

</div>

It looks cleaner than a heatmap I’d say, it doesn’t really have much different information than a heatmap with discrete color map though.
