Data space to figure units conversion

A utility function to simplify use of annotation function
13,3K téléchargements
Mise à jour 29 juin 2023

The annotation function, which allows you to programmatically add a wide range of annotations to your figure, requires coordinates to be specified in normalized figure units. I have found that I almost always want to specify my annotations in data space (i.e., based on the values of data displayed in an axes).
This utility function converts coordinates in data space into normalized figure coordinates, for input to annotation. Some annotations require you to specify (x,y) pairs, while others require a 4 element position vector. This function supports both syntaxes.

Here's a simple example:
% Create some data
t = 0:.1:4*pi;
s = sin(t);

% Add an annotation requiring (x,y) coordinate vectors
plot(t,s);ylim([-1.2 1.2])
xa = [1.6 2]*pi; % X-Coordinates in data space
ya = [0 0]; % Y-Coordinates in data space
[xaf,yaf] = ds2nfu(xa,ya); % Convert to normalized figure units
annotation('arrow',xaf,yaf) % Add annotation

Note: I believe annotation was introduced in MATLAB 7.

Citation pour cette source

Michelle Hirsch (2024). Data space to figure units conversion (https://github.com/michellehirsch/MATLAB-Dataspace-to-Figure-Units), GitHub. Récupéré le .

Compatibilité avec les versions de MATLAB
Créé avec R2006a
Compatible avec toutes les versions
Plateformes compatibles
Windows macOS Linux
Catégories
En savoir plus sur Image Filtering and Enhancement dans Help Center et MATLAB Answers

Community Treasure Hunt

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

Start Hunting!

Les versions qui utilisent la branche GitHub par défaut ne peuvent pas être téléchargées

Version Publié le Notes de version
1.2.0.0

Moved source to GitHub.

1.1.0.0

Updated copyright.

1.0.0.0

Pour consulter ou signaler des problèmes liés à ce module complémentaire GitHub, accédez au dépôt GitHub.
Pour consulter ou signaler des problèmes liés à ce module complémentaire GitHub, accédez au dépôt GitHub.