필터 지우기
필터 지우기

Change line type when figure handle is known

조회 수: 12 (최근 30일)
J
J 2011년 5월 10일
I have created a plot in a figure window. I want to change the line type to circles.
I know the figure handle. Let's say it's gcf. Can I use this to modify the plot or line? I figure they are children of the figure so I should be able to use
set(gcf, child:plot, child:line, 'o')
... something along those lines. I'm a newbie. How should this look?

채택된 답변

Arnaud Miege
Arnaud Miege 2011년 5월 10일
Does that do what you want?
t = 0:0.1:10;
y = sin(t);
h = plot(t,y);
set(h,'Marker','o');
set(h,'LineStyle','none');
Arnaud
  댓글 수: 1
Arnaud Miege
Arnaud Miege 2011년 5월 10일
PS: you need the plot handle, not the figure handle:
h_fig = gcf;
h_axes = gca;
h_plot = get(h_axes,'Children')

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Patrick Kalita
Patrick Kalita 2011년 5월 10일
Starting with a figure handle f, getting its Children property will most often return an axes handle a.
a = get(f, 'Children');
You can verify what it is by looking at a's Type property:
>> get(a, 'Type')
ans =
axes
So far so good. Now the line will be a child of the axes. So get the Children property of a ...
L = get(a, 'Children')
... and verify the Type:
>> get(L, 'Type')
ans =
line
Now you can set the Marker property of the line:
set(L, 'Marker', 'o')
This documentation page is a good reference which explains which objects can be children of other objects, and which properties objects have.
  댓글 수: 2
Patrick Kalita
Patrick Kalita 2011년 5월 10일
I should point out that Arnaud's answer is a better solution. It is always preferable to hold on to the handle that a function (like plot) returns, rather than diving through the 'Children' property of objects. This method should only be used when absolutely necessary (i.e. you use a function that doesn't return a handle).
Matt Fig
Matt Fig 2011년 5월 10일
An alternative would be to use FINDOBJ.
L = findobj(gcf,'type','line')

댓글을 달려면 로그인하십시오.


Matt Fig
Matt Fig 2011년 5월 10일
You could also try this tool, which allows you to make arbitrary changes with a mouse-click:
The preview image shows the options available when you right click on a line.

카테고리

Help CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by