9

I am currently using the Plots package and have it along with the PyPlot packages installed. With the code

using Plots
y = rand(10, 10)
pyplot()
plt = plot(y, st=:heatmap, clim=(0,1), color=:coolwarm, colorbar_title="y")

I am able to produce this heat map

My question is how I can change the color gradient from its current setting (coolwarm which corresponds with a transition from red to gray to blue) to a new setting which has a gradient from red to green to blue. Is there some way to create a custom colorgradient and use that as an argument where I have 'coolwarm' in my sample code?

JBar
  • 145
  • 3
  • 6
  • https://matplotlib.org/examples/color/colormaps_reference.html https://matplotlib.org/users/colormaps.html – skan May 25 '17 at 23:13

1 Answers1

7

Yes. First of all there are numerous color libraries in Plots. Try clibraries(), then e.g. cgradients(:colorbrewer) or showlibrary(colorbrewer). In addition, you can make your own gradient with e.g. cgrad([:red, :green, :blue]) and pass that as the color argument.

Michael K. Borregaard
  • 7,864
  • 1
  • 28
  • 35
  • 2
    I should perhaps add that custom color gradients cannot be recommended for professional use. All gradients in Plots, except for explicitly those in the `:misc` library, are selected to live up to the criteria for perceptual uniformity needed for e.g. scientific visualization. – Michael K. Borregaard May 26 '17 at 09:38
  • 1
    Thanks for the additional aside on perceptual uniformity. I was actually looking for the 'jet' color gradient but I have decided against this from your recommendation. As an aside I found https://github.com/bokeh/colorcet as a useful explaination of what makes a color gradient perceptually uniform. – JBar May 26 '17 at 15:08
  • Yes, I like that explanation too, and many of the `colorcet` gradients are also available in Plots. And good call IMHO on 'jet', matlab (who I think invented that color scheme and had it as their default for years) also discourage it today. `:Spectral` is a good alternative that is quite similar aesthetically. If you want something even more rainbow-like, you can set the colorcet library as default with `clibrary(:colorcet)` and then use `:rainbow` (that will override the non-uniform `:rainbow` gradient in `:misc`). – Michael K. Borregaard May 26 '17 at 15:53
  • Now that I'm at it, let me add that you can reverse any gradient with `_r`, e.g. `:Spectral_r`. – Michael K. Borregaard May 26 '17 at 15:56
  • Julia-oriented package [here](https://github.com/peterkovesi/PerceptualColourMaps.jl) – daycaster May 26 '17 at 19:17
  • Yes, that package is great, it includes the `colorcet` colors in Plots and some more. The package is by Peter Kovesi, who developed the color scheme, wrote the bit about color schemes linked from Bokeh above, and also contributed the gradients in the `colorcet` library in Plots. The PerceptualColourMaps can be be used in a range of julia plotting libraries, so it is also great for users of mainly PyPlot or Gadfly. – Michael K. Borregaard May 26 '17 at 19:35