Plot over a image

Hello to all,
I've a question, i want plot a graphic over a image, I've write this code:
%Plot Sw - r^2/t
figure(1)
imshow('Image2011.jpg'),colormap jet
hold on
semilogx(s.Sim,s.S_w, 'k');
xlabel r^2/t(m^2/s)
ylabel Sw
xlim([0.0001, 1])
ylim([0,1])
hold off
but it doesn't work because the two graphs do not coincide. How can I do?
This is the image:

Risposte (1)

Walter Roberson
Walter Roberson il 4 Dic 2021
%Plot Sw - r^2/t
figure(1)
Image2011 = imread('Image2011.jpg');
image([0 1], [0 1], Image2011)
colormap jet
hold on
semilogx(s.Sim,s.S_w, 'k');
xlabel r^2/t(m^2/s)
ylabel Sw
xlim([0.0001, 1])
ylim([0,1])
hold off
Note that jpg images are almost always RGB images, so the colormap jet is probably not going to affect the display of the image. It might as there are some grayscale JPG images... they are just very very uncommon, with it being much more common that what looks like a grayscale JPG image is really an RGB image.

5 Commenti

Vittorio Faustinella
Vittorio Faustinella il 4 Dic 2021
Modificato: Vittorio Faustinella il 4 Dic 2021
It didn't work, this is the result
(it's another image)
I just measured with calipers, and on my screen it appears that the margin between the left axes and the left axes of the image is 9.0 mm, and that the total width of the plot is 100.5 mm. (I might have measured slightly incorrectly... it would have been easier with a physical object.)
If the scale is consistent in both directions, then you would want to place the start of the image itself at a negative value such that the left axes of the image appears at 0 data units and the right bar appears at 1 data unit; that is a span of 100.5-9.0 = 91.5 mm being equal to one data unit, so one data unit is 1/91.5 mm, and 9.0mm = 9/91.5 = 0.0983606557377049. This would lead to
image([-9/91.5 1], [-9/91.5 1], Image2011)
This is an approximation that might need to be fine tuned. Especially as I did not measure for the vertical axes.
And remember to "axis off" so that you rely on the axes drawn by the image instead of on the axes drawn for the plot.
Thank you very much! Now it's better, but the graph it's different than the plot without the picture.
Walter Roberson
Walter Roberson il 5 Dic 2021
Hmmmm, there is a bit of a difficulty there. The plot in the image is in log scale, but you cannot use log scale with negative coordinates.
So you have two choices:
  1. Use two different axes with one overlaying the other, one with linear scale used to hold the image, and the other with log scale positioned a little to the right of the start of the other axes so that the 0.000001 point aligns with the image left hand side; OR
  2. use a single linear scale, but do a log transform of the x coordinates to determine linear coordinates to draw the data at; in such a case the image should probably be placed to have an x limit of 6
Thank you for your time, I'll figure it out.

Accedi per commentare.

Categorie

Scopri di più su Modify Image Colors in Centro assistenza e File Exchange

Prodotti

Release

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by