Clear Filters
Clear Filters

plotting with text display

2 views (last 30 days)
David C
David C on 8 Jun 2012
I have a multi day graph, that I must present in 12 hour blocks.
Currently, my code creates the graph, labels the graph, and places several annotations on the graph with the text function at the appropriate places. Then the code continues on to "parse" the figure into the 12 hour intervals by setting the x-lim in a for loop.
Everything works fine and dandy except for the text annotations. These things are carried over from one part to another and end up outside a particular parsed graph. For example, if there was an annotation at the end of part 1 of the graph, it would show up again in part 2, except it would outside the axis lines.
does anyone have any clever suggestions as to how to get rid of the phantom annotations on the parts of the graph where they don't belong?
Thanks in advanced!

Accepted Answer

Image Analyst
Image Analyst on 9 Jun 2012
I guess you'd have to capture the handles and location of each text object as you place it, and when it comes time to show interval "n" of the graph, you'd set the visible property to off of all the text handles that are not supposed to be shown when you're showing that interval.
hText1 = text(x1, y1, 'blah');
textHandles(1).handle = hText1;
textHandles(1).x = x1;
and so on for all the text controls you create. Later when you're showing an interval:
% Loop over all text controls, either showing or hiding depending
% on whether it is located inside interval "n" or not.
for k = 1 : length(textHandles)
if textHandles(k).x > currentX1Interval && textHandles(k).x < currentX2Interval
% It is supposed to show.
set(textHandles(1).handle, 'visible', 'on');
else
% It is not supposed to show.
set(textHandles(1).handle, 'visible', 'off');
end
end
where currentX1Interval to currentX2Interval define the x range of the interval you want to show at that time.
  2 Comments
David C
David C on 12 Jun 2012
I tried to do as you said, however, there seems to be no handle for the text function that determines the x-axis location.
I believe the only thing is the "PointerLocation" handle which is determined by x by y pixels? please correct me if i'm wrong.
Walter Roberson
Walter Roberson on 12 Jun 2012
hText1 = text(x1, y1, 'blah');
xyz = get(hText1, 'Position');
x = xyz(1); y = xyz(2);

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!