我有以下问题:绘制2个图形时,我得到了第二个图形的错误图例,因为线型('-', '--', ':')
未显示在图例中。但是,该图形与('-', '--', ':')
款式正确显示了3条不同的线条。Matlab:不正确的图例
奇怪的是,第一个图形的图例工作和显示不同的线型,即使我字面上使用相同的代码来格式化图表。
您是否看到错误,或者这是版本错误(我正在使用R2016b)?有没有办法“强制”图例输入样式作为解决方法?
请参阅下面的代码。
figure plot(x,CR1, 'LineStyle', '-', 'Color', 'b','LineWidth',1.5)
hold on
plot(x,CR2,'LineStyle', '--', 'Color', 'b','LineWidth',1.5)
hold on
plot(x,CR3,'LineStyle', ':', 'Color', 'b','LineWidth',1.5)
set(gca, 'xtick', [0:10:50])
xlabel('Fund lifetime (in quarters)')
legend ('\alpha = 1%', '\alpha = 5%', '\alpha = 10%', 'location','southoutside', 'Orientation','horizontal')
hold on
% Figure 2 - here the problem where the legend is incorrect
figure
plot(x,CFaR1_shift, 'LineStyle', '-', 'Color', 'b','LineWidth',1.5)
hold on
plot(x,CFaR2_shift,'LineStyle', '--', 'Color', 'b','LineWidth',1.5)
hold on
plot(x,CFaR3_shift,'LineStyle', ':', 'Color', 'b','LineWidth',1.5)
set(gca, 'xtick', [0:10:50])
xlabel('Fund lifetime (in quarters)')
legend ('\alpha = 1%', '\alpha = 5%', '\alpha = 10%', 'Location','southoutside', 'Orientation','horizontal')
这里是一个最小例子,其令人惊讶地正常工作:
x=1:0.5:50
y=x.^2;
CR1=3*y;
CR2=15*y;
CR3=20*y;
CFaR1_shift=10*y;
CFaR2_shift=15*y;
CFaR3_shift=20*y;
figure
plot(CR1, 'LineStyle', '-', 'Color', 'b','LineWidth',1.5)
hold on
plot(CR2,'LineStyle', '--', 'Color', 'b','LineWidth',1.5)
hold on
plot(CR3,'LineStyle', ':', 'Color', 'b','LineWidth',1.5)
set(gca, 'xtick', [0:10:50])
xlabel('Fund lifetime (in quarters)')
legend ('\alpha = 1%', '\alpha = 5%', '\alpha = 10%', 'location','southoutside', 'Orientation','horizontal')
hold on
% Figure 2
figure
plot(CFaR1_shift, 'LineStyle', '-', 'Color', 'b','LineWidth',1.5)
hold on
plot(CFaR2_shift,'LineStyle', '--', 'Color', 'b','LineWidth',1.5)
hold on
plot(CFaR3_shift,'LineStyle', ':', 'Color', 'b','LineWidth',1.5)
set(gca, 'xtick', [0:10:50])
xlabel('Fund lifetime (in quarters)')
legend ('\alpha = 1%', '\alpha = 5%', '\alpha = 10%', 'Location','southoutside', 'Orientation','horizontal')
以下问题表明图例类型不等于在该图中示出的线:
编辑2:如果我评论2个绘图,并且只留下一行绘制,则图例的样式是绘制的线条之一。例如,如果我只画了第二行,它看起来像如下:
请尝试构建一个[mcve]来演示您的问题。并非所有的变量都在您的代码中定义。提供你的问题的图像也可能有帮助。 – m7913d
无法用R2016a重现它 –
谢谢。我编辑了我的消息,包括一个最小的例子。令人惊讶的是,这里的传说显示正确。你看到有什么不同吗? – mcpe