Plot event listeners to update text along curve

1 Ansicht (letzte 30 Tage)
Ben Mercer
Ben Mercer am 21 Sep. 2021
Bearbeitet: Krishna Sutar am 27 Jan. 2022
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 :-)

Antworten (1)

Krishna Sutar
Krishna Sutar am 26 Jan. 2022
Bearbeitet: Krishna Sutar am 27 Jan. 2022
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.

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by