Show multiple axes all around image?

6 views (last 30 days)
Roger Breton
Roger Breton on 9 Jan 2022
Commented: Roger Breton on 11 Jan 2022
Currently, I get this result :
1) Would it possible to have the 'axes' show all around the image? I'd like to experiment with horizontal scales showing above and below the image, and with vertical scales showing on both the left and right hand side of the image, if that is possible? I did not see any property to do this in axes properties.
2) Is it possible to show the '0' coordinates on the right hand side the the horizontal axes?
3) Is there a way to control how far away Labels appear from the image? Say, at the bottom?

Accepted Answer

DGM
DGM on 10 Jan 2022
For a single axes, you can only have one set of tick labels per axis. The workaround is the creation of an empty axes to provide the other labels. The problem is making sure the two axes stay coincident. This should be a start, but it's probably not the end.
A = imread('peppers.png');
s = size(A);
image(A);
axis equal
xlim([0 s(2)])
ylim([0 s(1)])
xticklabels(flipud(xticklabels))
hax = gca;
% overlay empty axes
axes('color','none','XAxisLocation','top','YAxisLocation','right','ydir','reverse')
axis equal
xlim([0 s(2)])
ylim([0 s(1)])
xticklabels(flipud(xticklabels)) % flip ticklabel direction
% move xlabel
axes(hax); % switch back to first axes
hl = xlabel('dinner''s ready');
hl.Position(2) = hl.Position(2)+20; % this is in data units!
The web-figure really wants to cut that xlabel off, but in practice, you'll have to manage the axes position within the figure such that there are sufficient margins to move the xlabel away from the axes.
Regarding #2, note that only the label vector is being flipped. The coordinate space is not. If you use any sort of tool like the datatip tool or impixelinfo(), the coordinates will not agree with the labels. So while it can be done, I don't really think it's a good idea. You can set the 'xdir' property of both axes to 'reverse, which will reverse the labels, the ticks, and the image. That way, they all correspond -- but I assume you don't want the image flipped. I don't see the reason to do either.
Regarding #3, if you wanted instead to move the xticklabel position, I don't know if that's possible. There might be some other workaround, but I don't have one off the top of my head.
  1 Comment
Roger Breton
Roger Breton on 11 Jan 2022
I suppressed the 'flipud(xticklabels)'. This is perfect :
Specifying the xlim([0 s(2)]) from 0 to the horitontal size of the image got the axis tick starting at the 0 mark. Great!
Thank you so much for your kind help!!!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!