# Setting the "color scale" in Plots

**URL:** https://discourse.julialang.org/t/setting-the-color-scale-in-plots/6373
**Category:** General Usage
**Created:** [October 10, 2017, 11:45am UTC](https://discourse.julialang.org/t/setting-the-color-scale-in-plots/6373 "2017-10-10T11:45:40Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![Philippe\_Maincon](https://avatars.discourse-cdn.com/v4/letter/p/a4c791/32.png) [@Philippe\_Maincon](https://discourse.julialang.org/u/Philippe_Maincon)
#### Post date: [October 10, 2017, 11:45am UTC](https://discourse.julialang.org/t/setting-the-color-scale-in-plots/6373/1 "2017-10-10T11:45:40Z")

</div>

Hi,

A question about Plots.jl. The “contour” plot below (actually representing a scalar field by colors), works as it says on the packaging.

```julia
using Plots;gr(size=(2000,1000)) 

x = y = linspace(0,1,51)
p2 = plot(x,y,(x,y)->(x*y/2.),st = :contourf,fill=(true,cgrad(:grays,[0.,0.1,1.0])))

```

But I would like to do is have control of the range using in encoding “z” (the anonymous function) with colora. In my usage, the “bgrad” takes the min and max values of z to scale the colors.

Feedback on Plots.jl: excellent work, _thank you!_. The limiting factor now is the quality of the documentation…

---

<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: [October 10, 2017, 12:16pm UTC](https://discourse.julialang.org/t/setting-the-color-scale-in-plots/6373/2 "2017-10-10T12:16:27Z")

</div>

There’s an open PR on PlotDocs to describe this functionality: [https://github.com/JuliaPlots/PlotDocs.jl/pull/57/files](https://github.com/JuliaPlots/PlotDocs.jl/pull/57/files)  
The contents are mainly based on this discourse thread: [Current list of colorschemes in Plots.jl](https://discourse.julialang.org/t/current-list-of-colorschemes-in-plots-jl/5420)

---

<div class="post-metadata">

### Author: ![Philippe\_Maincon](https://avatars.discourse-cdn.com/v4/letter/p/a4c791/32.png) [@Philippe\_Maincon](https://discourse.julialang.org/u/Philippe_Maincon)
#### Post date: [October 10, 2017, 12:30pm UTC](https://discourse.julialang.org/t/setting-the-color-scale-in-plots/6373/3 "2017-10-10T12:30:49Z")

</div>

Hi,

thanks for taking the time. I am not sure you answered my question (I followed the links, and did not find what I want), so let me rephrase:

I make two “contour” plots, with two different sets of data, which typically will have different min and max values.

_I want the mapping from z-value to color to be the same in both plots_. So I need to be able to specify that mapping myself. The simplest way is that I specify the min and max values to which the “coldest” and “warmest” (or whatever) color in the pallette is associated. In my code example, the mapping changes from plot to plot, because Plots “maximizes the use of color”.

😀

---

<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: [October 10, 2017, 12:40pm UTC](https://discourse.julialang.org/t/setting-the-color-scale-in-plots/6373/4 "2017-10-10T12:40:30Z")

</div>

`clims`

---

<div class="post-metadata">

### Author: ![Philippe\_Maincon](https://avatars.discourse-cdn.com/v4/letter/p/a4c791/32.png) [@Philippe\_Maincon](https://discourse.julialang.org/u/Philippe_Maincon)
#### Post date: [October 10, 2017, 12:53pm UTC](https://discourse.julialang.org/t/setting-the-color-scale-in-plots/6373/5 "2017-10-10T12:53:39Z")

</div>

OK, so I type

```julia
p2 = plot(x,y,(x,y)->x*y,st = :contourf,fill=(true,cgrad(:grays)),clims=[-10.,10.])

```

(my test data is in [0,1]) but, wether I used Plots/pyplot or Plots/gr, there is no effect: my contour plot is still from black to white, while I expect nuances of grey.

Any idea?

---

<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: [October 10, 2017, 12:59pm UTC](https://discourse.julialang.org/t/setting-the-color-scale-in-plots/6373/6 "2017-10-10T12:59:38Z")

</div>

I get

 ![57](https://global.discourse-cdn.com/julialang/original/3X/f/1/f1a3cd42d7fd8a8a1c93ad3c39a4c87d47e51f61.png)

---

<div class="post-metadata">

### Author: ![Philippe\_Maincon](https://avatars.discourse-cdn.com/v4/letter/p/a4c791/32.png) [@Philippe\_Maincon](https://discourse.julialang.org/u/Philippe_Maincon)
#### Post date: [October 10, 2017, 1:08pm UTC](https://discourse.julialang.org/t/setting-the-color-scale-in-plots/6373/7 "2017-10-10T13:08:29Z")

</div>

Yes, and I get the same with and without clims in my call.

Now I assume that by writing clims=[-10.,10.], I request -10 as black, 10 as white, so the contrast between z=0 and z=1 should be small, as opposed to the plot you and I get.

---

<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: [October 10, 2017, 1:25pm UTC](https://discourse.julialang.org/t/setting-the-color-scale-in-plots/6373/8 "2017-10-10T13:25:16Z")

</div>

I get what you mean now. Looks like `clims` doesn’t accept a two-length vector, though I can understand why you might think a vector could work. It works for a 2-tuple:

```julia
contourf(x, y, (x,y)->x*y, fill=:grays, clims=(-10, 10))

```

---

<div class="post-metadata">

### Author: ![Philippe\_Maincon](https://avatars.discourse-cdn.com/v4/letter/p/a4c791/32.png) [@Philippe\_Maincon](https://discourse.julialang.org/u/Philippe_Maincon)
#### Post date: [October 10, 2017, 1:30pm UTC](https://discourse.julialang.org/t/setting-the-color-scale-in-plots/6373/9 "2017-10-10T13:30:46Z")

</div>

Oh joy!!! Thank you indeed for spending the time to find out.

Of course the question behind the question is - is there a doc I haven’t found yet, in which I will find the answer to similar questions about Plots?  
[Home · Plots](http://docs.juliaplots.org/latest/) is usefull, but I have the impression there is quite a bit of stuff in Plots not documented there.

Anyhow, thank you! 😀

---

<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: [October 10, 2017, 1:34pm UTC](https://discourse.julialang.org/t/setting-the-color-scale-in-plots/6373/10 "2017-10-10T13:34:22Z")

</div>

`clims` is documented in this page [Overview · Plots](http://docs.juliaplots.org/latest/attributes/) – together with Ctrl-F that is really the most comprehensive documentation. It’s also been added to the colormaps PR.  
There’s also the `plotattr` function:

```julia
julia> plotattr(:Subplot) #symbols look up themes
Defined Subplot attributes are:
annotations, aspect_ratio, background_color_inside, background_color_legend, background_color_subplot, bottom_margin, clims, color_palette, colorbar, colorbar_title, foreground_color_legend, foreground_color_subplot, foreground_color_title, framestyle, left_margin, legend, legendfont, legendtitle, margin, projection, right_margin, subplot_index, title, title_location, titlefont, top_margin

julia> plotattr("clims") #strings look up attributes
clims {`:auto` or NTuple{2,Number}}
cbar_lims, cbarlims, clim, climits, color_limits

Fixes the limits of the colorbar.
Subplot attribute, default: auto

```

The ` {:auto or NTuple{2,Number}}` tells you that you have to pass a Tuple.

---

<div class="post-metadata">

### Author: ![SaschaMann](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/saschamann/32/2852_2.png) [@SaschaMann](https://discourse.julialang.org/u/SaschaMann)
#### Post date: [October 10, 2017, 1:36pm UTC](https://discourse.julialang.org/t/setting-the-color-scale-in-plots/6373/11 "2017-10-10T13:36:42Z")

</div>

> [@mkborregaard](#):
>
> clims is documented in this page [Attributes · Plots](http://docs.juliaplots.org/latest/attributes/) – together with Ctrl-F that is really the most comprehensive documentation. It’s also been added to the colormaps PR.

Ctrl-F “clims” brings up no result on that page. But yeah, it’s being added to the Color section.

---

<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: [October 10, 2017, 1:37pm UTC](https://discourse.julialang.org/t/setting-the-color-scale-in-plots/6373/12 "2017-10-10T13:37:16Z")

</div>

Cmd-F? That works on my Mac (Firefox)

 ![01](https://global.discourse-cdn.com/julialang/original/3X/f/a/fa34b22d2d4855a5d1908c8e0be235a2c21dcb41.png)

---

<div class="post-metadata">

### Author: ![Philippe\_Maincon](https://avatars.discourse-cdn.com/v4/letter/p/a4c791/32.png) [@Philippe\_Maincon](https://discourse.julialang.org/u/Philippe_Maincon)
#### Post date: [October 10, 2017, 1:38pm UTC](https://discourse.julialang.org/t/setting-the-color-scale-in-plots/6373/13 "2017-10-10T13:38:39Z")

</div>

Noted. Thank you for your support!  
Ctrl-F does not work in the REPL in JuliaPro, Windows (that’s the keybinding for a text search). But I will llokup how to get the “man pages” from JuliaPor/Juno.

---

<div class="post-metadata">

### Author: ![SaschaMann](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/saschamann/32/2852_2.png) [@SaschaMann](https://discourse.julialang.org/u/SaschaMann)
#### Post date: [October 10, 2017, 1:40pm UTC](https://discourse.julialang.org/t/setting-the-color-scale-in-plots/6373/14 "2017-10-10T13:40:05Z")

</div>

Oops, my bad. Didn’t realise that I have to allow JS for the docs to load everything. Sorry.

---

<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: [October 10, 2017, 1:41pm UTC](https://discourse.julialang.org/t/setting-the-color-scale-in-plots/6373/15 "2017-10-10T13:41:29Z")

</div>

It’s not documented with docstrings, thus not findable from the documentation pane. Normal docstrings work for functions and types, but you cannot look up keyword arguments. That is why we have the `plotattr` function in Plots, because keyword arguments (“attributes”) are the main interface.

---

<div class="post-metadata">

### Author: ![Philippe\_Maincon](https://avatars.discourse-cdn.com/v4/letter/p/a4c791/32.png) [@Philippe\_Maincon](https://discourse.julialang.org/u/Philippe_Maincon)
#### Post date: [October 10, 2017, 1:43pm UTC](https://discourse.julialang.org/t/setting-the-color-scale-in-plots/6373/16 "2017-10-10T13:43:13Z")

</div>

Thank you: “plotattr” is the key.

---

<div class="post-metadata">

### Author: ![jleman](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@jleman](https://discourse.julialang.org/u/jleman)
#### Post date: [June 8, 2019, 7:03pm UTC](https://discourse.julialang.org/t/setting-the-color-scale-in-plots/6373/17 "2019-06-08T19:03:58Z")

</div>

When I set clims for the colorbar of a surface plot it overrides zlim for the surface plot. For example in the plot below I would like to limit the color range to +/-0.005, but would like set zlim to +/- 0.01 Is there a way to set zlim and clims separately?

```julia
using Plots
gr()
surface(My2DMatrix, xlim=(0,30), ylim=(0,30), zlim=(-0.01,0.01), clims=(-0.005,0.005))

```

![Surface](https://global.discourse-cdn.com/julialang/original/3X/f/6/f6a91a79883a5c5d4ebad9d57265259a36c072c9.png)
