Code covered by the BSD License  

Highlights from
tmark.m

4.0

4.0 | 1 rating Rate this file 7 Downloads (last 30 days) File Size: 10.42 KB File ID: #25767
image thumbnail

tmark.m

by J. Caspar

 

06 Nov 2009

Annotation class which generates peak marks that are automatically updated when axes are rescaled.

| Watch this File

File Information
Description

 TMARK Tickmark annotation class for 2-D plots.
 
 Usage: t = tmark([x,y],varargin)
            t = tmark(ginput(1),'color','r','label','Peak 1')
 
 Tmarks are user positioned annotation objects whos position's remain fixed
 in axes units when plot axes are rescaled (unlike standard annotation
 objects whos positions are not updated as a result of axis rescaling).
 Tmarks are intended to be used to label features like peak positions in
 spectroscopic data. The functionality is like the "Pin to Axes" function
 except tmarks are available from the command line and in scripts. Tmarks
 can be created either from the command line or interactively using
 tmulti.m. Once created tmark's properties may be edited via either a
 context menu (right click on the mark) or via the commaqnd line using the
 utility routines tedit.m, tfind.m and trestore.m, or using the set
 formalism as for other types of handle objects.
 
 Known Limitations:
      Currently when a figure containing tmarks is saved to disk and then
 reloaded the tmarks become 'dormant' (i.e. they will no longer be
 repositioned as a result of axis rescaling). The utility routine
 trestore.m will revive the tmarks subject to some limitations - in
 particular tmarks in figures containing more than one subplot may end up
 being attached to the wrong axis. See the help info in trestore.m for
 details and a workaround for this problem.
 
 Example
 
  %Plot some data
    x = 0:0.01:2*pi;
    plot(x,sin(x))
    ylim([-1.5 1.5])
  
  %Add a tmark from the command line.
 
    tm = tmark([pi,sin(pi)],'color','r','label','Tmark')
  
  %Modify the settings for the mark. Editing is also available by right
  %clicking on the mark with the mouse.
 
    set(tm,'resolution',0.001) %increase the resolution
    set(tm,'textonly',1) %display only the text label
  
  %Create marks interactively on the current figure using ginput. Left click
  %to create marks. Press escape to exit.
 
    tm = tmulti %tm will be a cell array of tmark handles.
 
 End example
 
 
 Required Inputs
 ===============
    pos .................... [x,y] coordinate of mark in experimental units
 
 Optional Inputs
 ===============
    label .................. Text label to be displayed in addition to the
                    x-coordinate of the mark.
    resolution ............. The numeric resolution of the displayed
                    position. For examples, a resolution of 1
                    will display the position rounded to the
                    nearest integer, a value of 0.02 will give the
                    position rounded to the nearest 0.02. When
                    tmarks are created they script picks the
                    initial resolution based upon the xaxis range
                    as reported by xlim.
    textonly ............... If set to 1 only the label text is displayed
                    (no x-axis value). Default = 0 (label and
                    x position displated).
    color .................. The color of the mark.
    fontsize ............... Font size for the mark.
    hdlAx .................. The handle of theaxis to which the tick mark
                    is attached.
 
 Outputs
 =======
    TM ..................... Tickmark object (tmark)
 
 See also: tedit tfind trestore tmulti

Acknowledgement - this script relies on a modified version of dsxy2figxy.m which appears as an example in the Matlab documentation.

MATLAB release MATLAB 7.9 (2009b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
26 Oct 2010 Kurt

Well thought out added functionality for adding text labels with leaders to a plot from a MATLAB script. Having the labels follow the selected point when zooming and panning is invaluable.

However, I found that it doesn't properly place the text markers when the "axis equal" command is applied (using release 2010B).

Mathworks should consider adding this type of functionality to their scripting language instead of just supporting pinned labels from the interactive figure menu.

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
graphics annotation label J. Caspar 09 Nov 2009 10:40:31

Contact us at files@mathworks.com