How can I force an image to render on the entire axes of a figure?
조회 수: 18 (최근 30일)
이전 댓글 표시
Sometimes I use imshow to view a dataset that has a very high or very low aspect ratio. imshow faithfully displays it in its correct aspect ratio, but it keeps the original image aspect ratio instead of showing data across the full axes if I zoom in with the mouse wheel.
Example code to show the problem I'm trying to address:
data = rand([10,500]);
imshow(data);
Resize the figure window to be roughly square and you'll see the following figure, showing the full image by default.
Now zoom in with your mouse wheel and the "very short but very wide" aspect ratio forces only a tiny slice of the image to show when it would be more helpful to show data across the full axes. The next image shows this. I've added text in paint to show where I want to see data.
Is there a way to change this behavior to always display data across the full area of the figure regardless of the original aspect ratio of that data? Thanks for any help!
댓글 수: 0
답변 (1개)
DGM
2024년 3월 5일
편집: DGM
2024년 3월 5일
There are various proposed solutions that I can't remember entirely. If I recall, many don't work consistently across different scenarios, so that's why I never bothered keeping track of them. I don't remember if there's a thread about that. I feel like there was, but I doubt I could find it.
This exact horrible problem is why I made imshow2() part of MIMT. It has practical zoom and pan controls and actually fills the figure area when zooming in. It also lets you zoom out further, and it supports a bunch of things imshow() doesn't support.
Is imshow2() an elegant solution? I wouldn't call it elegant.
EDIT:
I recall one of the simple ways:
image(myimage)
axis equal
That at least lets you zoom in, but the view controls are still clumsy as normal, and you're wasting figure area to excessive padding. You could get rid of most of the padding:
image(myimage)
axis equal off
set(gca,'position',[0 0 1 1])
댓글 수: 2
DGM
2024년 3월 5일
편집: DGM
2024년 3월 5일
You could try to simplify it, but that's not a bridge I'd suggest to cross unless you're sure that the simpler use of "image(); axis equal off" isn't appropriate.
EDIT: actually, I think the entire aspect ratio handling I did there is buried in the @onresize callback. Off the top of my head, I don't know of a way to work around that that isn't a bigger problem than just trying to use the snippet above.
참고 항목
카테고리
Help Center 및 File Exchange에서 Convert Image Type에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!