# 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:** 2

<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:** [July 11, 2020, 3:59am UTC](https://discourse.julialang.org/t/filled-contour-plots-in-plots-jl-without-contour-lines-and-smooth-interpolation-gr-backend/34796/21 "2020-07-11T03:59:48Z")

</div>

… you can add `linewidth=0` to your `contourf` command to disable the contour lines

---

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

</div>

Sorry, I meant on plotly backend. `linewidth=0` did not work. I should make a separate thread for that though. Thanks for the input, it is working on GR nicely 😀.

---

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

</div>

Ah, I’m sorry. Earlier in the thread @sloede said this didn’t work. But it does!

 ![jl_nRCgRE](https://global.discourse-cdn.com/julialang/original/3X/e/0/e03ca3107edfc4ec007649fd214dd2e8a6f88dae.gif)  
Sorry to pester you, but is there a way to change behaviour beyond the color limits? I have hacked it by limiting the array values before I pass it to `plot` , but I can’t see if there is a native way to avoid the white-out regions my previous plot.

---

<div class="post-metadata">

**Author:** ![Songhan](https://avatars.discourse-cdn.com/v4/letter/s/a9a28c/32.png) [@Songhan](https://discourse.julialang.org/u/Songhan)\
**Post date:** [February 4, 2021, 10:01am UTC](https://discourse.julialang.org/t/filled-contour-plots-in-plots-jl-without-contour-lines-and-smooth-interpolation-gr-backend/34796/24 "2021-02-04T10:01:57Z")

</div>

It looks amazing! But I have a question:

I note that the gray zone is not disturbed by the interpolation, which is correct.  
From my result, there are quite a lot of fluctuations in small-value areas, see below:

![ani_acoustics](https://global.discourse-cdn.com/julialang/original/3X/c/4/c4de3d26792a2d8a7aca6dd5b5f06f5321894e5a.gif)

I think this is possibly caused by the interpolation. While the issue does not occur when using the heatmap (with interpolation) in GLMakie, see the next reply (new users can only upload one media file).

As GLMakie is too much complicated for me, I wish to keep using Plots (GR). Is it possible to allow the interpolation in the heatmap function just like the heatmap in GLMakie? This was allowed in old version (in 2016 if I remember correctly), but it was later disabled by default (I don’t know why). Actually it is quite useful to visualizing the results of numerical modellings.

---

<div class="post-metadata">

**Author:** ![Songhan](https://avatars.discourse-cdn.com/v4/letter/s/a9a28c/32.png) [@Songhan](https://discourse.julialang.org/u/Songhan)\
**Post date:** [February 4, 2021, 10:02am UTC](https://discourse.julialang.org/t/filled-contour-plots-in-plots-jl-without-contour-lines-and-smooth-interpolation-gr-backend/34796/25 "2021-02-04T10:02:53Z")

</div>

![Makie_ani_acoustics](https://global.discourse-cdn.com/julialang/original/3X/f/9/f910d5801bcb6a4a79c4f7dc113de03da3343a80.gif)

---

<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:** [February 4, 2021, 10:41am UTC](https://discourse.julialang.org/t/filled-contour-plots-in-plots-jl-without-contour-lines-and-smooth-interpolation-gr-backend/34796/26 "2021-02-04T10:41:23Z")

</div>

Hey @Songhan,

Two important plotting tips! First, this kind of data (with high and low values around a midrange) should be visualized with a [diverging color scale](https://everydayanalytics.ca/2017/03/when-to-use-sequential-and-diverging-palettes.html), not a rainbow scale. Second, never include zero in your list of color levels. That is what gives you the flickers.

---

<div class="post-metadata">

**Author:** ![Songhan](https://avatars.discourse-cdn.com/v4/letter/s/a9a28c/32.png) [@Songhan](https://discourse.julialang.org/u/Songhan)\
**Post date:** [February 4, 2021, 11:12am UTC](https://discourse.julialang.org/t/filled-contour-plots-in-plots-jl-without-contour-lines-and-smooth-interpolation-gr-backend/34796/27 "2021-02-04T11:12:50Z")

</div>

Thank you @weymouth !

I have tried your suggestions:

1. The diverging colormap :diverging\_bwr\_55\_98\_c37\_n256 is used instead;

2. I have checked the data. All of them are non-zero. The values in some areas are quite close to zero (but not strictly zero).

![ani_acoustics](https://global.discourse-cdn.com/julialang/original/3X/b/9/b90431dbd1daba76504e7c8c2a80f75d9078fd92.gif)

The output becomes much better than the previous one, but the flickers can still be observed. Is there any other issues which should be fixed from my code?

But anyhow, I am not sure if it comes from a bug in Plots, since the heatmap in GLMakie avoids the flickers even using my previous settings.

---

<div class="post-metadata">

**Author:** ![Songhan](https://avatars.discourse-cdn.com/v4/letter/s/a9a28c/32.png) [@Songhan](https://discourse.julialang.org/u/Songhan)\
**Post date:** [February 4, 2021, 11:29am UTC](https://discourse.julialang.org/t/filled-contour-plots-in-plots-jl-without-contour-lines-and-smooth-interpolation-gr-backend/34796/28 "2021-02-04T11:29:24Z")

</div>

I tried to avoid the near-zero values from the following modifications on my data:

```julia
for ii = 1:5151
    for jj = 1:500
        if abs.(Ug[ii,jj]) < 1e-2
            Ug[ii,jj] = 0
        end
    end
end

```

This changes the small values to be exactly zero, and the plot result becomes correct (even using the colormap “jet” which is not diverging):

![ani_acoustics](https://global.discourse-cdn.com/julialang/original/3X/0/4/046961d5454e57d7302a0b5a39f6506114f3678b.gif)

So, possibly the issue comes from these small values. It would be good if there is another approach to overcome this issue instead of modifying the source data.

---

<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:** [February 4, 2021, 11:33am UTC](https://discourse.julialang.org/t/filled-contour-plots-in-plots-jl-without-contour-lines-and-smooth-interpolation-gr-backend/34796/29 "2021-02-04T11:33:17Z")

</div>

The problem is that you are using color maps with a _contour level_ at zero, and you have values just above and below zero in your field. Get rid of the 0 _contour level_.

Look at my color map compared to yours. Mine (`RdBl_11`) has the same grey color above and below zero, that means you won’t see the small changes above and below zero. The two you’ve picked both have different colors above and below zero.

In short - don’t change your data, change your color map.

---

<div class="post-metadata">

**Author:** ![Songhan](https://avatars.discourse-cdn.com/v4/letter/s/a9a28c/32.png) [@Songhan](https://discourse.julialang.org/u/Songhan)\
**Post date:** [February 4, 2021, 1:16pm UTC](https://discourse.julialang.org/t/filled-contour-plots-in-plots-jl-without-contour-lines-and-smooth-interpolation-gr-backend/34796/30 "2021-02-04T13:16:03Z")

</div>

Thank you @weymouth !

It comes out an error when using colormap = :RdBl\_11 as you suggested, but I have tried the colormap (colormap = :cyclic\_grey\_15\_85\_c0\_n256\_s25), and the result becomes fine indeed.

Still, I believe that this issue should exist as well in the heatmap (for GR) when the colormap is not diverging (such as the previous one). But it is not the case. So, I guess maybe the issue comes from the discretized colormap in contour, as I note that the colorbar is divided into a number of blocks, i.e., is not smooth and continuous. Should this be the reason?

---

<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:** [April 24, 2023, 1:32pm UTC](https://discourse.julialang.org/t/filled-contour-plots-in-plots-jl-without-contour-lines-and-smooth-interpolation-gr-backend/34796/31 "2023-04-24T13:32:53Z")

</div>

> [@weymouth](#):
>
> Upvote. Any update on turning off the contour lines for `contourf`? It would make this plot sooooo much nicer. 😉

This has stopped working again in new versions of Plots. Is there a new way to do it?

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [April 24, 2023, 10:42pm UTC](https://discourse.julialang.org/t/filled-contour-plots-in-plots-jl-without-contour-lines-and-smooth-interpolation-gr-backend/34796/32 "2023-04-24T22:42:07Z")

</div>

The `linewidth` keyword argument works for me with `gr()` backend.  
Try `lw=0`.

---

<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:** [April 25, 2023, 3:02am UTC](https://discourse.julialang.org/t/filled-contour-plots-in-plots-jl-without-contour-lines-and-smooth-interpolation-gr-backend/34796/33 "2023-04-25T03:02:52Z")

</div>

Yes, that seems to work. However, I would consider this a workaround and think of something better (in GR).

---

<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:** [April 25, 2023, 11:29am UTC](https://discourse.julialang.org/t/filled-contour-plots-in-plots-jl-without-contour-lines-and-smooth-interpolation-gr-backend/34796/34 "2023-04-25T11:29:26Z")

</div>

How odd. Neither of those options remove the lines from my `contourf` plots. Perhaps it depends on the system? I’m using Windows.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [April 25, 2023, 12:38pm UTC](https://discourse.julialang.org/t/filled-contour-plots-in-plots-jl-without-contour-lines-and-smooth-interpolation-gr-backend/34796/35 "2023-04-25T12:38:10Z")

</div>

Just to be sure we are talking about the same thing.

On Win11, Julia 1.8.5, with latest versions of Plots.j and GR.jl, the folllowing MWE:

```julia
using Plots; gr()
z = Plots.GR.peaks(200)
Plots.contourf(z, lw=0)

```

produces:

 ![Plots_gr_contourf_lw0](https://global.discourse-cdn.com/julialang/original/3X/a/b/ab8983f7cdafb7b54fa9e55274886520d92f7cdb.png)

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [April 25, 2023, 1:20pm UTC](https://discourse.julialang.org/t/filled-contour-plots-in-plots-jl-without-contour-lines-and-smooth-interpolation-gr-backend/34796/36 "2023-04-25T13:20:57Z")

</div>

Btw, using `contourf(z, lw=0, levels=1000)`, produces a smooth plot but not a sufficiently smooth color scale:

 ![Plots_gr_contourf_lw0_levels1000](https://global.discourse-cdn.com/julialang/original/3X/f/4/f4f476a7f0b56dc62bcc693b2e20d7ac49c1eb40.jpeg)

In this case, it is better to use `heatmap()`

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [April 25, 2023, 2:49pm UTC](https://discourse.julialang.org/t/filled-contour-plots-in-plots-jl-without-contour-lines-and-smooth-interpolation-gr-backend/34796/37 "2023-04-25T14:49:04Z")

</div>

… and another colorscale. That’s awful 🙂

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [April 25, 2023, 3:08pm UTC](https://discourse.julialang.org/t/filled-contour-plots-in-plots-jl-without-contour-lines-and-smooth-interpolation-gr-backend/34796/38 "2023-04-25T15:08:44Z")

</div>

As indicated, there is no problem with the `heatmap()` colorbar:

 ![Plots_gr_heatmap](https://global.discourse-cdn.com/julialang/original/3X/7/5/753c799d62982d22f23d7959ef427f690de600ae.png)

---

<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:** [April 25, 2023, 6:03pm UTC](https://discourse.julialang.org/t/filled-contour-plots-in-plots-jl-without-contour-lines-and-smooth-interpolation-gr-backend/34796/39 "2023-04-25T18:03:48Z")

</div>

Apologies. It turns out I’m talking about a line between two essentially equal levels in the colormap. Setting levels to the same number of colors in the colormap fixed the problem.

---

<div class="post-metadata">

**Author:** ![arietsu](https://avatars.discourse-cdn.com/v4/letter/a/71c47a/32.png) [@arietsu](https://discourse.julialang.org/u/arietsu)\
**Post date:** [August 29, 2023, 4:35pm UTC](https://discourse.julialang.org/t/filled-contour-plots-in-plots-jl-without-contour-lines-and-smooth-interpolation-gr-backend/34796/40 "2023-08-29T16:35:25Z")

</div>

I apologise 🙂 I’ve just came to very similar 2d contour diagrams, trying to use Plots.jl to visualise flow — 2d tabulated data with hydrodynamic equations solutions.

Could you please tell how you do it without using pyplot? (Possibly in gr()?). Because my gr contour() works only with explicit function of coordinates, but what if it’s just a table, 2d array? Google helped only to find this very topic. Thank you!

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

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