How do I plot arrays with filled markers using the default marker colors?

67 ビュー (過去 30 日間)
How can I plot arrays with markers in the default marker colors but with filled markers? Plot(x,'o') plots empty circles in default colors for each column of x. I want the same with filled circles.

採用された回答

MathWorks Support Team
MathWorks Support Team 2018 年 2 月 15 日
For this example, I have specified the array "x" to be an arbitrary 4x4 array of random numbers; however, you can specify it as your own array. You can use the "MarkerFaceColor" and "Color" properties of the plotted line or lines in order to fill in the markers with the same color as the default marker edge color.
Try the following sample code:
x = 1:4; 
y = rand(4); 
figure 
h = plot(x, y, 'o'); 
set(h, {'MarkerFaceColor'}, get(h,'Color')); 
The "Color" property of a line stores the RGB value of that line, whether it is a default or custom-set value. You can use the "get" function in order to retrieve this value. Next, you can use the "set" function in order to apply this RGB value to the line's "MarkerFaceColor" property, which determines the fill color of the marker.
If your plot has multiple lines, then "get" will return a cell array of RGB values corresponding to the "Color" property of each line. Similarly, "set" will need to use cell arrays in order to set the RGB values of the "MarkerFaceColor" of each line, so we must input both our "MarkerFaceColor" property and the corresponding RGB values from "get" as cell arrays.
You can also use scatter function with 'filled' option if you just want to plot a marker.
x = 1:4;
y = rand(4);
figure
hold
for n = 1:4
scatter(x,y(:,n),'filled')
end
 

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by