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!

回答(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
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