MATLAB Answers

How can I get the plot for a saved figure?

39 views (last 30 days)
Martim Zurita
Martim Zurita on 25 Apr 2019
Commented: Martim Zurita on 5 Oct 2020
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.

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
for n=1:50
hold on
X=[0.5 0.5 0.1 0.1];Y=[0.1 0.5 0.5 0.1];
%find all Line objects in the current axes
%set marker size
Adam Danz
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.

Sign in to comment.

More Answers (2)

Adam Danz
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;
Adam Danz
Adam Danz on 25 Apr 2019
Yeah, with 50 objects, Rik's solution is definitely better.

Sign in to comment.

Steven Lord
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;
Martim Zurita
Martim Zurita on 5 Oct 2020
@Adam, oh, it's true! Riks's answer also uses findobj. Since it has been more than one year since the question, I have forgotten.
Thanks again for the attention and explanation :)

Sign in to comment.




Community Treasure Hunt

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

Start Hunting!