How can I get the right image ratio when displaying an image behind a graph?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Walter Roberson
le 26 Mai 2023
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')
Voir également
Catégories
En savoir plus sur Basic Display dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!