multiple colorbars in one figure
58 次查看(过去 30 天)
显示 更早的评论
I would like to generate a colorbar for a plot which has two columns of colors. MWE of where I am now:
x = 0:10;
y1 = 1*x+(16:19)';
y2 = 2*x + (1:4)';
blue = [0 0.4470 0.7410];
orange = [0.8500 0.3250 0.0980];
colors = [1-(1-blue)*0.2;
1-(1-blue)*0.5;
1-(1-blue)*0.8;
blue;
1-(1-orange)*0.2;
1-(1-orange)*0.5;
1-(1-orange)*0.8;
orange];
figure;
colororder(colors)
hold on
plot(x,y1)
plot(x,y2)
colormap(colors)
colorbar
I would like the colorbar to look something more like this (edited in illustrator).
Is there a way to do this programmatically?
1 个评论
Dyuman Joshi
2023-9-26
You have stated that this is a MWE of what you are attempting to do.
How many colorbars do you want to merge in this fashion for your original data? Based on the first sentence I would say 2, but I am not certain.
采纳的回答
更多回答(1 个)
Walter Roberson
2023-9-26
You can create multiple colorbar() using the 'Position' property. If colorbar() believes that a new colorbar overlaps an existing one then it will delete the existing one(s) considered to be overlapped.
The rule is not "only one colorbar per axes" -- you can, for example, colorbar('north') and colorbar('east') on the same axes.
Once you have the handle for a colorbar, you can change its Limits property. If you do that then the color patch and labels will update.
It is not possible to create more than one colormap in one axes. It is, however, possible to set the Colormap property of a colorbar to contain a colormap (N x 3 array of double). I'm not convinced it would be a good idea to do so, but it is possible
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Colormaps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!