How can I change the color of each text in a plot?
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello,
I'm trying to set the color of each text instance in a plot to a different value as shown:
C={[112 48 160], [85 142 213], [250 0 0], [146 208 80]}; %my color values
hcolors=cellfun(@(x) x/255,C,'UniformOutput',false)'; %colors converted to correct scale
set(h,{'Color'},hcolors) %sets the color of each line in h, this works fine
gtext=text(0.55*exes,maxes,{'Color'},hcolors);
However, when I try to set the color of the text according to the values in hcolors, I get the following error:
"Value cell array handle dimension must match handle vector length."
If I instead use
set(gtext,{'Color'},hcolors)
Everything works fine.
Is there a way to get the correct color output all in one line using text()?
0 Commenti
Risposta accettata
Adam Danz
il 23 Ago 2019
Modificato: Adam Danz
il 23 Ago 2019
This line below should work iff the length of 'h' equal 4.
set(h,{'Color'},hcolors)
% iff
length(h) == 4
This line below, however, will definitely fail because it does not include any text values. Even when a cell array of string values is added, you cannot assign multiple colors. Multiple colors can be assigned, however, using the method above.
gtext=text(0.55*exes,maxes,{'Color'},hcolors); % will result in error
gtext=text(x,y,text); % this should work
set(gtext,{'Color'},hcolors)
2 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Annotations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!