# How to convert long form data frame for contour plot

**URL:** <https://discourse.julialang.org/t/how-to-convert-long-form-data-frame-for-contour-plot/135937>\
**Category:** General Usage\
**Tags:** plotting, dataframes\
**Created:** [March 1, 2026, 10:45am UTC](https://discourse.julialang.org/t/how-to-convert-long-form-data-frame-for-contour-plot/135937 "2026-03-01T10:45:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Post date:** [March 1, 2026, 10:45am UTC](https://discourse.julialang.org/t/how-to-convert-long-form-data-frame-for-contour-plot/135937/1 "2026-03-01T10:45:41Z")

</div>

Hello,

As shown in the MWE below, I have a data frame with three variables in long form and would like to plot it as a contour plot. There are two issues. First, the variables x and y span a triangular area rather than a rectangular area. Second, the function `contour` requires x and y to be vectors and z to be a matrix. Unfortunately, `contour` does not handle [data in long form](https://github.com/JuliaPlots/Plots.jl/issues/5493).

What is the best way to handle these issues?

```julia-auto
using DataFrames
using Plots 

df = DataFrame(x = Float64[], y = Float64[], z = Float64[])
vals = .01:.01:.99
for x ∈ vals, y ∈ vals
    if x + y ≤ 1 
        push!(df, [x y x * y])
    end
end

```

---

<div class="post-metadata">

**Author:** ![ForceBru](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/forcebru/32/21389_2.png) [@ForceBru](https://discourse.julialang.org/u/ForceBru)\
**Post date:** [March 1, 2026, 11:58am UTC](https://discourse.julialang.org/t/how-to-convert-long-form-data-frame-for-contour-plot/135937/2 "2026-03-01T11:58:15Z")

</div>

I usually use `tricontourf` in such cases: [tricontourf | Makie](https://docs.makie.org/dev/reference/plots/tricontourf). IMO it really is frustrating that it’s not possible to simply use `contourf` with flat vectors x \in \mathbb R^n, y \in \mathbb R^n and z \in \mathbb R^n, where z\_i = f(x\_i, y\_i)\;\forall i.

---

<div class="post-metadata">

**Author:** ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Post date:** [March 1, 2026, 2:25pm UTC](https://discourse.julialang.org/t/how-to-convert-long-form-data-frame-for-contour-plot/135937/3 "2026-03-01T14:25:58Z")

</div>

Thank you. I agree that its frustrating this cannot be easily achieved in Plots.jl, but CairoMakie is a good solution. Thanks again.
