Axes get reverse while overlaying line plot on image
3 views (last 30 days)
Show older comments
Hi everyone, I have problem with overlying line plot on image. I have corrected the reversed Y-axis, but the line plot is still wrong i.e plotted with reversed axes (as seen on data cursor). I have attached both real line plot (second fig) and same line plot getting falsely plotted when overlayed on image. plz help me on this, thanks
img = imread('wave.png')
min_y = 0
max_y =18
min_x = 985;
max_x = 4500
imagesc([min_x max_x] ,[min_y max_y],img);
truesize;
hold on;
plot(wav, N)
yTicks = get(gca,'YTick');
yTicks_reverse = sort(yTicks,2,'descend');
set(gca,'YTickLabel',num2str(yTicks_reverse.'));
set(gca,'YDir','reverse'); <<
<<
>>
>>
0 Comments
Answers (2)
Jan
on 12 Oct 2014
The tick labels are strings. Sorting them might lead to unexpected results, when they have a different number of digits - characters!
You reverse the tick labels and the YDir afterwards. This seems to be confusing.
0 Comments
Image Analyst
on 12 Oct 2014
I think the problem might be you're passing in the x and y axes to imagesc(). These might be opposite to that of a normal image, which has the y origin (y = row or line #1) at the top, instead of having y at the bottom like plot usually does. Try reversing the y array you send in to imagesc() and see if that helps.
imagesc([min_x, max_x] ,[max_y, min_y],img);
Or just use imshow() if you have the Image Processing Toolbox. Or set(gca, 'ydir', 'reverse') or set(gca, 'ydir', 'normal') at the critical time(s).
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!