2016-06-20 17 views
6

Mam dwa zestawy danych, które chcę wykreślić na tej samej figurze, np. dwa cosinus i dwie sine działki, które właśnie różnią się amplitudą:Scile line stiles w legendzie MATLAB

x = -pi:pi/20:pi; 
hold all; 
amplitude = 1; 
plot(x,amplitude*cos(x),'-'); 
plot(x,amplitude*sin(x),'-'); 

ax = gca; 
ax.ColorOrderIndex = 1; 

amplitude=3; 
plot(x,amplitude*cos(x),'.'); 
plot(x,amplitude*sin(x),'.'); 

legend('1*cos(x)','1*sin(x)', '2*cos(x)','2*sin(x)'); 
hold off; 

current

chcę „skompresować” legendę tak, że dwa Stiles liniowe (normalnej linii i przerywana linia) są „połączone” i pojawiają się obok tego samego wpisu tekstowego w legendy, takie jak:

desired

jak mogę to osiągnąć w MATLAB-ie? Obecnie używam R2015b.

+1

Tricky Quest jon, myślę, że to może pomóc, spójrz: [link] (http://stackoverflow.com/questions/33474206/add-custom-legend-without-any-relation-to-the-graph) – Niles

Odpowiedz

0

Jest to najbliżej mam o szybkie spojrzenie z r2015b:

Example image

%% 
f = figure; 
ax = axes; 
x = -pi:pi/20:pi; 
hold all; 
amplitude = 1; 
c1 = plot(x,amplitude*cos(x),'-', 'DisplayName', 'cos(x)'); 
s1 = plot(x,amplitude*sin(x),'-', 'DisplayName', 'sin(x)'); 

ax.ColorOrderIndex = 1; 

amplitude=3; 
c2 = plot(x,amplitude*cos(x),'.', 'DisplayName', ' '); 
s2 = plot(x,amplitude*sin(x),'.', 'DisplayName', ' '); 

lg = legend([c1 c2 s1 s2]); 
hold off; 

Manipulowanie legendy było łatwiejsze pre HG2 - tak korzystasz ze starszej wersji Matlab (r2013a) uzyskać:

enter image description here

%% 
f = figure; 
ax = handle(axes); 
x = -pi:pi/20:pi; 
hold all; 
amplitude = 1; 
c1 = plot(x,amplitude*cos(x),'r-', 'DisplayName', 'cos(x)'); 
s1 = plot(x,amplitude*sin(x),'b-', 'DisplayName', 'sin(x)'); 

amplitude=3; 
c2 = plot(x,amplitude*cos(x),'r.', 'DisplayName', ' '); 
s2 = plot(x,amplitude*sin(x),'b.', 'DisplayName', ' '); 

lg = handle(legend([c1 c2 s1 s2])); 
hold off; 

% You need to find which of the children on the legend is 
% each of the plots: 
c1 = handle(lg.Children(1)); 
c1.YData = 0.3; 

s1 = handle(lg.Children(7)); 
s1.YData = 0.75; 
+0

To ktokolwiek zignorował - czy możesz wyjaśnić, dlaczego? – matlabgui

+1

nie mam pojęcia, właśnie przegłosowałem :) –

Powiązane problemy