color of line plot with marker problem

6 ビュー (過去 30 日間)
Yu Li
Yu Li 2018 年 12 月 11 日
コメント済み: Yu Li 2018 年 12 月 11 日
I want to draw a line plot with color, and find the solution here:
the problem is that, it can only control the color of the marker, not the line. I tried to improve the command from:
x = linspace(0,10,50);
y = sin(x);
plot(x,y,'-s','MarkerSize',10,...
'MarkerEdgeColor','red',...
'MarkerFaceColor',[1 .6 .6])
to:
x = linspace(0,10,50);
y = sin(x);
plot(x,y,'r','-s','MarkerSize',10,...
'MarkerEdgeColor','red',...
'MarkerFaceColor',[1 .6 .6])
Matlab reports error.
is there anyway to control the color of both the line and marker together?
Thanks!
Yu

採用された回答

Adam Danz
Adam Danz 2018 年 12 月 11 日
編集済み: Adam Danz 2018 年 12 月 11 日
The color of the line is controlled by the 'color' parameter.
x = linspace(0,10,50);
y = sin(x);
plot(x,y,'-s','MarkerSize',10,...
'MarkerEdgeColor','red',...
'MarkerFaceColor',[1 .6 .6], 'color' 'r') % 'color' added
  1 件のコメント
Yu Li
Yu Li 2018 年 12 月 11 日
Thank you very much,the problem has been solved.

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

その他の回答 (2 件)

Saurabh Kotian
Saurabh Kotian 2018 年 12 月 11 日
You can set the line color after you plot it.
x = linspace(0,10,50);
y = sin(x);
h = plot(x,y,'-s','MarkerSize',10,...
'MarkerEdgeColor','red',...
'MarkerFaceColor',[1 .6 .6])
set(h,'Color','g');
  1 件のコメント
Yu Li
Yu Li 2018 年 12 月 11 日
Thank you very much, your answer also works.

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


Gareth
Gareth 2018 年 12 月 11 日
There are a couple of ways to solve this (I am using R2018b):
plot(x,y,'-s','MarkerSize',10,'Color','red',...
'MarkerEdgeColor','red',...
'MarkerFaceColor',[1 .6 .6])
Or if you prefer you can:
myhandle = plot(x,y)
And then use the myhandle to change the properties accordingly.

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by