lines through markers on legend

I am having a plot but on the legend, there are no lines through the markes. How can I fix this?.
The structure of the code is as follows:
x=-10:0.1:10;
y=cos(x);
plot(x,y,'--o','MarkerSize',5,'DisplayName',' cos(x)')
hold on
y=sin(x)
plot(x,y,'--d','MarkerSize',5,'DisplayName',' sin(x)')
hold off
legend
grid on

3 件のコメント

Molepo Alfred
Molepo Alfred 2020 年 8 月 7 日
I changed the line width from 0.5 to 1 and it worked.
madhan ravi
madhan ravi 2020 年 8 月 7 日
Well it’s clearly a bug!
Star Strider
Star Strider 2020 年 8 月 7 日
This might have already been fixed.
Be certain you have installed all the Updates. On the top toolstrip, click Help then Check for Updates.

サインインしてコメントする。

回答 (2 件)

madhan ravi
madhan ravi 2020 年 8 月 7 日

1 投票

x = -10 : 0.1 : 10;
y = cos(x);
plot(x, y, '--o', 'MarkerSize', 5)
hold on
y = sin(x)
plot(x, y, '--d', 'MarkerSize', 5)
hold off
legend({'cos(x)', 'sin(x)'})
grid on

3 件のコメント

madhan ravi
madhan ravi 2020 年 8 月 7 日
Running your code in 2020 gave me the desired result. What version are you running on?
Molepo Alfred
Molepo Alfred 2020 年 8 月 7 日
I have v 2019b.
As you can see on the figure, the lines are not going theough the markers on the legend. Its only the markers that are showing.
madhan ravi
madhan ravi 2020 年 8 月 7 日
Seems like a bug to me. Try contacting MathWorks Support Team.

サインインしてコメントする。

Arthur Roué
Arthur Roué 2020 年 8 月 7 日

1 投票

You specified '--' option for your line style in 3rd argument of plot. If you want full lines, use '-' instead.
x=-10:0.1:10;
y=cos(x);
plot(x,y,'-o','MarkerSize',5,'DisplayName',' cos(x)')
hold on
y=sin(x)
plot(x,y,'-d','MarkerSize',5,'DisplayName',' sin(x)')
hold off
legend
grid on

3 件のコメント

Molepo Alfred
Molepo Alfred 2020 年 8 月 7 日
But on legend its only markers that are showing as shown. Is there a way to modify the figure?
Arthur Roué
Arthur Roué 2020 年 8 月 7 日
I do have lines in the legend with previous code. Seems like your MATLAB is not working correctly...
Arthur Roué
Arthur Roué 2020 年 8 月 7 日

サインインしてコメントする。

カテゴリ

製品

質問済み:

2020 年 8 月 7 日

コメント済み:

2020 年 8 月 7 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by