Legend of a patch-object with a line in the center
조회 수: 13 (최근 30일)
이전 댓글 표시
Hi,
I am looking for a way to have a custom legend entry for a filled area plot along with a line plot where the individual legend entries would be combined into one entry. The single entry should have the line marker overlaid on top of the box of the filled area legend. Is this possible?
x = [0 1];
y = [1 0];
xArea = [x, fliplr(x)];
yArea = [y + 1, fliplr( y - 1 )];
figure();
hold on;
hp = plot( x, y);
hp.LineWidth = 2;
hp.HandleVisibility = 'off';
hf = fill( xArea, yArea, [0, 0.4470, 0.7410]);
hf.FaceAlpha = 0.25;
hf.LineStyle = 'none';
hLeg = legend('Single legend entry');
hLeg.FontSize = 30;
Result of the example code:
Desired look of the legend entry:
댓글 수: 1
채택된 답변
darova
2020년 4월 3일
What about this? Too complicated? No?
clc,clear
cla
[X,Y,Z] = peaks(5);
p = surf2patch(X,Y,Z);
p1 = patch(p,'facecolor','g');
h = legend('ha');
h1 = get(h,'children');
x = get(h1(1),'xdata');
y = get(h1(1),'ydata');
% c = get(h1(1),'faceVertexCData');
x = [x; x(1); x(end)];
y = [y; mean(y); mean(y)];
c = [ repmat([0 1 0],[4 1]); repmat([1 0 0],[2,1]) ];
ff = [1 2 3 4; 5 6 6 6];
set(h1(1),'vertices',[x y],...
'faces',ff,...
'faceVertexCData', c,...
'edgecolor','flat')
댓글 수: 2
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Legend에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!