# Setting the "color scale" in Plots

Hi,

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

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

x = y = linspace(0,1,51)
``````

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…

2 Likes

There’s an open PR on PlotDocs to describe this functionality: 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

1 Like

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”.

`clims`

1 Like

OK, so I type

``````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?

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.

1 Like

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:

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

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?
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!

`clims` is documented in this page 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> 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.

2 Likes

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

1 Like

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

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.

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

1 Like

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.

Thank you: “plotattr” is the key.

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?

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