Contourf fill smaller instead of larger
16 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Bjorn Gustavsson
2020-9-23
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 个评论
Bjorn Gustavsson
2020-10-5
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...
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Contour Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!