Overlaying contour plots - colours

I’m working with spectroscopic data where data are visualised as 2D contour plots (just lines, not filled), and it is extremely common to overlay multiple datasets using different colours (e.g. search ‘2D NMR titration’ for lots of examples). I’m trying to create a plot recipe to view this sort of data, but I can’t figure out how to set appropriate colours for the contour lines. I’d like to set up a series of line colours for both positive and negative contours (such as the colorbrewer Paired scheme), so that a typical use case would be:

  1. contour(myfirstdataset) - positive contours will be shown in blue, negative in cyan
  2. contour!(myseconddataset) - positive contours will be shown in red, negative in magenta

However, my attempts so far setting :linecolor or :seriescolor seem to apply to lines for different levels within the same dataset, and are not cycled across multiple calls as I would like. For example, a MWE (not using recipes):

using Plots
contour(rand(10,10),seriescolor=:Paired)
contour!(rand(10,10),seriescolor=:Paired)

Any advice would be appreciated!

You can set the colour explicitly with

contour(rand(10, 10), c=:blue)
contour!(rand(10, 10), c=:red)

Thanks - I realise that, and it’s a workaround for the moment, but I was hoping to be able to write a recipe where colours would be cycled automatically, for example as they would be when plotting multiple series in a scatter plot. Is this possible?

1 Like

Check this:

using Plots; gr(dpi=600)
color1 = palette([:cyan, :blue])
color2 = palette([:magenta, :red])
contour(rand(10,10) .- 0.5, c=color1)
contour!(rand(10,10) .- 0.5, c=color2)