# Filled contour plots in Plots.jl without contour lines and smooth interpolation (GR backend)

**URL:** <https://discourse.julialang.org/t/filled-contour-plots-in-plots-jl-without-contour-lines-and-smooth-interpolation-gr-backend/34796>\
**Category:** Visualization\
**Tags:** plots, gr\
**Created:** [February 18, 2020, 8:06am UTC](https://discourse.julialang.org/t/filled-contour-plots-in-plots-jl-without-contour-lines-and-smooth-interpolation-gr-backend/34796 "2020-02-18T08:06:33Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![sloede](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sloede/32/44787_2.png) [@sloede](https://discourse.julialang.org/u/sloede)\
**Post date:** [February 18, 2020, 8:06am UTC](https://discourse.julialang.org/t/filled-contour-plots-in-plots-jl-without-contour-lines-and-smooth-interpolation-gr-backend/34796/1 "2020-02-18T08:06:34Z")

</div>

Actually, these are two questions towards Plots.jl with the GR backend in one post (hope that’s ok, I think they are related):

1. Is it possible to create a filled contour plot (using `plot(linetype=:contourf, ...`) without actually showing the contour lines?

2. And is it possible to obtain smoothly interpolated colors instead of discrete levels, without resorting to setting `levels` to a ridiculously high value?

**EDIT:** I would like to generate an image as shown in [Color and width problems for contour line plots in plotly · Issue #1218 · JuliaPlots/Plots.jl · GitHub](https://github.com/JuliaPlots/Plots.jl/issues/1218#issuecomment-341054026), where it was reported as a bug (or as I would call it: a feature)

---

<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 18, 2020, 9:14am UTC](https://discourse.julialang.org/t/filled-contour-plots-in-plots-jl-without-contour-lines-and-smooth-interpolation-gr-backend/34796/2 "2020-02-18T09:14:02Z")

</div>

Isn’t this the functionality of a `heatmap`?

```julia
using GR
z = peaks(200)
contourf(z)
heatmap(z)

```

 ![Screen Shot 2020-02-18 at 10.11.29](https://global.discourse-cdn.com/julialang/original/3X/6/c/6cd724ca30b627bbab29745cfea6dfc032d05682.png) ![heatmao](https://global.discourse-cdn.com/julialang/original/3X/c/8/c8d05da6c01c3d40dbe8fc6a21e15e4765562239.png)

---

<div class="post-metadata">

**Author:** ![sloede](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sloede/32/44787_2.png) [@sloede](https://discourse.julialang.org/u/sloede)\
**Post date:** [February 18, 2020, 9:49am UTC](https://discourse.julialang.org/t/filled-contour-plots-in-plots-jl-without-contour-lines-and-smooth-interpolation-gr-backend/34796/3 "2020-02-18T09:49:07Z")

</div>

This is very embarrassing… but of course you are right 🤦‍♂️ Thanks a lot for the fast reply.

However, please allow me a follow-up question:

With `contourf!` it is possible to add multiple contour plots to the same figure without a problem:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/c/6/c676315c1217947a207b1443b438fa7dc1ff874c.png)  
The relevant line: `contourf!(vertices_x, vertices_y, (x,y) -> i/100 .+ x.+y)`  
Essentially, I am trying to plot a 2D solution from a numerical simulation cell-by-cell, with values interpolated within each cell, by iterating over all cells and calling `contourf` with the respective cell vertex coordinates `vertices_x`, `vertices_y`.

However, the same plot with `heatmap!` yields something weird:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/4/8/48ae2417c6780c2db65d43695a9d96eaf7202a1f.png)  
The relevant line: `heatmap!(vertices_x, vertices_y, (x,y) -> i/100 .+ x.+y)`  
Not only are the coordinate locations mixed up, but also there does not seem to be any interpolation between values.

Is it possible to tell from what I showed here, what I am doing wrong?

---

<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 18, 2020, 12:45pm UTC](https://discourse.julialang.org/t/filled-contour-plots-in-plots-jl-without-contour-lines-and-smooth-interpolation-gr-backend/34796/4 "2020-02-18T12:45:44Z")

</div>

Could you please provide the complete example or an MWE ?

---

<div class="post-metadata">

**Author:** ![sloede](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sloede/32/44787_2.png) [@sloede](https://discourse.julialang.org/u/sloede)\
**Post date:** [February 18, 2020, 4:26pm UTC](https://discourse.julialang.org/t/filled-contour-plots-in-plots-jl-without-contour-lines-and-smooth-interpolation-gr-backend/34796/5 "2020-02-18T16:26:08Z")

</div>

Of course. I am not sure if I was able to boil it down to the true MWE, but this is already quite short:

```julia
import GR
using Plots

gr()
GR.inline("png")

# Create cell coordinates
coordinates = transpose(
                        [-1 -1;
                          1 -1;
                         -1 1;
                          1 1]
                       )

# Create plot
plot(size=(2000,2000), thickness_scaling=3, aspectratio=:equal, legend=:none)
for i in axes(coordinates, 2)
  h = 2
  limits_x = [coordinates[1, i] - 1/2 * h, coordinates[1, i] + 1/2 * h]
  limits_y = [coordinates[2, i] - 1/2 * h, coordinates[2, i] + 1/2 * h]
  contourf!(limits_x, limits_y, (x,y) -> i .+ x .+ y)
end

savefig("mwe.png")

```

This yields the following image:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/6/e/6e209013438781d08a9446328444a2dcde35106e.png)

If I exchange `contourf!` for `heatmap!`, the following figure is generated instead:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/5/0/503b5502854ab3a3f8569635cc9fcdf9bb98292b.png)

If there’s anything else I could provide, please let me know!

---

<div class="post-metadata">

**Author:** ![sloede](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sloede/32/44787_2.png) [@sloede](https://discourse.julialang.org/u/sloede)\
**Post date:** [February 22, 2020, 7:37am UTC](https://discourse.julialang.org/t/filled-contour-plots-in-plots-jl-without-contour-lines-and-smooth-interpolation-gr-backend/34796/6 "2020-02-22T07:37:24Z")

</div>

@jheinen Any thoughts on this (sorry for the direct ping)?

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [February 22, 2020, 9:24am UTC](https://discourse.julialang.org/t/filled-contour-plots-in-plots-jl-without-contour-lines-and-smooth-interpolation-gr-backend/34796/7 "2020-02-22T09:24:18Z")

</div>

IMHO a heatmap should not interpolate by default

---

<div class="post-metadata">

**Author:** ![sloede](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sloede/32/44787_2.png) [@sloede](https://discourse.julialang.org/u/sloede)\
**Post date:** [February 22, 2020, 11:28am UTC](https://discourse.julialang.org/t/filled-contour-plots-in-plots-jl-without-contour-lines-and-smooth-interpolation-gr-backend/34796/8 "2020-02-22T11:28:26Z")

</div>

OK, but is it possible to enable interpolation in `heatmap`? And if not, this brings me back to my original questions: How can I use a contour plot without showing the lines, and how can I get smoothly interpolated colors instead of discrete levels?

---

<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 22, 2020, 11:30am UTC](https://discourse.julialang.org/t/filled-contour-plots-in-plots-jl-without-contour-lines-and-smooth-interpolation-gr-backend/34796/9 "2020-02-22T11:30:45Z")

</div>

I have an idea how to solve your problem in plain GR, but this needs some modifications in the GR convenience layer. Please give me some time to check this. In case of “success” I can integrate that solution in Plots, too.

---

<div class="post-metadata">

**Author:** ![sloede](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sloede/32/44787_2.png) [@sloede](https://discourse.julialang.org/u/sloede)\
**Post date:** [February 22, 2020, 11:35am UTC](https://discourse.julialang.org/t/filled-contour-plots-in-plots-jl-without-contour-lines-and-smooth-interpolation-gr-backend/34796/10 "2020-02-22T11:35:12Z")

</div>

This would be highly appreciated, thanks. At the moment we are looking for a Julia-only plot solution for 2D numerical results, but thus far I am not 100% convinced that it is feasible for us.

OTOH, could you please confirm that turning off contour lines (either in Plots or plain GR) is currently not supported? In that case I can stop looking 😉

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [February 22, 2020, 11:42am UTC](https://discourse.julialang.org/t/filled-contour-plots-in-plots-jl-without-contour-lines-and-smooth-interpolation-gr-backend/34796/11 "2020-02-22T11:42:10Z")

</div>

Can’t you do `linecolor = :transparent`?

---

<div class="post-metadata">

**Author:** ![sloede](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sloede/32/44787_2.png) [@sloede](https://discourse.julialang.org/u/sloede)\
**Post date:** [February 22, 2020, 11:54am UTC](https://discourse.julialang.org/t/filled-contour-plots-in-plots-jl-without-contour-lines-and-smooth-interpolation-gr-backend/34796/12 "2020-02-22T11:54:19Z")

</div>

> [@mkborregaard](#):
>
> Can’t you do `linecolor = :transparent` ?

No:

```julia
┌ Warning: GR: filled contour only supported with black contour lines
└ @ Plots ~/.julia/packages/Plots/12uaJ/src/backends/gr.jl:1641

```

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [February 22, 2020, 11:57am UTC](https://discourse.julialang.org/t/filled-contour-plots-in-plots-jl-without-contour-lines-and-smooth-interpolation-gr-backend/34796/13 "2020-02-22T11:57:50Z")

</div>

Does it help to make the linecolor width zero, or very small? Or to set the alpha channel level to 0?

---

<div class="post-metadata">

**Author:** ![sloede](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sloede/32/44787_2.png) [@sloede](https://discourse.julialang.org/u/sloede)\
**Post date:** [February 22, 2020, 12:16pm UTC](https://discourse.julialang.org/t/filled-contour-plots-in-plots-jl-without-contour-lines-and-smooth-interpolation-gr-backend/34796/14 "2020-02-22T12:16:35Z")

</div>

Good idea, but unfortunately `linewidth=0.0`, `linewidth=0.1`, or `linealpha=0` do not change the resulting image.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [February 22, 2020, 3:57pm UTC](https://discourse.julialang.org/t/filled-contour-plots-in-plots-jl-without-contour-lines-and-smooth-interpolation-gr-backend/34796/15 "2020-02-22T15:57:08Z")

</div>

PGFPlotsX can interpolate, see this example with an intentionally crude grid to highlight interpolation:

```julia
using PGFPlotsX
x = range(-2; stop = 2, length = 10)
y = range(-0.5; stop = 3, length = 10)
f(x, y) = (1 - x)^2 + 100*(y - x^2)^2
@pgf Axis({ view = (0, 90), colorbar, "colormap/jet" },
          Plot3({ surf, shader = "interp" },
                Coordinates(x, y, @. √(f(x, y')))))

```

 ![plot](https://global.discourse-cdn.com/julialang/original/3X/f/7/f7b4c1d4fb7c39bbe478ff6bd3ea92c190b33ab3.png)

There is also a bilinear shader which looks nicer (but, again, the grid is very crude):

```julia
push!(PGFPlotsX.CUSTOM_PREAMBLE, raw"\usepgfplotslibrary{patchplots}")
@pgf Axis({ view = (0, 90), colorbar, "colormap/jet" },
          Plot3({ surf, shader = "interp" ,"patch type" = "bilinear" },
                Coordinates(x, y, @. √(f(x, y')))))

```

 ![plot2](https://global.discourse-cdn.com/julialang/original/3X/7/b/7b178d6cc08f791d98d3342ccf47008f58302430.png)

You can of course overlay a contour on this, or use a different color sheme — see the manual.

---

<div class="post-metadata">

**Author:** ![sloede](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sloede/32/44787_2.png) [@sloede](https://discourse.julialang.org/u/sloede)\
**Post date:** [February 23, 2020, 2:16pm UTC](https://discourse.julialang.org/t/filled-contour-plots-in-plots-jl-without-contour-lines-and-smooth-interpolation-gr-backend/34796/16 "2020-02-23T14:16:47Z")

</div>

Thank you for the suggestion. At the moment we try to stick to `GR` as a backend, as `PGFPlotsX` we would like to avoid the additional dependency of requiring a LaTeX installation present. We might come back to your proposed solution if we cannot manage to do it otherwise though.

---

<div class="post-metadata">

**Author:** ![ElectronicTeaCup](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/electronicteacup/32/12647_2.png) [@ElectronicTeaCup](https://discourse.julialang.org/u/ElectronicTeaCup)\
**Post date:** [July 10, 2020, 11:15am UTC](https://discourse.julialang.org/t/filled-contour-plots-in-plots-jl-without-contour-lines-and-smooth-interpolation-gr-backend/34796/17 "2020-07-10T11:15:45Z")

</div>

Sorry to bring this thread back to life, but @sloede did you manage to find a way to get rid of the lines when using `contourf`?

---

<div class="post-metadata">

**Author:** ![sloede](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sloede/32/44787_2.png) [@sloede](https://discourse.julialang.org/u/sloede)\
**Post date:** [July 10, 2020, 11:45am UTC](https://discourse.julialang.org/t/filled-contour-plots-in-plots-jl-without-contour-lines-and-smooth-interpolation-gr-backend/34796/18 "2020-07-10T11:45:29Z")

</div>

No, unfortunately not. In the end, we decided to forego a Julia-only solution. Instead, we use [WriteVTK.jl](https://github.com/jipolanco/WriteVTK.jl) to write out vtk/vti/vtu files (depending on use case) and handle visualization and data analysis with ParaView.

---

<div class="post-metadata">

**Author:** ![ElectronicTeaCup](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/electronicteacup/32/12647_2.png) [@ElectronicTeaCup](https://discourse.julialang.org/u/ElectronicTeaCup)\
**Post date:** [July 10, 2020, 11:53am UTC](https://discourse.julialang.org/t/filled-contour-plots-in-plots-jl-without-contour-lines-and-smooth-interpolation-gr-backend/34796/19 "2020-07-10T11:53:01Z")

</div>

Ah okay, thanks. Anyone else know how this can be done? i.e remove contour lines when using `contourf`

---

<div class="post-metadata">

**Author:** ![weymouth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/weymouth/32/15839_2.png) [@weymouth](https://discourse.julialang.org/u/weymouth)\
**Post date:** [July 10, 2020, 10:08pm UTC](https://discourse.julialang.org/t/filled-contour-plots-in-plots-jl-without-contour-lines-and-smooth-interpolation-gr-backend/34796/20 "2020-07-10T22:08:05Z")

</div>

Upvote. Any update on turning off the contour lines for `contourf`? It would make this plot sooooo much nicer. 😉

 ![jl_xZkfBC](https://global.discourse-cdn.com/julialang/original/3X/f/e/febdd1436f4b9b5ef3c8093af4a1516d14b76d7c.gif)

Edit: `heatmap` with interpolation would be even better since I prefer the way it doesn’t cutout values outside `clims`.

[Next page](https://discourse.julialang.org/t/filled-contour-plots-in-plots-jl-without-contour-lines-and-smooth-interpolation-gr-backend/34796.md?page=2)
