Change all Plot MarkerSizes at once?
조회 수: 12 (최근 30일)
이전 댓글 표시
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!
댓글 수: 0
답변 (1개)
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
2021년 1월 6일
Oooh, I like that. TMW should release a line of MATLAB-branded gift-wrapping paper. Or wallpaper.
참고 항목
카테고리
Help Center 및 File Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!