Plotting image and data changes y-axis direction. Why and how to fix this?

56 views (last 30 days)
I am plotting latitude and longitudes of locations in USA. Using borders, I can plot my coordinates without problems. However, when I try plotting my coordinates over an image, it changes the order of my y-axis from ascending to descending and my plots appear flipped on the x-axis. My code for plotting wanted_city and locations is the same when using borders function.
I tried using set() and it does not help.
set(gca,'YDir','reverse');
Why does it work with borders but not when being plotted over an image?
figure
% image of contiguous USA Koppen Climate, it is edited to be upside down,
% that is why i use flipud to flip it back to normal again
image1 = imread('USA-KoppenClimate.png');
image([-124.7325 -66.9504],[24.5243 49.3560],flipud(image1)); %extreme [west east], [south, north] points for image placement
hold on
plot(wanted_city(2), wanted_city(1), 'k.', 'MarkerSize', 20); % plot(longitude, latitude, marker) of desired city
plot(locations(city(1),2), locations(city(1),1), 'r.', 'MarkerSize', 20); % plot(longitude, latitude, marker) of closest city

Answers (3)

Friedel Hartmann
Friedel Hartmann on 7 Jul 2022
Does the command
axis ij % makes the y axis point downward
placed after the plot command, help?

Ramishetti sai sreeja
Ramishetti sai sreeja on 8 Jul 2022
Hi Dhairya Mehta,
It is my understanding that the while plotting the cordinates on image the cordinates are being changed.
I assume you you gave the coordinates wrong,Refer to these ,

Steven Lord
Steven Lord on 8 Jul 2022
From the "More About" section on the documentation page for the image function:
"The image function has two versions, the high-level version and the low-level version. If you use image with 'CData' as an input argument, then you are using the low-level version. Otherwise, you are using the high-level version.
The high-level version of image calls newplot before plotting and sets these axes properties:
  • Layer to 'top'. The image is shown in front of any tick marks or grid lines.
  • YDir to 'reverse'. Values along the y-axis increase from top to bottom. To decrease the values from top to bottom, set YDir to 'normal'. This setting reverses both the y-axis and the image.
  • View to [0 90].
The low-level version of the image function does not call newplot and does not set these axes properties."
The relevant piece of this information for your application is the second bullet that discusses the axes YDir property. You can:
  • change this property of the axes manually after you've called image (if you change it before, image will change it as part of its execution), or
  • you could call the low-level version of the image function, or
  • you could use the axis function with 'xy' as input. See the axis function documentation for more information on the 'xy' option

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!