Show image in UIAxis with updated axis limits

9 views (last 30 days)
Shawn O'Neal
Shawn O'Neal on 26 Aug 2019
Edited: Adam Danz on 27 Aug 2019
I am using a function that outputs the x and y axis values, an image data matrix, and image colormap. I would like to put the image in a UIAxis and update the limits to represent the new x and y axis values.
This code gets me the image I would like with cooresponding axis values.
imagesc(X,Y,M)
colormap(Mcolor)
1.PNG
The following code shows the correct image in the UIAxis but the axis values are now based on the pixels of the image.
imagesc(app.UIAxes,M);
colormap(app.UIAxes,Mcolor);
2.PNG
Manually changing the axis limits just makes the images very small.
How do I get the correct axis values with the image in the UIAxis?
  4 Comments
Shawn O'Neal
Shawn O'Neal on 27 Aug 2019
In case anyone else has this issue, I found the solution. The 'tight' does make it look much better.
imagesc(app.UIAxes,XX,YY,M);
colormap(app.UIAxes,Mcolor);
axis(app.UIAxes,'tight');
3.PNG
Adam Danz
Adam Danz on 27 Aug 2019
Edited: Adam Danz on 27 Aug 2019
Nice!
The only other thing I'd suggest is setting the aspect ratios equal so that the distances along the x and y axes are the same. To set he aspect ratio equal, see the last line of code in my answer.

Sign in to comment.

Answers (1)

Adam Danz
Adam Danz on 27 Aug 2019
Check out the "x" and "y" inputs to imagesc().
If you do not supply the x and y values, the axes will represent a pixel count. If you want want the x and y axes to represent a different metric (miles, meters, KMs, etc) you need to supply those values just like you did in the first line of code in your question.
imagesc(app.UIAxes,X,Y,M)
Then, to trim the axes to fit the image,
axis(app.UIAxes,'tight')
You may also need to make the aspect ratio equal so the image is not skewed along one of the axes.
axis(app.UIAxes,'equal')

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!