How to add pattern fill to markers in scatter plot?

11 次查看(过去 30 天)
I want to add pattern fill to markers in scatterplot. It can easily be done in Excel (example befow). Is it possible to reproduce this in Matlab? I have seen user-defined functions in the file exchange like hatchfill2 but they seem to work well on bar plots and patch objects but not markers in scatter plot.

采纳的回答

Walter Roberson
Walter Roberson 2024-11-7
There is unfortunately no simple way to add hatch filling.
To apply hatch filling, there are two possibilities:
  1. Create sample copies of the filled area, centered on (0,0) and extending to [-1, 1] . Now create one hg transform object for each destination location, and copyobj() the sample object to parent it to the hg transform object, and set the Matrix property of the hg transform object to scale and translate it to the desired position. This approach has the advantage of only having to figure out the hatch pattern once per different hatch. This approach has the disadvantage of requiring separate copies of the objects and seperate hg transform objects for each desired location.
  2. Create extensive Vertices and Faces lists combining all of the hatch objects to be created, and create a single patch() object that combines information for all of the hatches together. This approach has the advantage of only using a single graphics object. This approach has the disadvantage of making it more difficult to program the hatch objects and to program different colors for the different objects.
  2 个评论
Adam Danz
Adam Danz 2024-11-8
3. A workaround to providing a hatch is to duplicate the scatter markers with + - | . x * symbols. This won't unfortunately, show up in the legend, though.
hold on;
s = scatter(rand(1,20),sort(rand(1,20)),randi(50,1,20)+40, 'c','filled','MarkerEdgeColor','k');
s2 = copyobj(s,s.Parent);
s2.Marker = '+';
p = scatter(rand(1,20)+.8,sort(rand(1,20))+.3,randi(50,1,20)+40, 'm','filled','MarkerEdgeColor','k');
p2 = copyobj(p,p.Parent);
p2.Marker = '.';
Elmira Ramazanova
Elmira Ramazanova 2024-11-11
This workaround with + - | . x * symbols helped. Thank you.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Object Properties 的更多信息

产品


版本

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by