Azzera filtri
Azzera filtri

How can I get the plot for a saved figure?

19 visualizzazioni (ultimi 30 giorni)
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.
ex_figure.png

Risposta accettata

Rik
Rik il 25 Apr 2019
Modificato: Rik il 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 Commenti
Martim Zurita
Martim Zurita il 4 Ott 2020
Thanks, Adam. This is a very good solution!
Adam Danz
Adam Danz il 4 Ott 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.

Accedi per commentare.

Più risposte (2)

Adam Danz
Adam Danz il 25 Apr 2019
Modificato: Adam Danz il 4 Ott 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 Commenti
Martim Zurita
Martim Zurita il 25 Apr 2019
Hi, Adam
Thank you for your answer. The problem is that, with the solution you described, I would still have to select all the 50 sets of that by hand.
Adam Danz
Adam Danz il 25 Apr 2019
Yeah, with 50 objects, Rik's solution is definitely better.

Accedi per commentare.


Steven Lord
Steven Lord il 4 Ott 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 Commenti
Adam Danz
Adam Danz il 4 Ott 2020
@Martim, Rik's answer also uses findobj. Steven Lord's answer is different from Rik's in two ways.
  1. He uses -property instead of type. As SL states, -property has a wider span than type since many classes have the same properties.
  2. 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.
Martim Zurita
Martim Zurita il 5 Ott 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 :)

Accedi per commentare.

Categorie

Scopri di più su Graphics Object Programming in Help Center e File Exchange

Prodotti


Release

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by