Plot event listeners to update text along curve

조회 수: 1 (최근 30일)
Ben Mercer
Ben Mercer 2021년 9월 21일
편집: Krishna Sutar 2022년 1월 27일
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 :-)

답변 (1개)

Krishna Sutar
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');
Please refer to axis documentation to understand its input arguments and functions.

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by