Update multiple plot fills using XData and YData
显示 更早的评论
I was doing the following to generate n filled areas on a graph between n pairs of upper and lower curves.
for i = 1:n
x = % x values, function of i
y1 = % upper curve, function of i
y2 = % lower curve, function i
fill([x fliplr(x)], [y2 fliplr(y1)]);
hold on
end
However, I need to be able to plot an empty fill, and then add the fills in a loop using XData and YData, like this (I know the following won't work, but schematically)
h = fill(nan, nan, 'r');
for i = 1:n
x = % x values, function of i
y1 = % upper curve, function of i
y2 = % lower curve, function i
h(i).XData = [x fliplr(x)]
h(i).YData = [y2 fliplr(y1)]
end
What's the proper way to do this? My need for this stems from using scrollplots, which doesn't work well with re-plotting the data, but instead you need to update the data of the existing plot if changes are made. Any ideas?
1 个评论
Jan
2018-1-29
It is not clear, what you want to do. What is "an empty fill"? "Doesn't work well" is no clear description of the problem you have.
回答(1 个)
[EDITED] Sorry, I've posted some nonsense code here by accident. Thanks, Walter. I do not remove the answer to keep the valuable comments.
8 个评论
Walter Roberson
2018-1-29
This attempts to set the XData and YData of placeholder objects.
fill() returns patch objects, so you could create empty patch objects. But you could probably just loop that fill(nan,nan) to create distinct patch objects that you could later set the XData and YData for.
Jeremy
2018-1-29
Walter Roberson
2018-1-29
Save a vector of the handles of fill(nan,nan) and adjust each with the appropriate data.
If you had a fixed number of plots then another possibility is to use surf() instead of fill(), and put the appropriate variables describing each into the base workspace, and then call refreshdata() . That triggers graphics items that have an XDataSource or YDataSource or ZDataSource to look in the base workspace for updates to the variables used to construct them, and do the appropriate graphics changes. This does not happen to be supported by patch() but is supported by surface objects.
... but in my opinion changing the XData and YData properties directly is cleaner and more flexible.
Jeremy
2018-1-30
Walter Roberson
2018-1-30
Make sure you "hold on" before that p3 call.
Jeremy
2018-1-30
Jeremy
2018-1-30
Walter Roberson
2018-1-30
p3(1, 1:3) = fill(nan, nan, 'r') would assign the same patch handle to those elements.
The easiest fix is to loop. But you could use an implicit loop such as
arrayfun(@(~) fill(nan,nan), 1:3)
类别
在 帮助中心 和 File Exchange 中查找有关 Annotations 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!