
How do I make a color bar of a loglog plot represent various exponents of plotted curves?
5 次查看(过去 30 天)
显示 更早的评论
I have a loglog plot on which I have plotted various curves with different exponential values (noted in the legend). My goal is to not have the legend, but instead, have a colour bar that associates the colour of the curve with values of the powers of ten. I.e., I have curves plotted for each value of 10^x, where x = [-3, ..., 3] by integer, and I would like to have, say, red be the the colour of the line associated with 10^3 and blue be associated with the line 10^-3, with a gradient in between.

0 个评论
采纳的回答
Benjamin Kraus
2018-2-14
编辑:Benjamin Kraus
2018-2-14
I'm not 100% sure I understood your question. If I understood correctly, you still want 7 lines, with 7 different colors (so the plot itself won't change), but instead of a legend you want a colorbar.
The first thing I think you will need to change to get that working is the colors. The default 7 colors come from the axes ColorOrder, and are not part of a colormap. In fact, they are 7 colors picked to be distinct from one another, instead of part of a gradient.
colors = parula(7);
Now you can plot your 7 lines, and specify your 7 colors. Note: It is up to you to make sure lines are colored in the correct order based on the data and ticks you select later.
madeupdata = magic(7);
p = loglog(madeupdata);
for ii = 1:7
p(ii).Color = colors(ii,:);
end
% set(p,{'Color'},mat2cell(colors,ones(1,7))) % Same as for loop above.
Once that is done, you need to create a colorbar with the same colormap, and manually set the ticks:
set(gca,'CLim',[-3 3]);
c = colorbar;
c.Colormap = parula;
c.Limits = [-3 3];
c.Ticks = -3:3;
Does that get you close to what you are trying to do?

2 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
