How to add pattern fill to markers in scatter plot?

조회 수: 5 (최근 30일)
Elmira Ramazanova
Elmira Ramazanova 2024년 11월 7일
댓글: Elmira Ramazanova 2024년 11월 11일
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