Legend of a patch-object with a line in the center
14 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commento
Risposta accettata
darova
il 3 Apr 2020
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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Legend 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!