How to only replot part of a graph?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi I'm currently plotting cubic bezier splines.
My aim is that every time I move a control point, the bezier curve moves accodingly. TO achieve this, for each control point, I plotted a ROI point with the drawpoint() function. I have a listener at each point:
function allevents(src,evt)
% Update the control point i
newPos = evt.CurrentPosition;
controlPoints(i,:) = [newPos(2),newPos(1)];
% Recompute the Bezier curve
[X,Y] = computeBezierCurve(controlPoints);
% Redraw the curve
cla reset
plot(X,Y)
% Redraw ROIs
drawPoint()
end
If I don't call 'cla reset', the new curve would overlap the original curve. However if I reset cla, I would need to redraw all control points, this process then doesn't look smooth at all, especially when the curve is compliacated.
Is there a way to only replot the changed point and the curve around it, but keeping the reset the same, so this dragging looks smooth?
Thank you very much.
0 comentarios
Respuestas (1)
Stephen23
el 17 de Oct. de 2020
Editada: Stephen23
el 17 de Oct. de 2020
"Is there a way to only replot the changed point and the curve around it,"
Yes: you just need to change the XData and YData values of the line object:
Forget about high-level commands like plot if you want to have this level of control, the solution is to simply create and manipulate graphics object properties:
I strongly recommend that you obtain and refer to every object using explicit handles (i.e. do NOT rely on gcf, gca, etc), e.g.:
lnh = plot(..);
..
set(lnh, 'XData',[..], 'YData',[..]);
If you are using a MATLAB version >=R2015b, then you can refer to object properties using dot syntax, which allows you to "only replot the changed point" exactly as you request, e.g. to change the third point on the line to 2:
lnh.YData(3) = 2;
0 comentarios
Ver también
Categorías
Más información sobre Graphics Object Programming en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!