How to change text in plot follow colormap?
2 views (last 30 days)
I am trying to make a plot where instead of a legend I have used text to annotate just above each line. Here is an example:
I have used a colormap (winter) to color each line in my plot by:
I have then placed text at the chosen position by selecting an x and y coordinate.
t = text(12 ,1.4, NCA-OCY,'FontSize',16); %...ect
Q: How would I go about applying the same colormap to my plot labels?
DGM on 10 May 2022
Edited: DGM on 10 May 2022
Consider the crude example:
% you have some plots already
cmap = winter(5); % use the colormap
for k = 1:5
t(k) = text(0,k,sprintf('this is label #%d',k),'FontSize',16);
t(k).Color = cmap(k,:); % just set the color
Note that t is an array of graphics handles instead of a scalar handle. If you were to need to change the text objects later, you'd still be able to.