How can I get the plot for a saved figure?

33 ビュー (過去 30 日間)
Martim Zurita
Martim Zurita 2019 年 4 月 25 日
コメント済み: Martim Zurita 2020 年 10 月 5 日
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

採用された回答

Rik
Rik 2019 年 4 月 25 日
編集済み: Rik 2019 年 4 月 25 日
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 件のコメント
Martim Zurita
Martim Zurita 2020 年 10 月 4 日
Thanks, Adam. This is a very good solution!
Adam Danz
Adam Danz 2020 年 10 月 4 日
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.

サインインしてコメントする。

その他の回答 (2 件)

Adam Danz
Adam Danz 2019 年 4 月 25 日
編集済み: Adam Danz 2020 年 10 月 4 日
"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 件のコメント
Martim Zurita
Martim Zurita 2019 年 4 月 25 日
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 2019 年 4 月 25 日
Yeah, with 50 objects, Rik's solution is definitely better.

サインインしてコメントする。


Steven Lord
Steven Lord 2020 年 10 月 4 日
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 件のコメント
Adam Danz
Adam Danz 2020 年 10 月 4 日
@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 2020 年 10 月 5 日
@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 :)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGraphics Object Programming についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by