How do I scale an image and a plot in a subplot in matlab

조회 수: 5 (최근 30일)
Lewis Asilevi
Lewis Asilevi 2018년 1월 18일
답변: Walter Roberson 2018년 1월 19일
Hi all, I have this plot of an image and a set of plots which I plotted together using subplot. However, I realized the image is not scaled with the plots (Should scale to the height of the adjacent plot subplot(222)). Please how do I scale the image to the plots? I tried assigning figure handles to the image plot (subplot(221)) with the hope that, I can access the width or height properties of that single plot but it did'nt work. Can someone please assist me? I have provided an example code below. Thanks
clc
close all
clear all
URL ='http://structures.wishartlab.com/molecules/HMDB00126/image.png';
filename = 'test.png';
urlwrite(URL,filename);
y = imread(filename, 'BackgroundColor', [1 1 1]);
subplot(221) % First subplot
imshow(y);
x = 0:0.2:4*pi;
subplot(222) % Second subplot
plot(x,sin(x))
subplot(223)% Third subplot
plot(x,cos(x))
subplot(224) % fourth subplot
plot(x,tan(x))
  댓글 수: 1
Rik
Rik 2018년 1월 18일
Have a read here and here. It will greatly improve your chances of getting an answer.

댓글을 달려면 로그인하십시오.

답변 (2개)

Image Analyst
Image Analyst 2018년 1월 18일
You can set the 'Position' property of the subplots to adjust the image size if you don't like the default size it is picking.
  댓글 수: 1
Lewis Asilevi
Lewis Asilevi 2018년 1월 19일
편집: Lewis Asilevi 2018년 1월 19일
Hi expert, I am not so accomplished in matlab. Still learning. I however tried to look around(fiddling here and there) but didnt really get any results. I looked here
where you provided an answer to a similar problem but the answer does not seem complete.

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2018년 1월 19일
Use image() instead of imshow(). imshow changes a number of properties. In my experience, imshow can seldom be used safely in a gui for anything other than roughly display of images when you do not care much about the size, and you are not plotting anything else in the same axes, and you have no interactive components.

카테고리

Help CenterFile Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by