Change all Plot MarkerSizes at once?

조회 수: 12 (최근 30일)
Felicia Brimigion
Felicia Brimigion 2021년 1월 6일
댓글: Felicia Brimigion 2021년 1월 7일
I have about 7 subplots, each with four plots)
Each plot has 8-16 separate plots, I was wondering if there is any way to make a blanket statement of sorts, to change the markersize of each point to 10, without having to do ,'MarkerSize',10 after every single (x,y) and (a,b) pair:
plot([x([2:4],:),y([2:4],:),'.',x([5:8],:),y([5:8],:),'.',x([9:11],:),y([9:11],:),'.', ...
a([2:4],:),b([2:4],:),'.',a([5:8],:),b([5:8],:),'.',a([9:11],:),b([9:11],:),'.')
These need to be indexed separately like this for unrelated legend reasons. This type of plotting occurs for every single plot, in each subplotso it would be quite tedious to have to copy/paste:
,'MarkerSize',10
after every single pair for every plot for every subplot.
Thank you!

답변 (1개)

Steven Lord
Steven Lord 2021년 1월 6일
x = 0:360;
h = gobjects(1, 5);
ax = axes;
axis([0 360 -1 1]);
hold on
for k = 1:5
h(k) = plot(x, sind(k*x), 'o-', 'MarkerIndices', 1:6*k:361, 'UserData', k);
end
Now let's find all the objects in the axes that have a MarkerSize property.
h2 = findall(ax, '-property', 'MarkerSize');
Now change them.
for whichone = 1:numel(h2)
this = h2(whichone);
oldMS = this.MarkerSize;
newMS = oldMS*this.UserData;
this.MarkerSize = newMS;
end
I used a for loop because I wanted to give each line a different MarkerSize. If you wanted to change them all to the same value, use set. Since I previously changed the MarkerSize property, here I'll change LineStyle instead.
set(h2, 'LineStyle', '--')
  댓글 수: 2
Stephen23
Stephen23 2021년 1월 6일
Oooh, I like that. TMW should release a line of MATLAB-branded gift-wrapping paper. Or wallpaper.
Felicia Brimigion
Felicia Brimigion 2021년 1월 7일
Thank you so much! I will give that a try!!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by