# Colormap logscale using Plot

**URL:** https://discourse.julialang.org/t/colormap-logscale-using-plot/44759
**Category:** General Usage
**Tags:** plots
**Created:** [August 11, 2020, 8:52pm UTC](https://discourse.julialang.org/t/colormap-logscale-using-plot/44759 "2020-08-11T20:52:35Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![sriharitn](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@sriharitn](https://discourse.julialang.org/u/sriharitn)
#### Post date: [August 11, 2020, 8:52pm UTC](https://discourse.julialang.org/t/colormap-logscale-using-plot/44759/1 "2020-08-11T20:52:36Z")

</div>

I’m trying to build a 3D surface plot with color in log10 scale. I just want the color to be in the log10 scale NOT the actual values itself.

```julia
N = 51
x = range(-10, stop = 10, length = N)
y = x
f(x,y)=x^2+y^2
Plots.plot(x,y,f,st=:surface,color=:jet,camera=(25,65))

```

See below:

![output](https://global.discourse-cdn.com/julialang/original/3X/b/6/b6eece1c1fea4342f64aaa7d3134269a89f1868d.png)

Here is the output with Logscale created using GNUPLOT.

 ![output_log_scale](https://global.discourse-cdn.com/julialang/original/3X/6/8/68d95f5724cb4d9c502ae81d84538d661835327b.png)

---

<div class="post-metadata">

### Author: ![BeastyBlacksmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/beastyblacksmith/32/4741_2.png) [@BeastyBlacksmith](https://discourse.julialang.org/u/BeastyBlacksmith)
#### Post date: [August 11, 2020, 8:58pm UTC](https://discourse.julialang.org/t/colormap-logscale-using-plot/44759/2 "2020-08-11T20:58:42Z")

</div>

Check out the [documentation](http://docs.juliaplots.org/latest/generated/colorschemes/#ColorGradient). It is pretty

---

<div class="post-metadata">

### Author: ![sriharitn](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@sriharitn](https://discourse.julialang.org/u/sriharitn)
#### Post date: [August 12, 2020, 4:41pm UTC](https://discourse.julialang.org/t/colormap-logscale-using-plot/44759/3 "2020-08-12T16:41:38Z")

</div>

Thank you. The link really helped.

I have used log scale, but still unable to reproduce the chart from `gnuplot`.

```julia
using Plots
N = 51
x = range(-10, stop = 10, length = N)
y = x
f(x,y)=x^2+y^2
out = Plots.plot(x,y,f,st=:surface,color= cgrad(:jet,scale=log),camera=(25,65))
savefig(out,"out.png")

```

The key driving factor is `z` the need to included in `cgrad`. How would one modify `z` to get a replica of my original plot.

![out](https://global.discourse-cdn.com/julialang/original/3X/0/d/0dcbc1bdee81310cc463ff37bc4cb8fb6b3ec26f.png)

---

<div class="post-metadata">

### Author: ![sriharitn](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@sriharitn](https://discourse.julialang.org/u/sriharitn)
#### Post date: [August 12, 2020, 4:46pm UTC](https://discourse.julialang.org/t/colormap-logscale-using-plot/44759/4 "2020-08-12T16:46:48Z")

</div>

I figured it out:

```julia
using Plots
N = 51
x = range(-10, stop = 10, length = N)
y = x
f(x,y)=x^2+y^2
z = [0.001,0.01,0.05,5,50,100,200]
out = Plots.plot(x,y,f,st=:surface,color= cgrad(:jet,z,scale=log),camera=(25,65))
savefig(out,"out.png")

```

It would be great if we can automatically estimate values `z` like `gnuplot`.

![out1](https://global.discourse-cdn.com/julialang/original/3X/7/1/71707cb488975f8e40a2d7feb1335bf91f0d0c73.png)

---

<div class="post-metadata">

### Author: ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)
#### Post date: [August 12, 2020, 7:20pm UTC](https://discourse.julialang.org/t/colormap-logscale-using-plot/44759/5 "2020-08-12T19:20:27Z")

</div>

You can do e.g.

```julia
z = 10 .^ (1:0.01:2)

```

---

<div class="post-metadata">

### Author: ![Ininterrompue](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ininterrompue/32/5594_2.png) [@Ininterrompue](https://discourse.julialang.org/u/Ininterrompue)
#### Post date: [November 21, 2022, 9:38pm UTC](https://discourse.julialang.org/t/colormap-logscale-using-plot/44759/6 "2022-11-21T21:38:50Z")

</div>

I’m trying to do this with contours but it’s not working.

```julia
using Plots; pyplot()

f(x, y) = exp(x^2 + y^2)
x = range(-3, 3, length=100)'
y = range(-3, 3, length=100)
z = @. f(x, y)
zc = 10 .^ range(log10(minimum(z)), log10(maximum(z)), length=100)
contourf(x, y, z, colorbar_scale=:log10, color=cgrad(:turbo, zc, scale=:log10))

```

But most of the plot is blue, when it should be a more gradual gradient. In other words, I’d like to have something like [this](https://matplotlib.org/stable/tutorials/colors/colormapnorms.html), or [this](https://matplotlib.org/stable/gallery/images_contours_and_fields/contourf_log.html), where each level is an order of magnitude. Is this possible?

---

<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: [November 21, 2022, 11:04pm UTC](https://discourse.julialang.org/t/colormap-logscale-using-plot/44759/7 "2022-11-21T23:04:36Z")

</div>

You can play with `plot()`'s keyword arguments `levels` and `colorbar_ticks` to produce discrete or smooth contour maps:

 ![Plots_pyplot_colorbar_tick_labels2](https://global.discourse-cdn.com/julialang/original/3X/f/2/f2cf8488260acd62574472916429fd7141ef298a.png)

 ![Plots_pyplot_colorbar_tick_labels3](https://global.discourse-cdn.com/julialang/original/3X/9/1/911ebf4fd18ec2a3eaec590b5df6d44463e67d84.png)

---

<div class="post-metadata">

### Author: ![Ininterrompue](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ininterrompue/32/5594_2.png) [@Ininterrompue](https://discourse.julialang.org/u/Ininterrompue)
#### Post date: [November 22, 2022, 3:26am UTC](https://discourse.julialang.org/t/colormap-logscale-using-plot/44759/9 "2022-11-22T03:26:17Z")

</div>

Ok I figured it out. Unfortunately it requires plotting \log z instead of z directly…code below for reference.

```julia
using Plots, LaTeXStrings
pyplot()

h(x, y) = exp(x^2 + y^2)

x = range(-3, 3, length=100) |> adjoint
y = range(-3, 3, length=100)
z = @. h(x, y)

tv = 0:8
tl = [L"10^{%$i}" for i in tv]
contourf(x, y, log10.(z), color=:turbo, levels=8, colorbar_ticks=(tv, tl), 
    aspect_ratio=:equal,
    title=L"\exp(x^{2} + y^{2})", 
    xlabel=L"x", 
    ylabel=L"y")

```

![Figure_1](https://global.discourse-cdn.com/julialang/original/3X/7/7/77a9f561ace47a0eed98fc898a68759608e3d13f.png)
