How to change a legend to a circle with a line crossing it?

35 ビュー (過去 30 日間)
Lukasz Skowron
Lukasz Skowron 2018 年 10 月 29 日
コメント済み: Lukasz Skowron 2018 年 10 月 29 日
Hi. So this is the code I am using:
i
X = [500,1000,2000,4000,8000,16000];
Y = [6.55,6.25,6.15,6.1,6.07,6.05];
ref = [6.048,6.048,6.048,6.048,6.048,6.048];
plot(X,Y,'k','Linewidth',1)
hold on
plot(X,Y,'o','MarkerEdgeColor','black')
hold on
plot(X,ref,'k','Linewidth',1)
hold on
grid on
legend('I dont want this', 'I want this', 'reference')
And here's a picture of how the graph looks like and a second picture with the graph I would like to achieve(edited in Paint):
Any ideas of how I can achieve that in Matlab without having to edit the file in Paint? Also how to get rid of the first item in the legend? Also there is no "i" at the beginning of my code, I just don't know how to delete it.

採用された回答

Addy
Addy 2018 年 10 月 29 日
Hi,
I saw that you plotted X and Y as a line and again plotting the X and Y as a marker.
That is why you get 2 legend entries and the third for reference.
If you would like to eliminate the this problem, you can use '-ok' to plot the data with line and the marker with black color in the same time.
plot(X,Y,'-ok','MarkerEdgeColor','black')
hold on
plot(X,ref,'k','Linewidth',1)
hold on
grid on
legend( 'I want this', 'reference')
and I got this
I hope this is what you were looking for.
  5 件のコメント
madhan ravi
madhan ravi 2018 年 10 月 29 日
It’s a bit rude because I was taking my time to explain you and then you accept other answer , (nothing personal though)
Lukasz Skowron
Lukasz Skowron 2018 年 10 月 29 日
To be honest I liked Addy's answer a bit more. So even if I had seen that yours before, I wouldn't have clicked accept the answer because Addy has just posted his solution.

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

その他の回答 (1 件)

madhan ravi
madhan ravi 2018 年 10 月 29 日
X = [500,1000,2000,4000,8000,16000];
Y = [6.55,6.25,6.15,6.1,6.07,6.05];
ref = [6.048,6.048,6.048,6.048,6.048,6.048];
h1=plot(X,Y,'-ok','Linewidth',1)
hold on
h2=plot(X,Y,'*','MarkerEdgeColor','black')
hold on
h3=plot(X,ref,'k','Linewidth',1)
hold on
grid on
legend([h1 h3],{'I want this' , 'reference'}) % just an example to skip a legend

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by