Adding non-fixed labels to UIAxes
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello, again !
I designed an app that has dates on x-axis and values on y-axis. As i expected, there are some drastical changes on the values between two following dates. So, i want to add the reason of critical changes onto the line between these two points like "Something happened in this section.". I tried to add labels and assign tooltips to them but the labels are sliding by zooming in/out as they have fixed position. Hence i'm trying to find a way that provides the information box wherever the two points are. Additionally, if there is a method that i also can handle the visibility of this information box, i would appreciate more.
Thanks.
0 commentaires
Réponse acceptée
Dinesh
le 29 Déc 2023
Hi Mehmet.
To address the issue of adding interactive annotations to your app's plot that align with significant data changes and remain positioned correctly during zooming or other operations, use MATLAB's "text" function. This function allows you to specify the position of your annotations in data coordinate terms, ensuring they move appropriately with your plot. You can also manage the visibility of these annotations by toggling the 'Visible' property of the text object based on user interaction or specific app conditions.
The following is an example:
x = 1:10; % Sample date points
y = rand(1, 10) * 20; % Sample values
figure;
plot(x, y, '-o');
idx1 = 5; % Index of first date point
idx2 = 6; % Index of second date point
% Calculate midpoint so that text can be placed there
midX = mean([x(idx1), x(idx2)]);
midY = mean([y(idx1), y(idx2)]);
% Use 'text' to create the label
txt = 'Something happened in this section';
text(midX, midY, txt, 'HorizontalAlignment', 'center', 'BackgroundColor', 'white');
The text's position is not fixed when you zoom in/out in this case. The label will always be between these 2 date points.
The following is the link to the documentation:
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Axis Labels dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!