Contourf fill smaller instead of larger
13 views (last 30 days)
Show older comments
Hi Folks,
By default, contourf fills colour equal to or greater than the chosen level.
Is it possible to make it do the opposite (i.e. fill with colour all areas lower than the specified level)?
I know a work around would be to just plot the negative of the data and flip the colormap, but ideally I want to use it to highlight positive and negative regions on the same plot, which using that workaround would require 2 colormaps on 1 axes which is problematic.
For example, the following code takes the "peaks" surface, and highlights everything greater than +2 in yellow, everything between -2 and +2 as dark blue, and everything lower than -2 remains white....
figure;
contour(peaks,[-2 2])
What I'd like it to do is what I photoshopped in the following image, to highlight everything greater than +2 as yellow (as before) but everything less than -2 as dark blue, and leave everything between -2 and +2 as white. Like this...
Ideally something that can be done programatically, as I need to do multiple levels and for many hundreds of plots!
Thanks,
Daniel
0 Comments
Answers (1)
Bjorn Gustavsson
on 23 Sep 2020
You "simply" have to create a colormap that is white (or suitable levels of pale, or black in case of that making more esthetic sense) in the middle, there are a couple of such colormap-tools on the file exchange: red-blue #1, custom colormaps, pycolormap4matlab, crameri colormaps, colorbrewer (I'm sure there's more). Some of these packages give you multiple colormaps, the red-blue is obviously a red-white-blue colormap, all will illustrate the concept so that you can start tinkering with something that makes the presentation of your data great.
HTH
2 Comments
Bjorn Gustavsson
on 5 Oct 2020
OK, that was a bit more of a slog than I imagined. Have a look at the cmfit function of the colormap-and-colorbar file exchange contribution. (At least at a first glance) it seems to give you a function to automatically set the colormap-bands. (I haven't needed to do plots like yours, and haven't tried to use this function for that either...)
Also there ought to be a contourf-like contribution on the FEX that does this...
See Also
Categories
Find more on Contour Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!