File Exchange

image thumbnail

Fractional position on plots

version 1.0 (8.17 KB) by

Position text or data relative to the frame of a plot, not necessarily relative to the data.

1 Download


View License

Functions xput, yput, and zput return the respective x, y, or z coordinate of a given fraction of the full x, y, or z range of a plot. These are useful if you have several plots with different data ranges, but you want text or a marker to appear in the same position relative to the frame of each plot. Input argument is simply the fractional linear dimension from 0 to 1.

x = -40:120;
y = x + 10*sin(x);
plot(x,y); hold on
text(xput(.1),yput(.9),'this is an example','fontsize',14)
text(xput(.6),yput(.25),'another example!','fontsize',16)
box off

Comments and Ratings (2)

Chad Greene

Chad Greene (view profile)

Jan, that's a great suggestion! I was not aware of the normalized units option. You're right, it's a much better solution than the functions here. Thanks for the tip!

Jan Simon

Jan Simon (view profile)

I suggest 'normalized' units for TEXT():
text(0.6, 0.25,'another example!','fontsize',16, 'Units', 'normalized')
Then even zooming does not change the position, e.g. when the resolution is changed temporarily for printing.

But for PLOT() this suggestion will not work. There are good reasons not to use units other than 'data' for line plots.

MATLAB Release
MATLAB 7.12 (R2011a)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video