How to add legend (or colorbar) to volshow/labelvolshow output?
조회 수: 38 (최근 30일)
이전 댓글 표시
Hi, can someone help me to add a legend to a panel created by labelvolshow? I managed to add a title but I really don't know how to put a legend (or at least a colorbar, even if I know it wouldn't be the same thing). Any kind of "legend" is accept: I mean, not just the output of the classic legend function; also some strings, written in the color of the data, can be fine for example..any way to categorize the output is welcome, the important thing is that I'd like it to be automatically generated by the code - no interactions with the panel required.
This is how I add a title:
view_panel = uipanel(figure,'Title',"Titolo");
view_panel.FontSize=14;
view_panel.TitlePosition='centertop';
labelvolshow(volume_labeled,'Parent',view_panel);
Thanks in advance
댓글 수: 0
채택된 답변
Voss
2022년 5월 25일
Maybe something like this can be a start:
volume_labeled = randi(10,[5 5 5]);
view_panel = uipanel(figure,'Title',"Titolo");
view_panel.FontSize=14;
view_panel.TitlePosition='centertop';
h = labelvolshow(volume_labeled,'Parent',view_panel);
NC = size(h.LabelColor,1);
ax = axes( ...
'Parent',view_panel, ...
'Units','normalized', ...
'Position',[0.93 0 0.07 1], ...
'Visible','off', ...
'YLim',[0 10], ...
'CLim',[0 10], ...
'Colormap',h.LabelColor);
p = patch( ...
'Parent',ax, ...
'XData',repmat([0; 1; 1; 0],1,NC), ...
'YData',[0;0;1;1]+(0:NC-1), ...
'FaceColor','flat', ...
'FaceVertexCData',ax.Colormap);
t = text(ax,0.5*ones(1,NC),(1:NC)-0.5,sprintfc('%d',1:NC), ...
'HorizontalAlignment','center');
t(1).Color = [1 1 1];
댓글 수: 17
Walter Roberson
2022년 9월 30일
unfortunately I do not seem to replicate this with a minimal test. Would it be possible for you to attach data and enough code to reproduce the problem?
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Polygons에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!