How to add axis in a figure where I'm drawing lines.

2 views (last 30 days)
Upasana Baishya
Upasana Baishya on 11 Jun 2022
Commented: Upasana Baishya on 11 Jun 2022
This is the code I'm using.
I = imread('figure251.png');
Error using imread>get_full_filename
File "figure251.png" does not exist.

Error in imread (line 371)
fullname = get_full_filename(filename);
figure, imshow(I); colormap hot ;
axis('on', 'image');
xticklabels({'-10','-5','0','5','10'}) ;
yticklabels({'10','5','0','-5','-10'}) ;
hold on
p1 = [125.5,125.5];
p2 = [125.5,130.5];
plot([p1(1),p2(1)],[p1(2),p2(2)],'Color','w','LineWidth',3)
hold on
p3 = [130.5,125.5];
p4 = [130.5,130.5];
plot([p3(1),p4(1)],[p3(2),p4(2)],'Color','w','LineWidth',3)
hold on
p5 = [125.5,125.5];
p6 = [130.5,125.5];
plot([p5(1),p6(1)],[p5(2),p6(2)],'Color','w','LineWidth',3)
hold on
p7 = [125.5,130.5];
p8 = [130.5,130.5];
plot([p7(1),p8(1)],[p7(2),p8(2)],'Color','w','LineWidth',3)
I need to put axis in the above program. But if I zoom in then the no of points in the axis reduces. if I use axis on only then it coms as piel no. Then I can zoom in. I want to zoom in with more axis label.

Accepted Answer

DGM
DGM on 11 Jun 2022
Edited: DGM on 11 Jun 2022
You can set xdata,ydata for imshow() as you do with image()/imagesc(), but by default imshow() will turn off axis visibility. You can turn it back on, but then you have to deal with the fact that the figure has been set up without consideration for the area required to show ticks and axis labels. You may have to adjust the position of the axes object to make room for everything.
I = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1028490/image.png');
xylim = [-90,90].*4.65./1000;
imshow(I,'Xdata',xylim,'Ydata',xylim);
set(gca,'visible','on')
colormap(hot);
The utility of imshow() is its conveniences for viewing pictures without extraneous axis decorations. If you're using it with the axis visible, I'm not sure why you wouldn't just use image()/imagesc() instead. You might need to set axis equal if you do, but that's about it.
FWIW, the first answer is a bit misleading. Both image() and imshow() will display RGB images in truecolor and they'll both display grayscale images using a colormap. The only difference is that imshow() forces the use of a gray colormap instead of whatever map was being used in the axes at the time. Again, that's considered a matter of convenience. If you explicitly set the map after the the image is displayed, there really isn't any difference.
  5 Comments
Upasana Baishya
Upasana Baishya on 11 Jun 2022
Thank you so much for the explanation and the solution.

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!