How can I get the right image ratio when displaying an image behind a graph?
조회 수: 4 (최근 30일)
이전 댓글 표시
I want to display an image behind the graph and would like to have to it as a specific X1 vlaue and length which is given by the X2. When I plot it like in my code the image is oversized along the y-axis and it would be nice to get the original ratios of the image. I know how long the object on the image is and I want to scale this to the x-axis (with the X1 and X2) and keep the right widht of the image.
X1 = X
X2 = X+590
figure
a1 = gca;
hold on
image('CData', imread('20-1.jpg'), 'XData', [X1 X2]);
plot(Pos9, TC_V9, '-', 'LineWidth', 2, 'Color', [0 0 0]);
ylabel('TC [W/m/K]', 'Fontweight', 'bold', 'FontSize', 14)
xlabel('Position (mm)', 'Fontweight', 'bold', 'FontSize', 14)
title('C20-1 (67-98 cm) Calc-Sil', 'FontSize', 16)
hold off
댓글 수: 0
답변 (1개)
Walter Roberson
2023년 5월 26일
The rule is that the XData you provide will be used as the center of the pixels. You want to shift the boundaries by half of a pixel each.
img = imread('20-1.jpg');
numcol = size(img,2);
X1 = X + numcol/2;
X2 = X + 590 - numcol/2;
fig = figure();
a1 = axes('Parent', fig);
hold(a1, 'on');
image(a1, 'CData', img, 'XData', [x1 X2]);
plot(a1, Pos9, TC_V9, '-', 'LineWidth', 2, 'Color', [0 0 0]);
ylabel(a1, 'TC [W/m/K]', 'Fontweight', 'bold', 'FontSize', 14)
xlabel(a1, 'Position (mm)', 'Fontweight', 'bold', 'FontSize', 14)
title(a1, 'C20-1 (67-98 cm) Calc-Sil', 'FontSize', 16) )
hold(a1, 'off')
참고 항목
카테고리
Help Center 및 File Exchange에서 Basic Display에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!