How do I plot arrays with filled markers using the default marker colors?
69 views (last 30 days)
Show older comments
MathWorks Support Team
on 15 Feb 2018
Answered: MathWorks Support Team
on 15 Feb 2018
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.
Accepted Answer
MathWorks Support Team
on 15 Feb 2018
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 Comments
More Answers (0)
See Also
Categories
Find more on Scatter Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!