Legend shows only one line type
Show older comments
I want to plot a figure with 6 groups of data, while in the plot, there are 6 different line types, but the legend always shows the same line type for all 6 groups of data. Could any one help me on this? Thanks!
Here is the code:
figure;
subplot(311);
hold on;
plot(X1(:, 3), X1(:,2)/X1(:,4), 'm','LineWidth',2);
plot(X2(:, 3), X2(:,2)/X2(:,4), 'r','LineWidth',2);
plot(X3(:, 3), X3(:,2)/X3(:,4), 'g','LineWidth',2);
plot(X4(:, 3), X4(:,2)/X4(:,4), 'm--','LineWidth',2);
plot(X5(:, 3), X5(:,2)/X5(:,4), 'r--','LineWidth',2);
plot(X6(:, 3), X6(:,2)/X6(:,4), 'g--','LineWidth',2);
%set(gca,'xscale','log');
legend('2.55','Honey Comb','3.57','5','1.88','Solid 1.88','Location','NorthOutside','Orientation','Horizontal');
title('X-axis Comparison');
ylabel('Transmissibility ratio)');
xlabel('Frequency(Hz)');
xlim([5, 250]);
grid on;
1 Comment
Thomas
on 10 Nov 2011
Can you please show the structure of X1 through X6.
Also how do you have 10 legends for 6 plots?
Answers (1)
Fangjun Jiang
on 10 Nov 2011
No line types are specified for the first three of your plots. The last three have the same line types.
It should work fine. See this example.
t=0:0.1:6;
figure(1);hold on;
plot(t,sin(t),'r+-');
plot(t,cos(t),'go-.');
plot(t,t,'b*:');
legend({'sin','cos','linear'});
Categories
Find more on Legend in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!