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

422 次查看(过去 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
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 CenterFile Exchange 中查找有关 Line Plots 的更多信息

产品


版本

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by