我有以下問題:繪製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