gpt4 book ai didi

matlab - 传奇;键/颜色之前的文本/描述?

转载 作者:太空宇宙 更新时间:2023-11-03 19:50:15 25 4
gpt4 key购买 nike

默认情况下,MATLAB 将图例条目的文本部分放在图中所用内容的样本之后。有什么办法可以扭转这种局面吗?例如,使用下面的代码,图例中的第一个条目是一个深蓝色矩形,后跟文本 I'm;我希望它是相反的(即文本 I'm 后跟一个深蓝色矩形)。我正在使用 R2017b

示例代码:

test_values = [ 12, 232, 22, 44, 67, 72, 123, 35, 98 ];
test_text = [ "I'm", "sorry", "Dave", "I'm", "afraid", "I", "can't", "do", "that" ];

Pie = pie( test_values );

legend( test_text );

最佳答案

这是使用一些 undocumented features 的另一个选项:

test_values = [ 12, 232, 22, 44, 67, 72, 123, 35, 98 ];
test_text = {'I''m'; 'sorry'; 'Dave'; 'I''m';'afraid';'I';'can''t';'do';'that'};
Pie = pie( test_values );
leg = legend(test_text,'Location','eastoutside');
drawnow % without this you can't accsses the legend entries
icons = [leg.EntryContainer.NodeChildren.Icon]; % an array with all the legend icons
leg.ItemTokenSize(1) = 0; % set the relative position of the text in the legend to x=0

% the following will probably need some fine tuning for a specific
% figure. It shifts the icons positions horizontally (i.e. only the first
% row has values other than zeros):
shift = [10 10 17 17
0 0 0 0
0 0 0 0];
for k = 1:numel(icons)
% move the icon (patch) border:
icons(k).Transform.Children.Children(1).VertexData = ...
icons(k).Transform.Children.Children(1).VertexData+shift;
% move the icon (patch) fill:
icons(k).Transform.Children.Children(2).VertexData = ...
icons(k).Transform.Children.Children(2).VertexData+shift;
end

% the following will probably need some fine tuning for a specific
% figure. It expands the legend box horizontally:
shift = [0 0 1 1
0 0 0 0
0 0 0 0];
leg.BoxEdge.VertexData = leg.BoxEdge.VertexData+shift; % the box border
leg.BoxFace.VertexData = leg.BoxFace.VertexData+shift; % the box face

enter image description here

关于matlab - 传奇;键/颜色之前的文本/描述?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54324854/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com