Plot event listeners to update text along curve
3 次查看(过去 30 天)
显示 更早的评论
Hi all,
I'm attempting to create a handy function which creates a text label along a curve on a plot. E.g.
One of the challenges of this is that the Rotation property of text objects is in terms of screen coordinates, not parent axes coordinates, which means that:
A) you must transform to screen coordinates before calculating the text angle.
B) If the figure is resized or interacted with (e.g. zoom), the text angle will need to be updated.
I've tried to hack my way around the above issues using event listeners to update the angle when the axes changes size, and I've got 75% of the way there. I've attached my functions and a test script.
What I'm missing is the list of properties at the axes/figure level that I need to create listeners for. I was hoping there might be a convenient axes redraw event so I don't need to add listeners for every separate parameter that may possibly change (possibly resulting in multiple callback calls). So far I'm listening for axes.XLim, axes.YLim, axes.ZLim, axes.Position. I tried listening for figure.Position but apparently this property has a SetObservable attribute = false.
Thanks in advance :-)
0 个评论
回答(1 个)
Krishna Sutar
2022-1-26
编辑:Krishna Sutar
2022-1-27
I understand that when the figure axis size is changed the change in angle of the text is not reflected as per the axes.
Use of axis equal sets the XLimMode and YLimMode appropriately so that the axes fill its allotted space within the parent figure or other container.
x = 0:(2*pi/32):2*pi;
y = sin(x);
figure
hLine = plot(x,y);
axis equal;
h = textOnCurve('sine wave', hLine, 0.125, 'verticalalignment', 'top');
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Object Properties 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!