Use refreshdata with voronoi plots

1 次查看(过去 30 天)
dakne
dakne 2019-2-12
How can I use refreshdata to update a graph genererated with the voronoi function?
I tried:
h = voronoi(peakx,peaky,'w');
set(h,'YDataSource','peaky','XDataSource','peakx')
which I wanted to update after some calculations:
refreshdata(h,'caller')
drawnow
This does not work because voronoi has no 'YDataSource' or - 'XDataSource' property.
I also tried to:
[vx,vy] = voronoi(peakx,peaky);
h = plot(peakx,peaky,'r+',vx,vy,'b-');
followed by
set(h,'YDataSource','peaky','XDataSource','peakx')
and
refreshdata(h,'caller')
drawnow
which also does not work because the voronoi function is not updated.
Is there a way to do this?

回答(1 个)

Agnish Dutta
Agnish Dutta 2019-3-7
I don't think voronoi was designed to support the refreshdata workflow.
voronoi is just a function which plots and returns handles. voronoi returns a handle h(1) to the original (x,y) data (plotted as markers) and another handle h(2) to the Voronoi edge lines which depend on (x,y):
x = gallery('uniformdata',[1 10],0);
y = gallery('uniformdata',[1 10],1);
h = voronoi(x,y)
h =
2×1 graphics array:
Line
Line
If you set the data source for the original (x,y) data, the Voronoi edge lines don't react to it when you call refreshdata:
h(1).XDataSource = 'x';
h(1).YDataSource = 'y';
x = 2*x;
y = 2*y;
refreshdata % the Voronoi edge lines will be out of sync
You're better off calling voronoi again on the new data to get a plot where the lines are in sync.

类别

Help CenterFile Exchange 中查找有关 Voronoi Diagram 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by