|
MRR wrote:
> I want to restrict the pan tool in a figure (with a plot), allowing only positive values
> of the axes (2 dimensions, both x and y). This is , pan will be "blocked" when the user
> tries to move the graph to negative values.
> Is there any "direct" function to make this restriction?
There is no direct method of achieving that, at least not as of R2007a.
Looking at the code, I see that there is a slightly indirect and
decidedly non-obvious way of achieving close to what you want:
If there is an image anywhere in the axes that is being panned, then
the pan will be constrained to stay within the image boundaries.
How to put this to effect? This important clue: The image does not need
to be *visible* to have this blocking effect.
So you could use
image(x,y,zeros(xpixels,ypixels),'Visible','off');
set(gca,'YDir','normal');
and use xlim and ylim to set the axis limits to what you want them to start at.
The trickiest part of this might be that the x and y specifications are those of
the -center- of the lower left and upper-right image pixels, but in data
coordinates. Calculating the correct centers so that half an image pixel back
is the 0 boundary is not immediately obvious. I would be tempted at first to
specify the image matrix as just zeros(2,2) with appropriate x and y
calculated, but there is a clause in "help image" that is not in "doc image"
that is of slight concern:
IMAGE(X,Y,C), where X and Y are vectors, specifies the locations
of the pixel centers of C(1,1) and C(M,N). Element C(1,1) is
centered over (X(1), Y(1)), element C(M,N) is centered over
(X(end), Y(end)), and the pixel centers of the remaining elements
of C are spread out evenly between those two points, so that the
rectilinear patches are all of equal width and height.
The last sentence could be interpreted as indicating that
the width of each image pixel would have to equal the height of the
image pixel; or it could be interpreted as indicating that each
image pixel will have the same width as each other image pixel,
and each image pixel will have the same height as each other
image pixel. The latter is the more probable interpretation, but it would
have to be tested in order to place the pixel centers properly so the
image just reaches the edge of the area you want to be pan-able to.
Also, if you want to use this image trick, you should read the following
part of "doc image":
You cannot interactively pan or zoom outside the x-limits or y-limits of an
image, unless the axes limits are already been set outside the bounds of the
image, in which case there is no such restriction. If other objects (such as
lineseries) occupy the axes and extend beyond the bounds of the image, you can
pan or zoom to the bounds of the other objects, but no further.
I did not notice that bit about things that extend beyond the bounds of the
image when I was scanning through pan.m but having read that bit now, I see
the corresponding line in the code that it is implemented.
|