How can I get the plot for a saved figure?
11 views (last 30 days)
Show older comments
Hello,
Long ago I've saved a figure with 50 sets of points (only 15 could be shown in the legend below). Now I want to edit the marker size of the data, but I don't want to select all the 50 sets by hand. Is there any other way to do it? People often use the variable p as in this command:
x = 1:10;
p = plot(x,x^2,'-k*', x,x^3,'-ko', x,x^4,'-k' )
p(1).MarkerSize = 20;
p(2).MarkerSize = 12;
However, as I am using a saved figure, I don't have this p variable. Is there another way of getting it? If there was a command 'gfc' (get current figure) but for the data itself it would be of great help to me.
0 Comments
Accepted Answer
Rik
on 25 Apr 2019
Edited: Rik
on 25 Apr 2019
The line objects are probably in the Children property of your axes, which is itself a child of the figure (but so is the legend on older releases).
%create example figure
figure(1),clf(1)
for n=1:50
plot(rand,rand,'.')
hold on
end
X=[0.5 0.5 0.1 0.1];Y=[0.1 0.5 0.5 0.1];
patch('XData',X,'YData',Y)
%find all Line objects in the current axes
object_list=findobj('Parent',gca,'Type','Line');
%set marker size
set(object_list,'MarkerSize',20);
5 Comments
Adam Danz
on 4 Oct 2020
Thanks, Martim. I just updated my answer > 1 yr later just to add the screen shot. I came across my answer today and I didn't understand what I meant by "white arrow tool" so I thought I'd un-confuse myself and any future visitors 😅.
Rik's answer is an automatted approach whereas mine is manual. I favor his approach unless there's a need to manually change something in the figure.
More Answers (2)
Adam Danz
on 25 Apr 2019
Edited: Adam Danz
on 4 Oct 2020
"If there was a command 'gfc' (get current figure) but for the data itself it would be of great help to me."
Open the .fig file in matlab. Use the white arrow tool ("Edit Plot") to select a single data point to make that set of data active.
Then go to the command window and type
h = gco; %get current object handle
Then you can change the object properties such as markersize.
h.MarkerSize = 20;
2 Comments
Steven Lord
on 4 Oct 2020
If you need to find the handles to all items that have a specific property (like MarkerSize or SizeData) calling findobj (or findall) with the '-property' option and the name of the property will give you the handles of all the objects with that property.
h = plot(1:10, 's-'); % Has a property MarkerSize but not SizeData
hold on
h2 = scatter(1:10, 10:-1:1, 25); % Has a property SizeData but not MarkerSize
objWithMarkerSize = findobj(gcf, '-property', 'MarkerSize'); % line h
objWithMarkerSize.MarkerSize = 20;
objWithSizeData = findobj(gcf, '-property', 'SizeData'); % scatter plot h2
objWithSizeData.SizeData = 100;
3 Comments
Adam Danz
on 4 Oct 2020
@Martim, Rik's answer also uses findobj. Steven Lord's answer is different from Rik's in two ways.
- He uses -property instead of type. As SL states, -property has a wider span than type since many classes have the same properties.
- He mentions findall which can access handles with HandleVisibilty set to off.
For comparison, my answer is a manual approach that requires the user to manually select objects by clicking on them whether their handles are visible or not (but requires that the object itself is visible). If object selection should be programmatic, Rik's or Steven Lord's answers are the way to go. If the object selection should be manual, you could use any of the approaches here but if only a few objects are needed, somtimes clicking on them is easiest.
See Also
Categories
Find more on Specifying Target for Graphics Output in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!