# Current list of colorschemes in Plots.jl

#1

Is there a command to find out all the currently defined colorschemes? The one below that used to work is not working anymore:

PlotUtils._gradients |> keys |> showall


Setting the "color scale" in Plots
#2

Color gradients in Plots are arranged into color libraries. You don’t need to know or specify the color library to pick a color scheme, but they are useful for exploration. To get a list of all color libraries in Plots, use the clibraries function:

julia> clibraries()
5-element Array{Symbol,1}:
:Plots
:cmocean
:misc
:colorcet
:colorbrewer


All but the :misc library are restricted to colorgradients that live up to the perceptual uniformity standards for scientific visualization (so you’ll have to look in the :misc library for a rainbow gradient). The Plots color library is loaded by default.
You can get a list of colorschemes in each gradient by calling e.g. cgradients(:colorcet). Or, you can use the showlibrary function to get a visual representation, e.g.

showlibrary(:Plots)


Each color library also defines a default gradient (:magma in the case of :Plots), a :sequential gradient, and a :diverging gradient (for color gradients that are brightest in the middle - in :Plots this is the :pu_or gradient).

You can change the active color library by clibrary(:colorbrewer). You can use any color gradient regardless of library by passing its name to the color attribute in Plots, but in case of namespace clashes (e.g. there are multiple :blues) it will default to the one in the current library.

I should add that you can reverse any color gradient by appending “_r”, e.g. :viridis_r.

I would strongly recommend exploring the :colorbrewer (from here), :colorcet (from e.g. here) and :cmocean (from here) libraries, they are very nice.

#3

This is an awesome answer @mkborregaard! All I always wanted to know about colorschemes in Plots.jl, a big

Thanks for answering in detail, this will serve as documentation for future users.

#4

This is indeed an excellent guide! Is there an equivalent for selecting discrete colors rather than gradients? In other words, if I do

ys = rand(10,5)
plot(ys)


Colors are picked in order, it seems to maximize contrast. Is there a way to look at what the order is, or change it?

#5

The colors of different series is as default set with the distinguishable_colors function from Colors.jl, in order to maximize the contrast to the background. You can change it with the color_palette attribute, either passing a vector of colors to choose from, or the name of a gradient (it will select distinguishable colors from that gradient).

Alternatively you can set the look of all your plots with theme, e.g. to make the look of plots match your visual theme in juno:

theme(:juno)
p1=plot([cumsum(randn(100)) cumsum(randn(100))])
theme(:sand)
p2 = plot([sin, cos])
theme(:default)
plot(p,p2)


#6

@mkborregaard, adding to the thread, how do you construct a color gradient with N specific colors? (e.g. [:red, :yellow, :blue])

#7

You can’t at the moment. Color gradients in Plots are stretched/interpolated. A classified color map is on the todo:
https://github.com/JuliaPlots/Plots.jl/issues/118
https://github.com/JuliaPlots/Plots.jl/issues/383
https://github.com/JuliaPlots/PlotUtils.jl/issues/3

#8

@mkborregaard, I was asking for an interpolation method actually that given 3 colors let’s say, generates the color gradient. I just found the solution by digging into the source code:

using Plots

A = [i for i=1:100, j=1:100]



#9

Ah, I misunderstood. The syntax is actually heatmap(A, c=cgrad([:red,:yellow,:blue])). The cgrad function also lets you associate each of the colors with a certain value, create uneven interpolations, specify that the color scale should be e.g. logged, and set an alpha value for the gradient. It’s all in the source code You know, I think I should move some of this post to the Plots docs

#10

That would be great! Thanks for sharing the right way

#11

#12

http://docs.juliaplots.org/latest/colors/

Is anything still missing from there in your view @yakir12?

#13

IMO what you said earlier in this thread:

All but the :misc library are restricted to colorgradients that live up to the perceptual uniformity standards for scientific visualization

… is not clear in the docs, especially since the section on the Colorcet library is the only one that mentions perceptual uniformness (making it seem like none of the others have this property).

#14

@mkborregaard, this is really great. Thank you very much. I especially think that the tutorial is useful. I was especially after the logarithmic color scale, a very cool option for heatmaps.

#15

Cool it’s useful - thank @SaschaMann who did the PR The tutorial is really old and should perhaps be revisited It’s an original by Tom Breloff.

@waldyrious yes that’s a good point

#16

Very useful info in this thread!

I’ve always wondered about colors. Is it so that symbols for the CSS color names are supported, https://www.w3schools.com/colors/colors_groups.asp ? Seems like one can use symbols with the CSS color names in lowercase…, e.g.:

p1 = plot(x,y,lc=:red,label=L"\sin(x)\exp(-x/6)");
p2 = plot(x,z,lc=:green,label=L"\cos(x)\exp(-x/8)");
p3 = plot(x,u,lc=:cornflowerblue,label=L"\sinc(x)");

#17

Some info I have had problems finding, related to layout… for more specialized layout, e.g:

plot(p1,p2,p3,p4, layout = @layout [a{0.4w} [b c;d]])

…is it so that “a”, “b”, “c”, “d” is some reference to p1, p2, p3, p4? (I assume so…), but I haven’t really found clear explanation of this.

#18

A final couple of things I have wished for…

• When doing parametric plots, e.g., with phase plots with time as parameter, it would be really useful to let the color of the curve change with the parameter. One can do this by splitting up the curve of N elements in N-1 straight lines, and assign a new color to each segment – e.g., using linspace between two RGB colors, but the resulting plotting is really slow.

• I have tried to use 3D plot with contours. Doesn’t look nice if the min value of the surface is close to zero – this tends to hide the contours. It would be useful if one could specify at which “z” value the contours should appear. (This can relatively easily be done with Matplotlib/Pyplot).

#19

plot(rand(10), line_z = 0.1:0.1:1)

contour(rand(10,10), levels = [0.2, 0.5])

Concerning layout, this tutorial may be helpful.

As a general rule though, this (a topic about colorschemes) is not the preferred place to ask usage questions about plots, either the gitter or the slack channels are probably better. Also, make sure to go through the documentation before asking and, once you figure out something that was not documented, please consider opening a PR to improve the documentation (which you can find here).

#20

And yes, CSS color names are supported.