How can I change the color of each text in a plot?
5 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Adam Danz
2019 年 8 月 23 日
編集済み: Adam Danz
2019 年 8 月 23 日
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Annotations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!