MATLAB Answers

Scatter plot changes markers when using 'filled' option

214 views (last 30 days)
njj1 on 10 Feb 2020
Edited: Adam Danz on 10 Feb 2020
I am using scatter plot and for some reason when I use the "filled" option, the marker shapes change to squares. Here is an example of my code:
scatter(T{:,i},height(T):-1:1,20, 'filled')
In this case, I am just plotting the entries for a particular table column, T{:,i}, against the row numbers. When I execute this code, the marker shapes are squares. However, if I use the longer form, I get filled circles:
scatter(T{:,i},height(T):-1:1,20, 'MarkerFaceColor', lines(1))
The drag here is that I have to know which color I am using rather than simply having the markers automatically filled with the matching color. Has anyone else ever experienced this?
Adam Danz
Adam Danz on 10 Feb 2020
I moved my comment as an answer and expanded upon it. Long story short, the marker edges are included when you use the "MarkerFaceColor' and those edges smooth out the rigid scatter points.

Sign in to comment.

Accepted Answer

Adam Danz
Adam Danz on 10 Feb 2020
Edited: Adam Danz on 10 Feb 2020
The shape of "filled" scatter points aren't necessarily changing to a square, although at some marker sizes it does appear to be a square. Change the SizeData property and you'll see that "filled" markers change shape. The marker size for scatter points specify the marker area in points squared which may partially explain the lack of consistency in shape. Monitor resolution may also factor in.
The reason the markers may appear less rigid when MarkerFaceColor is applied is because the marker edges are also applied and they smooth out the rigidity.
This demo below compare 5 scatter point sizes across the three conditions. You'll notice that the "filled" and the "MarkerFaceColor without edges" appear the same.
% Reproduce the plot above.
hold on
markerSizes = 20:20:100;
scatter(1:5, ones(1,5)+2, markerSizes, 'b', 'filled')
scatter(1:5, ones(1,5)+1, markerSizes, 'MarkerFaceColor', 'b')
scatter(1:5, ones(1,5)+0, markerSizes, 'MarkerFaceColor', 'b','MarkerEdgeColor', 'none')
xlim([-4, 10])
% use FEX function:
labelpoints(1:5, ones(1,5)+2, markerSizes, 'N', 0.1)
labelpoints(1, [3,2,1], {'filled','MarkerFaceColor', 'MarkerfaceColor w/o edges'}, 'W', 0.2)

More Answers (0)


Community Treasure Hunt

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

Start Hunting!