Set MarkerFaceColor to be filled by default

67 ビュー (過去 30 日間)
John
John 2018 年 12 月 5 日
コメント済み: Steven Lord 2024 年 4 月 19 日 13:37
How can MarkerFaceColor be set to take on whichever color MarkerEdgeColor is by default?

回答 (2 件)

Astha Singh
Astha Singh 2018 年 12 月 12 日
Hello John,
This can be achieved by setting the line properties in the plot.
The 'MarkerEdgeColor' is the outline color of the marker. Its default value is 'auto', which uses the same color as the 'Color' property of the line. This value can be accessed using the dot notation on the line object.
The following is an example code snippet:
l = plot(x,y,'o');
l.MarkerFaceColor = l.Color;
  1 件のコメント
Marguerite Bienia
Marguerite Bienia 2024 年 4 月 19 日 7:49
this does not work, the filling is white in my case

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


Image Analyst
Image Analyst 2024 年 4 月 19 日 12:47
Try this:
x = 1:5;
y = rand(1,5);
l = plot(x,y,'o', 'MarkerSize', 30);
l.MarkerFaceColor = [.6, .2, .9]; % Change color from default to purple
Also see colororder
  3 件のコメント
Image Analyst
Image Analyst 2024 年 4 月 19 日 13:35
You can also set the color in the plot call
myColor = [.6, .2, .9]; % Change color from default to purple
for k = 1 : whatever
x = whatever
y = whatever
plot(x, y, 'o', 'MarkerSize', 30, 'Color', myColor);
end
Or you can use scatter and use one of the inputs to specify the colors for all of the datasets in advance.
Steven Lord
Steven Lord 2024 年 4 月 19 日 13:37
You can set the MarkerFaceColor inside the plot call just like you can set Marker, MarkerEdgeColor, etc. They're all properties of the line.
c = [0.25 0.5 0.25];
plot(1:10, 1:10, ...
'Color', 'r', ... red line
'Marker', 's', ... square markers
'MarkerEdgeColor', c, ... marker edges are green
'MarkerFaceColor', 1-c); % marker faces are purple

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

カテゴリ

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

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by