how to plot 2 colorbars from same set of data in contourf
Show older comments
I have a contourf plot using a single set of data consisting of both positive and negative values.
I would like to plot two separate colorbars to easily distinguish between the positive and negative values (I assume this would require some conditional statement). I would like to have the 0 values of data in white, negative values in blue scale and positive values in red scale. Basically, similar to that shown in the figure.
Any ideas on how this can be done? I've looked through the forum but I can't seem to find something related to two color bars from the same set of data.

3 Comments
darova
on 13 Jun 2020
create your own colorbar using surf or patch
Jacqueline Mifsud
on 13 Jun 2020
darova
on 13 Jun 2020
Bad idea about surf and patch. BUt you can modify existing colorbar
Answers (1)
darova
on 13 Jun 2020
- Create one more colorbar using copyobj
- Modify colorbars using set function
clc,clear
clf
[x,y,z] = peaks(50);
surf(x,y,z)
h = colorbar('location','north');
h1 = copyobj(h,gcf);
set(h,'position',[0.05 0.85 0.4 0.05])
set(h,'xlim',[2 5])
set(h1,'position',[0.55 0.85 0.4 0.05])
set(h1,'xlim',[-5 -2])

Categories
Find more on Colorbar 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!